bracket a few more low-level things with pstats

This commit is contained in:
David Rose 2004-02-18 18:21:00 +00:00
parent 82385a51d0
commit be6354f9ef
13 changed files with 96 additions and 13 deletions

View File

@ -39,7 +39,8 @@
#endif
#ifndef CPPPARSER
PStatCollector GraphicsEngine::_show_code_pcollector("App:Show Code");
PStatCollector GraphicsEngine::_app_pcollector("App");
PStatCollector GraphicsEngine::_yield_pcollector("App:Yield");
PStatCollector GraphicsEngine::_cull_pcollector("Cull");
PStatCollector GraphicsEngine::_draw_pcollector("Draw");
PStatCollector GraphicsEngine::_sync_pcollector("Draw:Sync");
@ -91,8 +92,8 @@ GraphicsEngine(Pipeline *pipeline) :
////////////////////////////////////////////////////////////////////
GraphicsEngine::
~GraphicsEngine() {
if (_show_code_pcollector.is_active()) {
_show_code_pcollector.stop();
if (_app_pcollector.is_started()) {
_app_pcollector.stop();
}
remove_all_windows();
@ -347,9 +348,9 @@ is_empty() const {
void GraphicsEngine::
render_frame() {
// Anything that happens outside of GraphicsEngine::render_frame()
// is deemed to be show code.
if (_show_code_pcollector.is_active()) {
_show_code_pcollector.stop();
// is deemed to be App.
if (_app_pcollector.is_started()) {
_app_pcollector.stop();
}
// We hold the GraphicsEngine mutex while we wait for all of the
@ -384,7 +385,7 @@ render_frame() {
_transform_states_unused_pcollector.set_level(TransformState::get_num_unused_states());
_render_states_unused_pcollector.set_level(RenderState::get_num_unused_states());
}
// Now signal all of our threads to begin their next frame.
_app.do_frame(this);
for (ti = _threads.begin(); ti != _threads.end(); ++ti) {
@ -409,6 +410,7 @@ render_frame() {
if (yield_timeslice) {
// Nap for a moment to yield the timeslice, to be polite to other
// running applications.
PStatTimer timer(_yield_pcollector);
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
@ -416,8 +418,8 @@ render_frame() {
}
// Anything that happens outside of GraphicsEngine::render_frame()
// is deemed to be show code.
_show_code_pcollector.start();
// is deemed to be App.
_app_pcollector.start();
}
////////////////////////////////////////////////////////////////////

View File

@ -192,7 +192,8 @@ private:
FlipState _flip_state;
Mutex _lock;
static PStatCollector _show_code_pcollector;
static PStatCollector _app_pcollector;
static PStatCollector _yield_pcollector;
static PStatCollector _cull_pcollector;
static PStatCollector _draw_pcollector;
static PStatCollector _sync_pcollector;

View File

@ -24,6 +24,10 @@
TypeHandle GraphicsOutput::_type_handle;
#ifndef CPPPARSER
PStatCollector GraphicsOutput::_make_current_pcollector("Draw:Make current");
#endif // CPPPARSER
////////////////////////////////////////////////////////////////////
// Function: GraphicsOutput::Constructor
// Access: Protected

View File

@ -28,6 +28,7 @@
#include "clearableRegion.h"
#include "typedWritableReferenceCount.h"
#include "pStatCollector.h"
#include "notify.h"
#include "pmutex.h"
#include "filename.h"
@ -153,6 +154,8 @@ protected:
int _y_size;
bool _has_size;
bool _is_valid;
static PStatCollector _make_current_pcollector;
public:
static TypeHandle get_class_type() {

View File

@ -59,6 +59,7 @@ PStatCollector GraphicsStateGuardian::_transform_state_pcollector("State changes
PStatCollector GraphicsStateGuardian::_texture_state_pcollector("State changes:Textures");
PStatCollector GraphicsStateGuardian::_other_state_pcollector("State changes:Other");
PStatCollector GraphicsStateGuardian::_draw_primitive_pcollector("Draw:Primitive");
PStatCollector GraphicsStateGuardian::_clear_pcollector("Draw:Clear");
#endif
@ -346,6 +347,8 @@ set_depth_clear_value(const float value) {
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
clear(ClearableRegion *clearable) {
PStatTimer timer(_clear_pcollector);
int clear_buffer_type = 0;
if (clearable->get_clear_color_active()) {
clear_buffer_type |= RenderBuffer::T_back;

View File

@ -295,6 +295,7 @@ public:
static PStatCollector _texture_state_pcollector;
static PStatCollector _other_state_pcollector;
static PStatCollector _draw_primitive_pcollector;
static PStatCollector _clear_pcollector;
private:
class LightInfo {

View File

@ -23,6 +23,7 @@
#include "graphicsPipe.h"
#include "glgsg.h"
#include "pStatTimer.h"
TypeHandle glxGraphicsBuffer::_type_handle;
@ -60,7 +61,9 @@ glxGraphicsBuffer::
// is ready for drawing.
////////////////////////////////////////////////////////////////////
void glxGraphicsBuffer::
make_current() {
make_current() {
PStatTimer timer(_make_current_pcollector);
glxGraphicsStateGuardian *glxgsg;
DCAST_INTO_V(glxgsg, _gsg);
glXMakeCurrent(_display, _pbuffer, glxgsg->_context);

View File

@ -26,6 +26,7 @@
#include "mouseButton.h"
#include "glgsg.h"
#include "clockObject.h"
#include "pStatTimer.h"
#include <errno.h>
#include <sys/time.h>
@ -75,6 +76,8 @@ glxGraphicsWindow::
////////////////////////////////////////////////////////////////////
void glxGraphicsWindow::
make_current() {
PStatTimer timer(_make_current_pcollector);
glxGraphicsStateGuardian *glxgsg;
DCAST_INTO_V(glxgsg, _gsg);
glXMakeCurrent(_display, _xwindow, glxgsg->_context);

View File

@ -43,6 +43,7 @@ PStatClient *PStatClient::_global_pstats = NULL;
PStatCollector _total_size_pcollector("Memory usage");
PStatCollector _cpp_size_pcollector("Memory usage:C++");
PStatCollector _interpreter_size_pcollector("Memory usage:Interpreter");
PStatCollector _pstats_pcollector("App:PStats");
#endif
////////////////////////////////////////////////////////////////////
@ -557,6 +558,25 @@ is_active(int collector_index, int thread_index) const {
_threads[thread_index]._is_active);
}
////////////////////////////////////////////////////////////////////
// Function: PStatClient::is_started
// Access: Private
// Description: Returns true if the indicated collector/thread
// combination has been started, or false otherwise.
//
// Normally you would not use this interface directly;
// instead, call PStatCollector::is_started().
////////////////////////////////////////////////////////////////////
bool PStatClient::
is_started(int collector_index, int thread_index) const {
nassertr(collector_index >= 0 && collector_index < (int)_collectors.size(), false);
nassertr(thread_index >= 0 && thread_index < (int)_threads.size(), false);
return (_collectors[collector_index]._def->_is_active &&
_threads[thread_index]._is_active &&
_collectors[collector_index]._per_thread[thread_index]._nested_count != 0);
}
////////////////////////////////////////////////////////////////////
// Function: PStatClient::start
// Access: Private
@ -798,6 +818,10 @@ new_frame(int thread_index) {
thread._frame_data.clear();
thread._frame_number++;
start(0, thread_index, frame_start);
// Also record the time for the PStats operation itself.
start(_pstats_pcollector.get_index(), thread_index, frame_start);
stop(_pstats_pcollector.get_index(), thread_index, _clock.get_real_time());
}
////////////////////////////////////////////////////////////////////

View File

@ -104,6 +104,7 @@ private:
PStatThread make_thread(const string &name);
bool is_active(int collector_index, int thread_index) const;
bool is_started(int collector_index, int thread_index) const;
void start(int collector_index, int thread_index);
void start(int collector_index, int thread_index, float as_of);

View File

@ -137,6 +137,17 @@ is_active() {
return _client->is_active(_index, 0);
}
////////////////////////////////////////////////////////////////////
// Function: PStatCollector::is_started
// Access: Published
// Description: Returns true if this particular collector has been
// started on the default thread, or false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool PStatCollector::
is_started() {
return _client->is_started(_index, 0);
}
////////////////////////////////////////////////////////////////////
// Function: PStatCollector::start
// Access: Published
@ -234,6 +245,17 @@ is_active(const PStatThread &thread) {
return _client->is_active(_index, thread._index);
}
////////////////////////////////////////////////////////////////////
// Function: PStatCollector::is_started
// Access: Public
// Description: Returns true if this particular collector has been
// started on the indicated thread, or false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool PStatCollector::
is_started(const PStatThread &thread) {
return _client->is_started(_index, thread._index);
}
////////////////////////////////////////////////////////////////////
// Function: PStatCollector::start
// Access: Public
@ -345,6 +367,17 @@ get_level(const PStatThread &thread) {
return _client->get_level(_index, thread._index);
}
////////////////////////////////////////////////////////////////////
// Function: PStatCollector::get_index
// Access: Public
// Description: Returns the index number of this particular collector
// within the PStatClient.
////////////////////////////////////////////////////////////////////
INLINE int PStatCollector::
get_index() const {
return _index;
}
#else // DO_PSTATS
////////////////////////////////////////////////////////////////////

View File

@ -67,6 +67,7 @@ PUBLISHED:
INLINE void operator = (const PStatCollector &copy);
INLINE bool is_active();
INLINE bool is_started();
INLINE void start();
INLINE void stop();
@ -76,8 +77,11 @@ PUBLISHED:
INLINE void sub_level(float decrement);
INLINE float get_level();
INLINE int get_index() const;
public:
INLINE bool is_active(const PStatThread &thread);
INLINE bool is_started(const PStatThread &thread);
INLINE void start(const PStatThread &thread);
INLINE void start(const PStatThread &thread, float as_of);
INLINE void stop(const PStatThread &thread);

View File

@ -104,7 +104,6 @@ struct LevelCollectorProperties {
};
static TimeCollectorProperties time_properties[] = {
{ 1, "Swap buffers", { 0.5, 1.0, 0.8 } },
{ 1, "App", { 0.0, 0.8, 0.4 }, 1.0 / 30.0 },
{ 1, "App:Animation", { 1.0, 0.0, 1.0 } },
{ 1, "App:Collisions", { 1.0, 0.5, 0.0 } },
@ -122,9 +121,11 @@ static TimeCollectorProperties time_properties[] = {
{ 1, "Cull:Show fps", { 0.5, 0.8, 1.0 } },
{ 1, "Cull:Bins", { 0.3, 0.6, 0.3 } },
{ 1, "Draw", { 1.0, 0.0, 0.0 }, 1.0 / 30.0 },
{ 1, "Draw:Make current", { 0.4, 0.2, 0.6 } },
{ 1, "Draw:Clear", { 0.0, 0.8, 0.6 } },
{ 1, "Draw:Sync", { 0.5, 0.7, 0.7 } },
{ 1, "Draw:Flip", { 1.0, 0.6, 0.3 } },
{ 1, "Draw:Bins", { 0.3, 0.6, 0.3 } },
{ 1, "Draw:Bins", { 0.3, 0.6, 0.0 } },
{ 0, "Draw:Primitive", { 0.0, 0.0, 0.5 } },
{ 0, NULL }
};