From be6354f9efa33de0f930e04aa1b2f8ae79cc6477 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 18 Feb 2004 18:21:00 +0000 Subject: [PATCH] bracket a few more low-level things with pstats --- panda/src/display/graphicsEngine.cxx | 20 +++++++------ panda/src/display/graphicsEngine.h | 3 +- panda/src/display/graphicsOutput.cxx | 4 +++ panda/src/display/graphicsOutput.h | 3 ++ panda/src/display/graphicsStateGuardian.cxx | 3 ++ panda/src/display/graphicsStateGuardian.h | 1 + panda/src/glxdisplay/glxGraphicsBuffer.cxx | 5 +++- panda/src/glxdisplay/glxGraphicsWindow.cxx | 3 ++ panda/src/pstatclient/pStatClient.cxx | 24 +++++++++++++++ panda/src/pstatclient/pStatClient.h | 1 + panda/src/pstatclient/pStatCollector.I | 33 +++++++++++++++++++++ panda/src/pstatclient/pStatCollector.h | 4 +++ panda/src/pstatclient/pStatProperties.cxx | 5 ++-- 13 files changed, 96 insertions(+), 13 deletions(-) diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 93e012ea21..eec4e172d8 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -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(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index 087cecd171..b6b7b9c0d5 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -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; diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 0d2c31655f..20ab9ed60f 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -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 diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index 127e25adaa..3ed8491caf 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -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() { diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 8beae2121b..f6b2fd73f4 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -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; diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index c777947585..3c04cc5d47 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -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 { diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.cxx b/panda/src/glxdisplay/glxGraphicsBuffer.cxx index 7d443533a7..12a1781323 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.cxx +++ b/panda/src/glxdisplay/glxGraphicsBuffer.cxx @@ -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); diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 411491dce6..164aeb6ae1 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -26,6 +26,7 @@ #include "mouseButton.h" #include "glgsg.h" #include "clockObject.h" +#include "pStatTimer.h" #include #include @@ -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); diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 25603ca83c..10c2d44923 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -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()); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 2acdde2d3d..bd8c45f650 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -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); diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index a711c601f7..4e3079ff66 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -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 //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pstatclient/pStatCollector.h b/panda/src/pstatclient/pStatCollector.h index 4fd67e2305..df916f7028 100644 --- a/panda/src/pstatclient/pStatCollector.h +++ b/panda/src/pstatclient/pStatCollector.h @@ -67,6 +67,7 @@ PUBLISHED: INLINE void operator = (const PStatCollector ©); 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); diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index bc4dd3a824..8f1c48abd7 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -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 } };