From 8b760751337a66f09bc034cabab62e169016edef Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 28 Jun 2007 04:12:14 +0000 Subject: [PATCH] repair pstats mem tracking --- dtool/src/dtoolbase/pset.h | 8 ++++---- dtool/src/dtoolbase/typeHandle.cxx | 2 ++ dtool/src/dtoolbase/typeHandle.h | 2 +- dtool/src/prc/configVariableCore.cxx | 3 ++- panda/src/pstatclient/pStatClient.cxx | 18 +++++++++--------- panda/src/pstatclient/pStatClient.h | 6 +++--- panda/src/pstatclient/pStatProperties.cxx | 10 ++++++---- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dtool/src/dtoolbase/pset.h b/dtool/src/dtoolbase/pset.h index 22f09b6c6f..15b0c23db4 100644 --- a/dtool/src/dtoolbase/pset.h +++ b/dtool/src/dtoolbase/pset.h @@ -57,9 +57,9 @@ class pset : public set > { public: typedef pallocator_single allocator; typedef set base_class; - pset(TypeHandle type_handle = pmap_type_handle) : base_class(Compare(), allocator(type_handle)) { } + pset(TypeHandle type_handle = pset_type_handle) : base_class(Compare(), allocator(type_handle)) { } pset(const pset ©) : base_class(copy) { } - pset(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : base_class(comp, type_handle) { } + pset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : base_class(comp, type_handle) { } #ifdef USE_TAU std::pair @@ -118,9 +118,9 @@ template > class pmultiset : public multiset > { public: typedef pallocator_single allocator; - pmultiset(TypeHandle type_handle = pmap_type_handle) : multiset(Compare(), allocator(type_handle)) { } + pmultiset(TypeHandle type_handle = pset_type_handle) : multiset(Compare(), allocator(type_handle)) { } pmultiset(const pmultiset ©) : multiset(copy) { } - pmultiset(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : multiset(comp, type_handle) { } + pmultiset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : multiset(comp, type_handle) { } }; #ifdef HAVE_STL_HASH diff --git a/dtool/src/dtoolbase/typeHandle.cxx b/dtool/src/dtoolbase/typeHandle.cxx index 5056ece255..fb3512802e 100644 --- a/dtool/src/dtoolbase/typeHandle.cxx +++ b/dtool/src/dtoolbase/typeHandle.cxx @@ -59,6 +59,7 @@ inc_memory_usage(MemoryClass memory_class, int size) { TypeRegistryNode *rnode = TypeRegistry::ptr()->look_up(*this, NULL); assert(rnode != (TypeRegistryNode *)NULL); AtomicAdjust::add(rnode->_memory_usage[memory_class], (PN_int32)size); + assert(rnode->_memory_usage[memory_class] >= 0); } } #endif // DO_MEMORY_USAGE @@ -77,6 +78,7 @@ dec_memory_usage(MemoryClass memory_class, int size) { TypeRegistryNode *rnode = TypeRegistry::ptr()->look_up(*this, NULL); assert(rnode != (TypeRegistryNode *)NULL); AtomicAdjust::add(rnode->_memory_usage[memory_class], -(PN_int32)size); + assert(rnode->_memory_usage[memory_class] >= 0); } } #endif // DO_MEMORY_USAGE diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index 8ff08e2c83..8510516cc4 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -131,7 +131,7 @@ PUBLISHED: void inc_memory_usage(MemoryClass memory_class, int size); void dec_memory_usage(MemoryClass memory_class, int size); #else - INLINE size_t get_memory_usage(MemoryClass) const { return 0; } + INLINE int get_memory_usage(MemoryClass) const { return 0; } INLINE void inc_memory_usage(MemoryClass, int) { } INLINE void dec_memory_usage(MemoryClass, int) { } #endif // DO_MEMORY_USAGE diff --git a/dtool/src/prc/configVariableCore.cxx b/dtool/src/prc/configVariableCore.cxx index dce04fc266..4d0caf585d 100644 --- a/dtool/src/prc/configVariableCore.cxx +++ b/dtool/src/prc/configVariableCore.cxx @@ -491,7 +491,8 @@ sort_declarations() { // need to be recomputed all that often. _unique_declarations.clear(); - pset already_added(TypeHandle::none()); + init_system_type_handles(); // Make sure pset_type_handle is initted. + pset already_added; for (di = _trusted_declarations.begin(); di != _trusted_declarations.end(); ++di) { diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 6e4d7b96cb..2b590b8f7f 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -33,12 +33,12 @@ #include "clockObject.h" #include "neverFreeMemory.h" -PStatCollector PStatClient::_total_size_pcollector("Main memory"); -PStatCollector PStatClient::_cpp_size_pcollector("Main memory:C++"); -PStatCollector PStatClient::_cpp_other_size_pcollector("Main memory:C++:Other"); -PStatCollector PStatClient::_nf_unused_size_pcollector("Main memory:NeverFree:Unused"); -PStatCollector PStatClient::_nf_other_size_pcollector("Main memory:NeverFree:Other"); -PStatCollector PStatClient::_interpreter_size_pcollector("Main memory:Interpreter"); +PStatCollector PStatClient::_nf_unused_size_pcollector("Track memory 1:NeverFree:Unused"); +PStatCollector PStatClient::_nf_other_size_pcollector("Track memory 1:NeverFree:Other"); +PStatCollector PStatClient::_cpp_other_size_pcollector("Track memory 1:Heap:Other"); +PStatCollector PStatClient::_total_size_pcollector("Track memory 2"); +PStatCollector PStatClient::_cpp_size_pcollector("Track memory 2:C++"); +PStatCollector PStatClient::_interpreter_size_pcollector("Track memory 2:Interpreter"); PStatCollector PStatClient::_pstats_pcollector("*:PStats"); PStatCollector PStatClient::_clock_wait_pcollector("Wait:Clock Wait:Sleep"); PStatCollector PStatClient::_clock_busy_wait_pcollector("Wait:Clock Wait:Spin"); @@ -219,7 +219,7 @@ main_tick() { _total_size_pcollector.set_level(MemoryUsage::get_total_size()); } if (MemoryUsage::has_cpp_size()) { - _cpp_size_pcollector.set_level(MemoryUsage::get_cpp_size() - NeverFreeMemory::get_total_alloc()); + _cpp_size_pcollector.set_level(MemoryUsage::get_cpp_size()); } if (MemoryUsage::has_interpreter_size()) { _interpreter_size_pcollector.set_level(MemoryUsage::get_interpreter_size()); @@ -277,10 +277,10 @@ main_tick() { break; default: - category = "C++"; + category = "Heap"; } ostringstream strm; - strm << "Main memory:" << category << ":" << type << ":" << mc; + strm << "Track memory 1:" << category << ":" << type << ":" << mc; col = PStatCollector(strm.str()); } col.set_level(usage); diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 073009164c..f47720b160 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -227,11 +227,11 @@ private: PStatClientImpl *_impl; - static PStatCollector _total_size_pcollector; - static PStatCollector _cpp_size_pcollector; - static PStatCollector _cpp_other_size_pcollector; static PStatCollector _nf_unused_size_pcollector; static PStatCollector _nf_other_size_pcollector; + static PStatCollector _cpp_other_size_pcollector; + static PStatCollector _total_size_pcollector; + static PStatCollector _cpp_size_pcollector; static PStatCollector _interpreter_size_pcollector; static PStatCollector _pstats_pcollector; static PStatCollector _clock_wait_pcollector; diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index ced92bbd59..2d2f7d86d4 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -196,10 +196,12 @@ static LevelCollectorProperties level_properties[] = { { 1, "State changes:Textures", { 0.8, 0.2, 0.2 } }, { 1, "Occlusion tests", { 0.9, 0.8, 0.3 }, "", 500.0 }, { 1, "Occlusion results", { 0.3, 0.9, 0.8 }, "", 500.0 }, - { 1, "Main memory", { 0.5, 1.0, 0.5 }, "MB", 64, 1048576 }, - { 1, "Main memory:C++", { 0.2, 0.2, 1.0 } }, - { 1, "Main memory:NeverFree", { 0.2, 0.5, 0.8 } }, - { 1, "Main memory:Interpreter", { 0.8, 0.2, 0.5 } }, + { 1, "Track memory 1", { 0.5, 1.0, 0.5 }, "MB", 64, 1048576 }, + { 1, "Track memory 1:Heap", { 0.8, 0.2, 1.0 } }, + { 1, "Track memory 1:NeverFree", { 0.2, 0.5, 0.8 } }, + { 1, "Track memory 2", { 0.5, 1.0, 0.5 }, "MB", 64, 1048576 }, + { 1, "Track memory 2:C++", { 0.2, 0.2, 1.0 } }, + { 1, "Track memory 2:Interpreter", { 0.8, 0.2, 0.5 } }, { 1, "Vertex Data", { 1.0, 0.4, 0.0 }, "MB", 64, 1048576 }, { 1, "Vertex Data:Independent", { 0.9, 0.1, 0.9 } }, { 1, "Vertex Data:Small", { 0.2, 0.3, 0.4 } },