From e25b5a359faaf4bb51186235567fcb1fea15e440 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 23 Sep 2013 16:07:32 -0700 Subject: refactored lltrace mem tracking to store allocation and deallocation sizes at the same time and work better with threads --- indra/llcommon/lltrace.h | 76 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 29 deletions(-) (limited to 'indra/llcommon/lltrace.h') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index bf1119d694..9c620ca5e3 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -200,7 +200,7 @@ void add(CountStatHandle& count, VALUE_T value) } template<> -class TraceType +class TraceType : public TraceType { public: @@ -211,7 +211,7 @@ public: }; template<> -class TraceType +class TraceType : public TraceType { public: @@ -221,6 +221,28 @@ public: {} }; +template<> +class TraceType + : public TraceType +{ +public: + + TraceType(const char* name, const char* description = "") + : TraceType(name, description) + {} +}; + +template<> +class TraceType + : public TraceType +{ +public: + + TraceType(const char* name, const char* description = "") + : TraceType(name, description) + {} +}; + template<> class TraceType : public TraceType @@ -248,59 +270,58 @@ public: /*virtual*/ const char* getUnitLabel() const { return "B"; } - TraceType& allocationCount() + TraceType& allocations() { - return static_cast&>(*(TraceType*)this); + return static_cast&>(*(TraceType*)this); } - TraceType& deallocationCount() + TraceType& deallocations() { - return static_cast&>(*(TraceType*)this); + return static_cast&>(*(TraceType*)this); } - TraceType& childMem() + TraceType& shadowAllocations() { - return static_cast&>(*(TraceType*)this); + return static_cast&>(*(TraceType*)this); } -}; -inline void track_alloc(MemStatHandle& measurement, size_t size) -{ - MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); - accumulator.mAllocatedCount++; -} + TraceType& shadowDeallocations() + { + return static_cast&>(*(TraceType*)this); + } -inline void track_dealloc(MemStatHandle& measurement, size_t size) -{ - MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); - accumulator.mAllocatedCount--; - accumulator.mDeallocatedCount++; -} + TraceType& shadowMem() + { + return static_cast&>(*(TraceType*)this); + } +}; inline void claim_mem(MemStatHandle& measurement, size_t size) { MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); + accumulator.mAllocated.add(1); } inline void disclaim_mem(MemStatHandle& measurement, size_t size) { MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); + accumulator.mDeallocated.add(1); } inline void claim_shadow_mem(MemStatHandle& measurement, size_t size) { MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); accumulator.mShadowSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); + accumulator.mShadowAllocated.add(1); } inline void disclaim_shadow_mem(MemStatHandle& measurement, size_t size) { MemStatAccumulator& accumulator = measurement.getCurrentAccumulator(); accumulator.mShadowSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); + accumulator.mShadowDeallocated.add(1); } // measures effective memory footprint of specified type @@ -408,7 +429,7 @@ public: void* operator new(size_t size) { - track_alloc(sMemStat, size); + claim_mem(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -430,7 +451,7 @@ public: void operator delete(void* ptr, size_t size) { - track_dealloc(sMemStat, size); + disclaim_mem(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -452,7 +473,7 @@ public: void *operator new [](size_t size) { - track_alloc(sMemStat, size); + claim_mem(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -474,10 +495,7 @@ public: void operator delete[](void* ptr, size_t size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); - accumulator.mAllocatedCount--; - accumulator.mDeallocatedCount++; + disclaim_mem(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { -- cgit v1.2.3