diff options
-rw-r--r-- | indra/llcommon/lltrace.h | 81 | ||||
-rw-r--r-- | indra/llcommon/lltraceaccumulators.cpp | 12 | ||||
-rw-r--r-- | indra/llcommon/lltraceaccumulators.h | 20 | ||||
-rw-r--r-- | indra/llcommon/lltracerecording.cpp | 20 | ||||
-rw-r--r-- | indra/llcommon/lltracerecording.h | 10 | ||||
-rw-r--r-- | indra/llcommon/lltracethreadrecorder.cpp | 2 |
6 files changed, 85 insertions, 60 deletions
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index f7ceaf585d..472f0b0cf0 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -80,8 +80,8 @@ public: LL_FORCE_INLINE ACCUMULATOR& getCurrentAccumulator() const { - ACCUMULATOR* accumulator_storage = AccumulatorBuffer<ACCUMULATOR>::getCurrentStorage(); - return accumulator_storage[mAccumulatorIndex]; + ACCUMULATOR* accumulator_storage = LLThreadLocalSingletonPointer<ACCUMULATOR>::getInstance(); + return accumulator_storage ? accumulator_storage[mAccumulatorIndex] : (*AccumulatorBuffer<ACCUMULATOR>::getDefaultBuffer())[mAccumulatorIndex]; } size_t getIndex() const { return mAccumulatorIndex; } @@ -222,7 +222,7 @@ public: }; template<> -class TraceType<MemStatAccumulator::ChildMemFacet> +class TraceType<MemStatAccumulator::ShadowMemFacet> : public TraceType<MemStatAccumulator> { public: @@ -258,12 +258,51 @@ public: return static_cast<TraceType<MemStatAccumulator::DeallocationCountFacet>&>(*(TraceType<MemStatAccumulator>*)this); } - TraceType<MemStatAccumulator::ChildMemFacet>& childMem() + TraceType<MemStatAccumulator::ShadowMemFacet>& childMem() { - return static_cast<TraceType<MemStatAccumulator::ChildMemFacet>&>(*(TraceType<MemStatAccumulator>*)this); + return static_cast<TraceType<MemStatAccumulator::ShadowMemFacet>&>(*(TraceType<MemStatAccumulator>*)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++; +} + +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++; +} + +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); +} + +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); +} + +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); +} + +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); +} + // measures effective memory footprint of specified type // specialize to cover different types @@ -369,9 +408,7 @@ public: void* operator new(size_t size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); - accumulator.mAllocatedCount++; + track_alloc(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -393,10 +430,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++; + track_dealloc(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -418,9 +452,7 @@ public: void *operator new [](size_t size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); - accumulator.mAllocatedCount++; + track_alloc(sMemStat, size); if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) { @@ -442,7 +474,7 @@ public: void operator delete[](void* ptr, size_t size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); accumulator.mAllocatedCount--; accumulator.mDeallocatedCount++; @@ -484,9 +516,8 @@ public: template<typename AMOUNT_T> AMOUNT_T& memClaimAmount(AMOUNT_T& size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); mMemFootprint += (size_t)size; - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); return size; } @@ -508,7 +539,7 @@ public: template<typename AMOUNT_T> AMOUNT_T& memDisclaimAmount(AMOUNT_T& size) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); return size; } @@ -521,17 +552,17 @@ private: { static void claim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); size_t footprint = MemFootprint<TRACKED>::measure(tracked); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)footprint : (F64)footprint); + claim_mem(sMemStat, footprint); tracker.mMemFootprint += footprint; } static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); size_t footprint = MemFootprint<TRACKED>::measure(tracked); - accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)footprint : -(F64)footprint); + disclaim_mem(sMemStat, footprint); tracker.mMemFootprint -= footprint; } }; @@ -541,13 +572,13 @@ private: { static void claim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mChildSize.sample(accumulator.mChildSize.hasValue() ? accumulator.mChildSize.getLastValue() + (F64)MemFootprint<TRACKED>::measure(tracked) : (F64)MemFootprint<TRACKED>::measure(tracked)); } static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mChildSize.sample(accumulator.mChildSize.hasValue() ? accumulator.mChildSize.getLastValue() - (F64)MemFootprint<TRACKED>::measure(tracked) : -(F64)MemFootprint<TRACKED>::measure(tracked)); } }; diff --git a/indra/llcommon/lltraceaccumulators.cpp b/indra/llcommon/lltraceaccumulators.cpp index b234f43337..58d0b5b227 100644 --- a/indra/llcommon/lltraceaccumulators.cpp +++ b/indra/llcommon/lltraceaccumulators.cpp @@ -70,13 +70,13 @@ void AccumulatorBufferGroup::makeCurrent() } //static -void AccumulatorBufferGroup::resetCurrent() +void AccumulatorBufferGroup::clearCurrent() { - AccumulatorBuffer<CountAccumulator>::resetCurrent(); - AccumulatorBuffer<SampleAccumulator>::resetCurrent(); - AccumulatorBuffer<EventAccumulator>::resetCurrent(); - AccumulatorBuffer<TimeBlockAccumulator>::resetCurrent(); - AccumulatorBuffer<MemStatAccumulator>::resetCurrent(); + AccumulatorBuffer<CountAccumulator>::clearCurrent(); + AccumulatorBuffer<SampleAccumulator>::clearCurrent(); + AccumulatorBuffer<EventAccumulator>::clearCurrent(); + AccumulatorBuffer<TimeBlockAccumulator>::clearCurrent(); + AccumulatorBuffer<MemStatAccumulator>::clearCurrent(); } bool AccumulatorBufferGroup::isCurrent() const diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h index e31058ab4b..c5a0693fef 100644 --- a/indra/llcommon/lltraceaccumulators.h +++ b/indra/llcommon/lltraceaccumulators.h @@ -138,17 +138,11 @@ namespace LLTrace return LLThreadLocalSingletonPointer<ACCUMULATOR>::getInstance() == mStorage; } - static void resetCurrent() + static void clearCurrent() { LLThreadLocalSingletonPointer<ACCUMULATOR>::setInstance(NULL); } - LL_FORCE_INLINE static ACCUMULATOR* getCurrentStorage() - { - ACCUMULATOR* accumulator = LLThreadLocalSingletonPointer<ACCUMULATOR>::getInstance(); - return accumulator ? accumulator : getDefaultBuffer()->mStorage; - } - // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned size_t reserveSlot() { @@ -491,7 +485,7 @@ namespace LLTrace typedef U32 value_t; }; - struct ChildMemFacet + struct ShadowMemFacet { typedef F64Bytes value_t; }; @@ -504,7 +498,7 @@ namespace LLTrace void addSamples(const MemStatAccumulator& other, EBufferAppendType append_type) { mSize.addSamples(other.mSize, append_type); - mChildSize.addSamples(other.mChildSize, append_type); + mShadowSize.addSamples(other.mShadowSize, append_type); mAllocatedCount += other.mAllocatedCount; mDeallocatedCount += other.mDeallocatedCount; } @@ -512,7 +506,7 @@ namespace LLTrace void reset(const MemStatAccumulator* other) { mSize.reset(other ? &other->mSize : NULL); - mChildSize.reset(other ? &other->mChildSize : NULL); + mShadowSize.reset(other ? &other->mShadowSize : NULL); mAllocatedCount = 0; mDeallocatedCount = 0; } @@ -520,11 +514,11 @@ namespace LLTrace void sync(F64SecondsImplicit time_stamp) { mSize.sync(time_stamp); - mChildSize.sync(time_stamp); + mShadowSize.sync(time_stamp); } SampleAccumulator mSize, - mChildSize; + mShadowSize; int mAllocatedCount, mDeallocatedCount; }; @@ -536,7 +530,7 @@ namespace LLTrace void handOffTo(AccumulatorBufferGroup& other); void makeCurrent(); bool isCurrent() const; - static void resetCurrent(); + static void clearCurrent(); void append(const AccumulatorBufferGroup& other); void merge(const AccumulatorBufferGroup& other); diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index bc98eebf31..c278901bc0 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -193,29 +193,29 @@ F64Bytes Recording::getLastValue(const TraceType<MemStatAccumulator>& stat) return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mSize.getLastValue()); } -F64Bytes Recording::getMin(const TraceType<MemStatAccumulator::ChildMemFacet>& stat) +F64Bytes Recording::getMin(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat) { - return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMin()); + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getMin()); } -F64Bytes Recording::getMean(const TraceType<MemStatAccumulator::ChildMemFacet>& stat) +F64Bytes Recording::getMean(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat) { - return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMean()); + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getMean()); } -F64Bytes Recording::getMax(const TraceType<MemStatAccumulator::ChildMemFacet>& stat) +F64Bytes Recording::getMax(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat) { - return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mChildSize.getMax()); + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getMax()); } -F64Bytes Recording::getStandardDeviation(const TraceType<MemStatAccumulator::ChildMemFacet>& stat) +F64Bytes Recording::getStandardDeviation(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat) { - return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mChildSize.getStandardDeviation()); + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getStandardDeviation()); } -F64Bytes Recording::getLastValue(const TraceType<MemStatAccumulator::ChildMemFacet>& stat) +F64Bytes Recording::getLastValue(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat) { - return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mChildSize.getLastValue()); + return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getLastValue()); } U32 Recording::getSum(const TraceType<MemStatAccumulator::AllocationCountFacet>& stat) diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index ea090e6ee1..9550838798 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -181,11 +181,11 @@ namespace LLTrace F64Bytes getStandardDeviation(const TraceType<MemStatAccumulator>& stat); F64Bytes getLastValue(const TraceType<MemStatAccumulator>& stat); - F64Bytes getMin(const TraceType<MemStatAccumulator::ChildMemFacet>& stat); - F64Bytes getMean(const TraceType<MemStatAccumulator::ChildMemFacet>& stat); - F64Bytes getMax(const TraceType<MemStatAccumulator::ChildMemFacet>& stat); - F64Bytes getStandardDeviation(const TraceType<MemStatAccumulator::ChildMemFacet>& stat); - F64Bytes getLastValue(const TraceType<MemStatAccumulator::ChildMemFacet>& stat); + F64Bytes getMin(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat); + F64Bytes getMean(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat); + F64Bytes getMax(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat); + F64Bytes getStandardDeviation(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat); + F64Bytes getLastValue(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat); U32 getSum(const TraceType<MemStatAccumulator::AllocationCountFacet>& stat); U32 getSum(const TraceType<MemStatAccumulator::DeallocationCountFacet>& stat); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 8cddc49e71..d3d9eb5ca7 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -194,7 +194,7 @@ void ThreadRecorder::deactivate( AccumulatorBufferGroup* recording ) { if (mActiveRecordings.empty()) { - AccumulatorBufferGroup::resetCurrent(); + AccumulatorBufferGroup::clearCurrent(); } else { |