diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 7140d0eb9b..0bbd5c9f07 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -41,6 +41,8 @@ #ifndef CPPPARSER PStatCollector GraphicsEngine::_cull_pcollector("Cull"); PStatCollector GraphicsEngine::_draw_pcollector("Draw"); +PStatCollector GraphicsEngine::_sync_pcollector("Draw:Sync"); +PStatCollector GraphicsEngine::_flip_pcollector("Draw:Flip"); PStatCollector GraphicsEngine::_transform_states_pcollector("TransformStates"); PStatCollector GraphicsEngine::_transform_states_unused_pcollector("TransformStates:Unused"); PStatCollector GraphicsEngine::_render_states_pcollector("RenderStates"); @@ -627,6 +629,9 @@ flip_windows(const GraphicsEngine::Windows &wlist) { //////////////////////////////////////////////////////////////////// void GraphicsEngine:: do_sync_frame() { + // Statistics + PStatTimer timer(_sync_pcollector); + nassertv(_flip_state == FS_draw); // Wait for all the threads to finish their current frame. Grabbing @@ -649,6 +654,9 @@ do_sync_frame() { //////////////////////////////////////////////////////////////////// void GraphicsEngine:: do_flip_frame() { + // Statistics + PStatTimer timer(_flip_pcollector); + nassertv(_flip_state == FS_draw || _flip_state == FS_sync); // First, wait for all the threads to finish their current frame, if diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index e88716cded..c8cb042c1b 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -182,6 +182,8 @@ private: static PStatCollector _cull_pcollector; static PStatCollector _draw_pcollector; + static PStatCollector _sync_pcollector; + static PStatCollector _flip_pcollector; static PStatCollector _transform_states_pcollector; static PStatCollector _transform_states_unused_pcollector; static PStatCollector _render_states_pcollector; diff --git a/panda/src/grutil/frameRateMeter.cxx b/panda/src/grutil/frameRateMeter.cxx index 35fdb5b21d..a575a237bb 100644 --- a/panda/src/grutil/frameRateMeter.cxx +++ b/panda/src/grutil/frameRateMeter.cxx @@ -25,6 +25,11 @@ #include "config_grutil.h" #include "depthTestAttrib.h" #include "depthWriteAttrib.h" +#include "pStatTimer.h" + +#ifndef CPPPARSER +PStatCollector FrameRateMeter::_show_fps_pcollector("Cull:Show fps"); +#endif // CPPPARSER TypeHandle FrameRateMeter::_type_handle; @@ -143,6 +148,9 @@ clear_layer() { //////////////////////////////////////////////////////////////////// bool FrameRateMeter:: cull_callback(CullTraverser *trav, CullTraverserData &data) { + // Statistics + PStatTimer timer(_show_fps_pcollector); + // Check to see if it's time to update. double now = _clock_object->get_frame_time(); double elapsed = now - _last_update; diff --git a/panda/src/grutil/frameRateMeter.h b/panda/src/grutil/frameRateMeter.h index 5d066a00f0..55ac16959b 100644 --- a/panda/src/grutil/frameRateMeter.h +++ b/panda/src/grutil/frameRateMeter.h @@ -25,6 +25,7 @@ #include "graphicsWindow.h" #include "graphicsLayer.h" #include "pointerTo.h" +#include "pStatCollector.h" class GraphicsChannel; class ClockObject; @@ -76,6 +77,8 @@ private: string _text_pattern; ClockObject *_clock_object; + static PStatCollector _show_fps_pcollector; + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pgraph/cullBin.I b/panda/src/pgraph/cullBin.I index 10cf494fd9..8b127bc1e4 100644 --- a/panda/src/pgraph/cullBin.I +++ b/panda/src/pgraph/cullBin.I @@ -23,7 +23,9 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE CullBin:: -CullBin(GraphicsStateGuardianBase *gsg) : +CullBin(const string &name, GraphicsStateGuardianBase *gsg) : + _cull_this_pcollector(_cull_bin_pcollector, name), + _draw_this_pcollector(_draw_bin_pcollector, name), _gsg(gsg) { } diff --git a/panda/src/pgraph/cullBin.cxx b/panda/src/pgraph/cullBin.cxx index eaa50e1b9a..1f3ccf8013 100644 --- a/panda/src/pgraph/cullBin.cxx +++ b/panda/src/pgraph/cullBin.cxx @@ -19,6 +19,11 @@ #include "cullBin.h" +#ifndef CPPPARSER +PStatCollector CullBin::_cull_bin_pcollector("Cull:Bins"); +PStatCollector CullBin::_draw_bin_pcollector("Draw:Bins"); +#endif + TypeHandle CullBin::_type_handle; //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/cullBin.h b/panda/src/pgraph/cullBin.h index ce5e1b536b..7a83dc4c5b 100644 --- a/panda/src/pgraph/cullBin.h +++ b/panda/src/pgraph/cullBin.h @@ -22,6 +22,7 @@ #include "pandabase.h" #include "typedReferenceCount.h" +#include "pStatCollector.h" #include "pointerTo.h" class CullableObject; @@ -40,7 +41,7 @@ class GraphicsStateGuardianBase; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA CullBin : public TypedReferenceCount { public: - INLINE CullBin(GraphicsStateGuardianBase *gsg); + INLINE CullBin(const string &name, GraphicsStateGuardianBase *gsg); virtual ~CullBin(); virtual PT(CullBin) make_next() const; @@ -53,6 +54,11 @@ public: protected: GraphicsStateGuardianBase *_gsg; + static PStatCollector _cull_bin_pcollector; + static PStatCollector _draw_bin_pcollector; + PStatCollector _cull_this_pcollector; + PStatCollector _draw_this_pcollector; + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/pgraph/cullBinBackToFront.I b/panda/src/pgraph/cullBinBackToFront.I index c76bd32c09..84406f7981 100644 --- a/panda/src/pgraph/cullBinBackToFront.I +++ b/panda/src/pgraph/cullBinBackToFront.I @@ -47,7 +47,7 @@ operator < (const ObjectData &other) const { // Description: //////////////////////////////////////////////////////////////////// INLINE CullBinBackToFront:: -CullBinBackToFront(GraphicsStateGuardianBase *gsg) : - CullBin(gsg) +CullBinBackToFront(const string &name, GraphicsStateGuardianBase *gsg) : + CullBin(name, gsg) { } diff --git a/panda/src/pgraph/cullBinBackToFront.cxx b/panda/src/pgraph/cullBinBackToFront.cxx index 3bae862192..98fe333c2f 100644 --- a/panda/src/pgraph/cullBinBackToFront.cxx +++ b/panda/src/pgraph/cullBinBackToFront.cxx @@ -21,6 +21,7 @@ #include "geometricBoundingVolume.h" #include "cullableObject.h" #include "cullHandler.h" +#include "pStatTimer.h" #include @@ -77,6 +78,7 @@ add_object(CullableObject *object) { //////////////////////////////////////////////////////////////////// void CullBinBackToFront:: finish_cull() { + PStatTimer timer(_cull_this_pcollector); sort(_objects.begin(), _objects.end()); } @@ -88,6 +90,7 @@ finish_cull() { //////////////////////////////////////////////////////////////////// void CullBinBackToFront:: draw() { + PStatTimer timer(_draw_this_pcollector); Objects::const_iterator oi; for (oi = _objects.begin(); oi != _objects.end(); ++oi) { CullableObject *object = (*oi)._object; diff --git a/panda/src/pgraph/cullBinBackToFront.h b/panda/src/pgraph/cullBinBackToFront.h index 3cec82a507..ff524398cc 100644 --- a/panda/src/pgraph/cullBinBackToFront.h +++ b/panda/src/pgraph/cullBinBackToFront.h @@ -37,7 +37,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA CullBinBackToFront : public CullBin { public: - INLINE CullBinBackToFront(GraphicsStateGuardianBase *gsg); + INLINE CullBinBackToFront(const string &name, GraphicsStateGuardianBase *gsg); virtual ~CullBinBackToFront(); virtual void add_object(CullableObject *object); diff --git a/panda/src/pgraph/cullBinFixed.I b/panda/src/pgraph/cullBinFixed.I index f4d26f62af..4f9f38283f 100644 --- a/panda/src/pgraph/cullBinFixed.I +++ b/panda/src/pgraph/cullBinFixed.I @@ -47,7 +47,7 @@ operator < (const ObjectData &other) const { // Description: //////////////////////////////////////////////////////////////////// INLINE CullBinFixed:: -CullBinFixed(GraphicsStateGuardianBase *gsg) : - CullBin(gsg) +CullBinFixed(const string &name, GraphicsStateGuardianBase *gsg) : + CullBin(name, gsg) { } diff --git a/panda/src/pgraph/cullBinFixed.cxx b/panda/src/pgraph/cullBinFixed.cxx index 3e4b2f5e49..4678dcd883 100644 --- a/panda/src/pgraph/cullBinFixed.cxx +++ b/panda/src/pgraph/cullBinFixed.cxx @@ -21,6 +21,7 @@ #include "geometricBoundingVolume.h" #include "cullableObject.h" #include "cullHandler.h" +#include "pStatTimer.h" #include @@ -64,6 +65,7 @@ add_object(CullableObject *object) { //////////////////////////////////////////////////////////////////// void CullBinFixed:: finish_cull() { + PStatTimer timer(_cull_this_pcollector); stable_sort(_objects.begin(), _objects.end()); } @@ -75,6 +77,7 @@ finish_cull() { //////////////////////////////////////////////////////////////////// void CullBinFixed:: draw() { + PStatTimer timer(_draw_this_pcollector); Objects::const_iterator oi; for (oi = _objects.begin(); oi != _objects.end(); ++oi) { CullableObject *object = (*oi)._object; diff --git a/panda/src/pgraph/cullBinFixed.h b/panda/src/pgraph/cullBinFixed.h index 4050b933ff..cb565878c3 100644 --- a/panda/src/pgraph/cullBinFixed.h +++ b/panda/src/pgraph/cullBinFixed.h @@ -40,7 +40,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA CullBinFixed : public CullBin { public: - INLINE CullBinFixed(GraphicsStateGuardianBase *gsg); + INLINE CullBinFixed(const string &name, GraphicsStateGuardianBase *gsg); virtual ~CullBinFixed(); virtual void add_object(CullableObject *object); diff --git a/panda/src/pgraph/cullBinFrontToBack.I b/panda/src/pgraph/cullBinFrontToBack.I index d34aedd79e..44fffcde16 100644 --- a/panda/src/pgraph/cullBinFrontToBack.I +++ b/panda/src/pgraph/cullBinFrontToBack.I @@ -47,7 +47,7 @@ operator < (const ObjectData &other) const { // Description: //////////////////////////////////////////////////////////////////// INLINE CullBinFrontToBack:: -CullBinFrontToBack(GraphicsStateGuardianBase *gsg) : - CullBin(gsg) +CullBinFrontToBack(const string &name, GraphicsStateGuardianBase *gsg) : + CullBin(name, gsg) { } diff --git a/panda/src/pgraph/cullBinFrontToBack.cxx b/panda/src/pgraph/cullBinFrontToBack.cxx index 7151899c38..c23311ba32 100644 --- a/panda/src/pgraph/cullBinFrontToBack.cxx +++ b/panda/src/pgraph/cullBinFrontToBack.cxx @@ -21,6 +21,7 @@ #include "geometricBoundingVolume.h" #include "cullableObject.h" #include "cullHandler.h" +#include "pStatTimer.h" #include @@ -77,6 +78,7 @@ add_object(CullableObject *object) { //////////////////////////////////////////////////////////////////// void CullBinFrontToBack:: finish_cull() { + PStatTimer timer(_cull_this_pcollector); sort(_objects.begin(), _objects.end()); } @@ -88,6 +90,7 @@ finish_cull() { //////////////////////////////////////////////////////////////////// void CullBinFrontToBack:: draw() { + PStatTimer timer(_draw_this_pcollector); Objects::const_iterator oi; for (oi = _objects.begin(); oi != _objects.end(); ++oi) { CullableObject *object = (*oi)._object; diff --git a/panda/src/pgraph/cullBinFrontToBack.h b/panda/src/pgraph/cullBinFrontToBack.h index c4444335d5..267d3dc2b9 100644 --- a/panda/src/pgraph/cullBinFrontToBack.h +++ b/panda/src/pgraph/cullBinFrontToBack.h @@ -38,7 +38,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA CullBinFrontToBack : public CullBin { public: - INLINE CullBinFrontToBack(GraphicsStateGuardianBase *gsg); + INLINE CullBinFrontToBack(const string &name, GraphicsStateGuardianBase *gsg); virtual ~CullBinFrontToBack(); virtual void add_object(CullableObject *object); diff --git a/panda/src/pgraph/cullBinManager.cxx b/panda/src/pgraph/cullBinManager.cxx index 656adebd6f..3210898ebb 100644 --- a/panda/src/pgraph/cullBinManager.cxx +++ b/panda/src/pgraph/cullBinManager.cxx @@ -200,19 +200,20 @@ PT(CullBin) CullBinManager:: make_new_bin(int bin_index, GraphicsStateGuardianBase *gsg) { nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), NULL); nassertr(_bin_definitions[bin_index]._in_use, NULL); + string name = get_bin_name(bin_index); switch (_bin_definitions[bin_index]._type) { case BT_back_to_front: - return new CullBinBackToFront(gsg); + return new CullBinBackToFront(name, gsg); case BT_front_to_back: - return new CullBinFrontToBack(gsg); + return new CullBinFrontToBack(name, gsg); case BT_fixed: - return new CullBinFixed(gsg); + return new CullBinFixed(name, gsg); default: - return new CullBinUnsorted(gsg); + return new CullBinUnsorted(name, gsg); } } diff --git a/panda/src/pgraph/cullBinUnsorted.I b/panda/src/pgraph/cullBinUnsorted.I index cdb03b0cc0..0a958ee95e 100644 --- a/panda/src/pgraph/cullBinUnsorted.I +++ b/panda/src/pgraph/cullBinUnsorted.I @@ -23,7 +23,7 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE CullBinUnsorted:: -CullBinUnsorted(GraphicsStateGuardianBase *gsg) : - CullBin(gsg) +CullBinUnsorted(const string &name, GraphicsStateGuardianBase *gsg) : + CullBin(name, gsg) { } diff --git a/panda/src/pgraph/cullBinUnsorted.cxx b/panda/src/pgraph/cullBinUnsorted.cxx index 923f052818..351931b818 100644 --- a/panda/src/pgraph/cullBinUnsorted.cxx +++ b/panda/src/pgraph/cullBinUnsorted.cxx @@ -19,6 +19,7 @@ #include "cullBinUnsorted.h" #include "cullHandler.h" #include "graphicsStateGuardianBase.h" +#include "pStatTimer.h" TypeHandle CullBinUnsorted::_type_handle; @@ -56,6 +57,7 @@ add_object(CullableObject *object) { //////////////////////////////////////////////////////////////////// void CullBinUnsorted:: draw() { + PStatTimer timer(_draw_this_pcollector); Objects::iterator oi; for (oi = _objects.begin(); oi != _objects.end(); ++oi) { CullableObject *object = (*oi); diff --git a/panda/src/pgraph/cullBinUnsorted.h b/panda/src/pgraph/cullBinUnsorted.h index b728682785..1545f95a6c 100644 --- a/panda/src/pgraph/cullBinUnsorted.h +++ b/panda/src/pgraph/cullBinUnsorted.h @@ -33,7 +33,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA CullBinUnsorted : public CullBin { public: - INLINE CullBinUnsorted(GraphicsStateGuardianBase *gsg); + INLINE CullBinUnsorted(const string &name, GraphicsStateGuardianBase *gsg); ~CullBinUnsorted(); virtual void add_object(CullableObject *object); diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index 4f5c43d1f2..e2ddb97ff3 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -119,9 +119,13 @@ static TimeCollectorProperties time_properties[] = { { 0, "App:Show code:Nametags:3d:Contents", { 0.0, 0.5, 0.0 } }, { 0, "App:Show code:Nametags:3d:Adjust", { 0.5, 0.0, 0.5 } }, { 1, "Cull", { 0.0, 1.0, 0.0 }, 1.0 / 30.0 }, + { 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: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 } }, { 0, "Draw:Primitive", { 0.0, 0.0, 0.5 } }, - { 0, "Draw:Show fps", { 0.5, 0.8, 1.0 } }, { 0, NULL } };