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 ++++++++++++++++++++++-------------- indra/llcommon/lltraceaccumulators.h | 58 +++++++++++++++++++-------- indra/llcommon/lltracerecording.cpp | 57 +++++++++++++++++++++++++-- indra/llcommon/lltracerecording.h | 19 +++++++-- 4 files changed, 157 insertions(+), 53 deletions(-) (limited to 'indra') 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) { diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h index c5a0693fef..37a35f4e23 100644 --- a/indra/llcommon/lltraceaccumulators.h +++ b/indra/llcommon/lltraceaccumulators.h @@ -475,40 +475,62 @@ namespace LLTrace typedef MemStatAccumulator self_t; // fake classes that allows us to view different facets of underlying statistic - struct AllocationCountFacet + struct AllocationFacet { - typedef U32 value_t; + typedef F64Bytes value_t; }; - struct DeallocationCountFacet + struct DeallocationFacet { - typedef U32 value_t; + typedef F64Bytes value_t; }; - struct ShadowMemFacet + struct ShadowAllocationFacet { typedef F64Bytes value_t; }; - MemStatAccumulator() - : mAllocatedCount(0), - mDeallocatedCount(0) - {} + struct ShadowDeallocationFacet + { + typedef F64Bytes value_t; + }; + + struct ShadowMemFacet + { + typedef F64Bytes value_t; + }; void addSamples(const MemStatAccumulator& other, EBufferAppendType append_type) { - mSize.addSamples(other.mSize, append_type); - mShadowSize.addSamples(other.mShadowSize, append_type); - mAllocatedCount += other.mAllocatedCount; - mDeallocatedCount += other.mDeallocatedCount; + mAllocated.addSamples(other.mAllocated, append_type); + mDeallocated.addSamples(other.mDeallocated, append_type); + if (append_type == SEQUENTIAL) + { + mSize.addSamples(other.mSize, SEQUENTIAL); + mShadowSize.addSamples(other.mShadowSize, SEQUENTIAL); + } + else + { + F64 allocation_delta(other.mAllocated.getSum() - other.mDeallocated.getSum()); + mSize.sample(mSize.hasValue() + ? mSize.getLastValue() + allocation_delta + : allocation_delta); + + F64 shadow_allocation_delta(other.mShadowAllocated.getSum() - other.mShadowDeallocated.getSum()); + mShadowSize.sample(mShadowSize.hasValue() + ? mShadowSize.getLastValue() + shadow_allocation_delta + : shadow_allocation_delta); + } } void reset(const MemStatAccumulator* other) { mSize.reset(other ? &other->mSize : NULL); mShadowSize.reset(other ? &other->mShadowSize : NULL); - mAllocatedCount = 0; - mDeallocatedCount = 0; + mAllocated.reset(other ? &other->mAllocated : NULL); + mDeallocated.reset(other ? &other->mDeallocated : NULL); + mShadowAllocated.reset(other ? &other->mShadowAllocated : NULL); + mShadowDeallocated.reset(other ? &other->mShadowDeallocated : NULL); } void sync(F64SecondsImplicit time_stamp) @@ -519,8 +541,10 @@ namespace LLTrace SampleAccumulator mSize, mShadowSize; - int mAllocatedCount, - mDeallocatedCount; + CountAccumulator mAllocated, + mDeallocated, + mShadowAllocated, + mShadowDeallocated; }; struct AccumulatorBufferGroup : public LLRefCount diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 7155cfa40a..5728997676 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -228,16 +228,65 @@ F64Bytes Recording::getLastValue(const TraceTypemMemStats[stat.getIndex()].mShadowSize.getLastValue()); } -U32 Recording::getSum(const TraceType& stat) +F64Bytes Recording::getSum(const TraceType& stat) { - return mBuffers->mMemStats[stat.getIndex()].mAllocatedCount; + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mAllocated.getSum()); } -U32 Recording::getSum(const TraceType& stat) +F64Bytes Recording::getPerSec(const TraceType& stat) { - return mBuffers->mMemStats[stat.getIndex()].mAllocatedCount; + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mAllocated.getSum() / mElapsedSeconds.value()); } +U32 Recording::getSampleCount(const TraceType& stat) +{ + return mBuffers->mMemStats[stat.getIndex()].mAllocated.getSampleCount(); +} + +F64Bytes Recording::getSum(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSum()); +} + +F64Bytes Recording::getPerSec(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSum() / mElapsedSeconds.value()); +} + +U32 Recording::getSampleCount(const TraceType& stat) +{ + return mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSampleCount(); +} + +F64Bytes Recording::getSum(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSum()); +} + +F64Bytes Recording::getPerSec(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSum() / mElapsedSeconds.value()); +} + +U32 Recording::getSampleCount(const TraceType& stat) +{ + return mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSampleCount(); +} + +F64Bytes Recording::getSum(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSum()); +} + +F64Bytes Recording::getPerSec(const TraceType& stat) +{ + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSum() / mElapsedSeconds.value()); +} + +U32 Recording::getSampleCount(const TraceType& stat) +{ + return mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSampleCount(); +} F64 Recording::getSum( const TraceType& stat ) { diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 2f5cefa8eb..466efe44ce 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -177,7 +177,7 @@ namespace LLTrace F32 getPerSec(const TraceType& stat); // Memory accessors - bool hasValue(const TraceType& stat); + bool hasValue(const TraceType& stat); bool hasValue(const TraceType& stat); F64Bytes getMin(const TraceType& stat); @@ -192,8 +192,21 @@ namespace LLTrace F64Bytes getStandardDeviation(const TraceType& stat); F64Bytes getLastValue(const TraceType& stat); - U32 getSum(const TraceType& stat); - U32 getSum(const TraceType& stat); + F64Bytes getSum(const TraceType& stat); + F64Bytes getPerSec(const TraceType& stat); + U32 getSampleCount(const TraceType& stat); + + F64Bytes getSum(const TraceType& stat); + F64Bytes getPerSec(const TraceType& stat); + U32 getSampleCount(const TraceType& stat); + + F64Bytes getSum(const TraceType& stat); + F64Bytes getPerSec(const TraceType& stat); + U32 getSampleCount(const TraceType& stat); + + F64Bytes getSum(const TraceType& stat); + F64Bytes getPerSec(const TraceType& stat); + U32 getSampleCount(const TraceType& stat); // CountStatHandle accessors F64 getSum(const TraceType& stat); -- cgit v1.2.3