Browse Source

Improved pstats support for texmem

David Rose 24 years ago
parent
commit
d7ed6d3cbd

+ 2 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -19,6 +19,8 @@ PStatCollector GraphicsStateGuardian::_total_texusage_pcollector("Texture usage"
 PStatCollector GraphicsStateGuardian::_active_texusage_pcollector("Texture usage:Active");
 PStatCollector GraphicsStateGuardian::_active_texusage_pcollector("Texture usage:Active");
 PStatCollector GraphicsStateGuardian::_total_texmem_pcollector("Texture memory");
 PStatCollector GraphicsStateGuardian::_total_texmem_pcollector("Texture memory");
 PStatCollector GraphicsStateGuardian::_used_texmem_pcollector("Texture memory:In use");
 PStatCollector GraphicsStateGuardian::_used_texmem_pcollector("Texture memory:In use");
+PStatCollector GraphicsStateGuardian::_texmgrmem_total_pcollector("Texture manager");
+PStatCollector GraphicsStateGuardian::_texmgrmem_resident_pcollector("Texture manager:Resident");
 PStatCollector GraphicsStateGuardian::_vertices_pcollector("Vertices");
 PStatCollector GraphicsStateGuardian::_vertices_pcollector("Vertices");
 PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Triangle strips");
 PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Triangle strips");
 PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans");
 PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans");

+ 2 - 0
panda/src/display/graphicsStateGuardian.h

@@ -180,6 +180,8 @@ public:
   static PStatCollector _active_texusage_pcollector;
   static PStatCollector _active_texusage_pcollector;
   static PStatCollector _total_texmem_pcollector;
   static PStatCollector _total_texmem_pcollector;
   static PStatCollector _used_texmem_pcollector;
   static PStatCollector _used_texmem_pcollector;
+  static PStatCollector _texmgrmem_total_pcollector;
+  static PStatCollector _texmgrmem_resident_pcollector;
   static PStatCollector _vertices_pcollector;
   static PStatCollector _vertices_pcollector;
   static PStatCollector _vertices_tristrip_pcollector;
   static PStatCollector _vertices_tristrip_pcollector;
   static PStatCollector _vertices_trifan_pcollector;
   static PStatCollector _vertices_trifan_pcollector;

+ 4 - 0
panda/src/display/textureContext.cxx

@@ -25,6 +25,9 @@ estimate_texture_memory() {
 
 
   size_t pixels = pb->get_xsize() * pb->get_ysize();
   size_t pixels = pb->get_xsize() * pb->get_ysize();
 
 
+  size_t bpp = 4;
+
+  /*
   size_t bpp = 1;
   size_t bpp = 1;
   switch (pb->get_format()) {
   switch (pb->get_format()) {
   case PixelBuffer::F_rgb332:
   case PixelBuffer::F_rgb332:
@@ -60,6 +63,7 @@ estimate_texture_memory() {
     bpp = 6;
     bpp = 6;
     break;
     break;
   }
   }
+  */
 
 
   size_t bytes = pixels * bpp;
   size_t bytes = pixels * bpp;
 
 

+ 29 - 0
panda/src/dxgsg/dxGraphicsStateGuardian.cxx

@@ -67,6 +67,7 @@
 #include <throw_event.h>
 #include <throw_event.h>
 #include <mmsystem.h>
 #include <mmsystem.h>
 #include <pStatTimer.h>
 #include <pStatTimer.h>
+#include <pStatCollector.h>
 
 
 #define DISABLE_POLYGON_OFFSET_DECALING
 #define DISABLE_POLYGON_OFFSET_DECALING
 // currently doesnt work well enough in toontown models for us to use
 // currently doesnt work well enough in toontown models for us to use
@@ -777,6 +778,12 @@ render_frame(const AllAttributesWrapper &initial_state) {
 
 
 	show_frame();
 	show_frame();
 
 
+#ifdef DO_PSTATS
+  if (_texmgrmem_total_pcollector.is_active()) {
+    report_texmgr_stats();
+  }
+#endif
+
 #ifdef PRINT_TEXSTATS
 #ifdef PRINT_TEXSTATS
 	{
 	{
 
 
@@ -840,6 +847,28 @@ render_frame(const AllAttributesWrapper &initial_state) {
 #endif
 #endif
 }
 }
 
 
+#ifdef DO_PSTATS
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian::report_texmgr_stats
+//       Access: Protected
+//  Description: Reports the DX texture manager's activity to PStats.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian::
+report_texmgr_stats() {
+  HRESULT hr;
+
+  D3DDEVINFO_TEXTUREMANAGER tminfo;
+  ZeroMemory(&tminfo, sizeof(tminfo));
+  hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,
+                           &tminfo, sizeof(tminfo));
+  
+  // Quietly ignore an error in GetInfo().
+  if (hr == D3D_OK) {
+    _texmgrmem_total_pcollector.set_level(tminfo.dwTotalBytes);
+    _texmgrmem_resident_pcollector.set_level(tminfo.dwWorkingSetBytes);
+  }
+}
+#endif  // DO_PSTATS
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian::render_scene
 //     Function: DXGraphicsStateGuardian::render_scene

+ 4 - 0
panda/src/dxgsg/dxGraphicsStateGuardian.h

@@ -265,6 +265,10 @@ protected:
   size_t draw_prim_setup(const Geom *geom) ;
   size_t draw_prim_setup(const Geom *geom) ;
   void draw_multitri(const Geom *geom, D3DPRIMITIVETYPE tri_id);
   void draw_multitri(const Geom *geom, D3DPRIMITIVETYPE tri_id);
 
 
+#ifdef DO_PSTATS
+  void report_texmgr_stats();
+#endif
+
   //   for drawing primitives
   //   for drawing primitives
   Colorf	p_color;
   Colorf	p_color;
   Normalf	p_normal;
   Normalf	p_normal;

+ 1 - 0
panda/src/pstatclient/config_pstats.cxx

@@ -30,6 +30,7 @@ const float pstats_target_frame_rate = config_pstats.GetFloat("pstats-target-fra
 // not the client.
 // not the client.
 const bool pstats_scroll_mode = config_pstats.GetBool("pstats-scroll-mode", true);
 const bool pstats_scroll_mode = config_pstats.GetBool("pstats-scroll-mode", true);
 const float pstats_history = config_pstats.GetFloat("pstats-history", 30.0);
 const float pstats_history = config_pstats.GetFloat("pstats-history", 30.0);
+const bool pstats_threaded_write = config_pstats.GetBool("pstats-threaded-write", false);
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: init_libpstatclient
 //     Function: init_libpstatclient

+ 2 - 0
panda/src/pstatclient/config_pstats.h

@@ -25,6 +25,8 @@ extern EXPCL_PANDA const float pstats_target_frame_rate;
 extern EXPCL_PANDA const bool pstats_scroll_mode;
 extern EXPCL_PANDA const bool pstats_scroll_mode;
 extern EXPCL_PANDA const float pstats_history;
 extern EXPCL_PANDA const float pstats_history;
 
 
+extern EXPCL_PANDA const bool pstats_threaded_write;
+
 extern EXPCL_PANDA void init_libpstatclient();
 extern EXPCL_PANDA void init_libpstatclient();
 
 
 #endif
 #endif

+ 3 - 3
panda/src/pstatclient/pStatClient.I

@@ -67,7 +67,7 @@ get_max_rate() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool PStatClient::
 INLINE bool PStatClient::
 connect(const string &hostname, int port) {
 connect(const string &hostname, int port) {
-  return get_global_pstats()->ns_connect(hostname, port);
+  return get_global_pstats()->client_connect(hostname, port);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -77,7 +77,7 @@ connect(const string &hostname, int port) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void PStatClient::
 INLINE void PStatClient::
 disconnect() {
 disconnect() {
-  get_global_pstats()->ns_disconnect();
+  get_global_pstats()->client_disconnect();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -88,5 +88,5 @@ disconnect() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE bool PStatClient::
 INLINE bool PStatClient::
 is_connected() {
 is_connected() {
-  return get_global_pstats()->ns_is_connected();
+  return get_global_pstats()->client_is_connected();
 }
 }

+ 28 - 8
panda/src/pstatclient/pStatClient.cxx

@@ -46,7 +46,7 @@ PerThreadData() {
 PStatClient::
 PStatClient::
 PStatClient() :
 PStatClient() :
   _reader(this, 0),
   _reader(this, 0),
-  _writer(this, 0)
+  _writer(this, pstats_threaded_write ? 1 : 0)
 {
 {
   _is_connected = false;
   _is_connected = false;
   _got_udp_port = false;
   _got_udp_port = false;
@@ -369,13 +369,13 @@ get_global_pstats() {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: PStatClient::ns_connect
+//     Function: PStatClient::client_connect
 //       Access: Private
 //       Access: Private
 //  Description: The nonstatic implementation of connect().
 //  Description: The nonstatic implementation of connect().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool PStatClient::
 bool PStatClient::
-ns_connect(string hostname, int port) {
-  ns_disconnect();
+client_connect(string hostname, int port) {
+  client_disconnect();
 
 
   if (hostname.empty()) {
   if (hostname.empty()) {
     hostname = pstats_host;
     hostname = pstats_host;
@@ -410,12 +410,12 @@ ns_connect(string hostname, int port) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: PStatClient::ns_disconnect
+//     Function: PStatClient::client_disconnect
 //       Access: Private
 //       Access: Private
 //  Description: The nonstatic implementation of disconnect().
 //  Description: The nonstatic implementation of disconnect().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PStatClient::
 void PStatClient::
-ns_disconnect() {
+client_disconnect() {
   if (_is_connected) {
   if (_is_connected) {
     _reader.remove_connection(_tcp_connection);
     _reader.remove_connection(_tcp_connection);
     close_connection(_tcp_connection);
     close_connection(_tcp_connection);
@@ -451,15 +451,35 @@ ns_disconnect() {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: PStatClient::ns_is_connected
+//     Function: PStatClient::client_is_connected
 //       Access: Public
 //       Access: Public
 //  Description: The nonstatic implementation of is_connected().
 //  Description: The nonstatic implementation of is_connected().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool PStatClient::
 bool PStatClient::
-ns_is_connected() const {
+client_is_connected() const {
   return _is_connected;
   return _is_connected;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PStatClient::is_active
+//       Access: Private
+//  Description: Returns true if the indicated collector/thread
+//               combination is active, and we are transmitting stats
+//               data, or false otherwise.
+//
+//               Normally you would not use this interface directly;
+//               instead, call PStatCollector::is_active().
+////////////////////////////////////////////////////////////////////
+bool PStatClient::
+is_active(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 (_is_connected &&
+          _collectors[collector_index]._def->_is_active &&
+          _threads[thread_index]._is_active);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PStatClient::start_collector
 //     Function: PStatClient::start_collector
 //       Access: Private
 //       Access: Private

+ 18 - 7
panda/src/pstatclient/pStatClient.h

@@ -31,6 +31,14 @@ class PStatThread;
 // Description : Manages the communications to report statistics via a
 // Description : Manages the communications to report statistics via a
 //               network connection to a remote PStatServer.
 //               network connection to a remote PStatServer.
 //
 //
+//               Normally, there is only one PStatClient in the world,
+//               although it is possible to have multiple PStatClients
+//               if extraordinary circumstances require in.  Since
+//               each PStatCollector registers itself with the
+//               PStatClient when it is created, having multiple
+//               PStatClients requires special care when constructing
+//               the various PStatCollectors.
+//
 //               If DO_PSTATS is not defined, we don't want to use
 //               If DO_PSTATS is not defined, we don't want to use
 //               stats at all.  This class is therefore defined as a
 //               stats at all.  This class is therefore defined as a
 //               stub class.
 //               stub class.
@@ -59,23 +67,26 @@ public:
   const ClockObject &get_clock() const;
   const ClockObject &get_clock() const;
   PStatThread get_main_thread() const;
   PStatThread get_main_thread() const;
 
 
-  static void main_tick();
-  static PStatClient *get_global_pstats();
-
 PUBLISHED:
 PUBLISHED:
   INLINE static bool connect(const string &hostname = string(), int port = -1);
   INLINE static bool connect(const string &hostname = string(), int port = -1);
   INLINE static void disconnect();
   INLINE static void disconnect();
   INLINE static bool is_connected();
   INLINE static bool is_connected();
 
 
-private:
-  bool ns_connect(string hostname, int port);
-  void ns_disconnect();
-  bool ns_is_connected() const;
+public:
+  static void main_tick();
+  static PStatClient *get_global_pstats();
+
+  bool client_connect(string hostname, int port);
+  void client_disconnect();
+  bool client_is_connected() const;
 
 
+private:
   PStatCollector make_collector_with_relname(int parent_index, string relname);
   PStatCollector make_collector_with_relname(int parent_index, string relname);
   PStatCollector make_collector_with_name(int parent_index, const string &name);
   PStatCollector make_collector_with_name(int parent_index, const string &name);
   PStatThread make_thread(const string &name);
   PStatThread make_thread(const string &name);
 
 
+  bool is_active(int collector_index, int thread_index) const;
+
   void start(int collector_index, int thread_index, float as_of);
   void start(int collector_index, int thread_index, float as_of);
   void stop(int collector_index, int thread_index, float as_of);
   void stop(int collector_index, int thread_index, float as_of);
 
 

+ 24 - 0
panda/src/pstatclient/pStatCollector.I

@@ -112,6 +112,30 @@ operator = (const PStatCollector &copy) {
   _index = copy._index;
   _index = copy._index;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PStatCollector::is_active
+//       Access: Public
+//  Description: Returns true if this particular collector is active
+//               on the default thread, and we are currently
+//               transmitting PStats data.
+////////////////////////////////////////////////////////////////////
+INLINE bool PStatCollector::
+is_active() {
+  return _client->is_active(_index, 0);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PStatCollector::is_active
+//       Access: Public
+//  Description: Returns true if this particular collector is active
+//               on the indicated thread, and we are currently
+//               transmitting PStats data.
+////////////////////////////////////////////////////////////////////
+INLINE bool PStatCollector::
+is_active(const PStatThread &thread) {
+  return _client->is_active(_index, thread._index);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PStatCollector::start
 //     Function: PStatCollector::start
 //       Access: Public
 //       Access: Public

+ 6 - 0
panda/src/pstatclient/pStatCollector.h

@@ -53,6 +53,9 @@ public:
   INLINE PStatCollector(const PStatCollector &copy);
   INLINE PStatCollector(const PStatCollector &copy);
   INLINE void operator = (const PStatCollector &copy);
   INLINE void operator = (const PStatCollector &copy);
 
 
+  INLINE bool is_active();
+  INLINE bool is_active(const PStatThread &thread);
+
   INLINE void start();
   INLINE void start();
   INLINE void start(const PStatThread &thread);
   INLINE void start(const PStatThread &thread);
   INLINE void start(const PStatThread &thread, float as_of);
   INLINE void start(const PStatThread &thread, float as_of);
@@ -87,6 +90,9 @@ public:
 			const RGBColorf & = RGBColorf::zero(),
 			const RGBColorf & = RGBColorf::zero(),
 			int = -1) { }
 			int = -1) { }
 
 
+  INLINE bool is_active() { return false; }
+  INLINE bool is_active(const PStatThread &) { return false; }
+
   INLINE void start() { }
   INLINE void start() { }
   INLINE void start(const PStatThread &) { }
   INLINE void start(const PStatThread &) { }
   INLINE void start(const PStatThread &, float) { }
   INLINE void start(const PStatThread &, float) { }

+ 4 - 2
panda/src/pstatclient/pStatProperties.cxx

@@ -108,10 +108,12 @@ static TimeCollectorProperties time_properties[] = {
 };
 };
 
 
 static LevelCollectorProperties level_properties[] = {
 static LevelCollectorProperties level_properties[] = {
-  { 1, "Texture usage",                    { 1.0, 0.0, 0.0 },  "MB", 12, 1048576 },
-  { 1, "Texture usage:Active",             { 1.0, 1.0, 0.0 } },
+  { 1, "Texture usage",                    { 1.0, 0.0, 0.5 },  "MB", 12, 1048576 },
+  { 1, "Texture usage:Active",             { 0.5, 1.0, 0.8 } },
   { 1, "Texture memory",                   { 0.0, 0.0, 1.0 },  "MB", 12, 1048576 },
   { 1, "Texture memory",                   { 0.0, 0.0, 1.0 },  "MB", 12, 1048576 },
   { 1, "Texture memory:In use",            { 0.0, 1.0, 1.0 } },
   { 1, "Texture memory:In use",            { 0.0, 1.0, 1.0 } },
+  { 1, "Texture manager",                  { 1.0, 0.0, 0.0 },  "MB", 12, 1048576 },
+  { 1, "Texture manager:Resident",         { 1.0, 1.0, 0.0 } },
   { 1, "Vertices",                         { 0.5, 0.2, 0.0 },  "K", 10, 1000 },
   { 1, "Vertices",                         { 0.5, 0.2, 0.0 },  "K", 10, 1000 },
   { 1, "Vertices:Other",                   { 0.2, 0.2, 0.2 } },
   { 1, "Vertices:Other",                   { 0.2, 0.2, 0.2 } },
   { 1, "Vertices:Triangles",               { 0.8, 0.8, 0.8 } },
   { 1, "Vertices:Triangles",               { 0.8, 0.8, 0.8 } },