summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-09-23 16:07:32 -0700
committerRichard Linden <none@none>2013-09-23 16:07:32 -0700
commite25b5a359faaf4bb51186235567fcb1fea15e440 (patch)
tree8af498e5753aa49a56fe6b88224f89cda89d19ad
parentb16fb80906b4098b68d8f555998f42a3017ee095 (diff)
refactored lltrace mem tracking to store allocation and deallocation sizes
at the same time and work better with threads
-rw-r--r--indra/llcommon/lltrace.h76
-rw-r--r--indra/llcommon/lltraceaccumulators.h58
-rw-r--r--indra/llcommon/lltracerecording.cpp57
-rw-r--r--indra/llcommon/lltracerecording.h19
4 files changed, 157 insertions, 53 deletions
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<T>& count, VALUE_T value)
}
template<>
-class TraceType<MemStatAccumulator::AllocationCountFacet>
+class TraceType<MemStatAccumulator::AllocationFacet>
: public TraceType<MemStatAccumulator>
{
public:
@@ -211,7 +211,7 @@ public:
};
template<>
-class TraceType<MemStatAccumulator::DeallocationCountFacet>
+class TraceType<MemStatAccumulator::DeallocationFacet>
: public TraceType<MemStatAccumulator>
{
public:
@@ -222,6 +222,28 @@ public:
};
template<>
+class TraceType<MemStatAccumulator::ShadowAllocationFacet>
+ : public TraceType<MemStatAccumulator>
+{
+public:
+
+ TraceType(const char* name, const char* description = "")
+ : TraceType<MemStatAccumulator>(name, description)
+ {}
+};
+
+template<>
+class TraceType<MemStatAccumulator::ShadowDeallocationFacet>
+ : public TraceType<MemStatAccumulator>
+{
+public:
+
+ TraceType(const char* name, const char* description = "")
+ : TraceType<MemStatAccumulator>(name, description)
+ {}
+};
+
+template<>
class TraceType<MemStatAccumulator::ShadowMemFacet>
: public TraceType<MemStatAccumulator>
{
@@ -248,59 +270,58 @@ public:
/*virtual*/ const char* getUnitLabel() const { return "B"; }
- TraceType<MemStatAccumulator::AllocationCountFacet>& allocationCount()
+ TraceType<MemStatAccumulator::AllocationFacet>& allocations()
{
- return static_cast<TraceType<MemStatAccumulator::AllocationCountFacet>&>(*(TraceType<MemStatAccumulator>*)this);
+ return static_cast<TraceType<MemStatAccumulator::AllocationFacet>&>(*(TraceType<MemStatAccumulator>*)this);
}
- TraceType<MemStatAccumulator::DeallocationCountFacet>& deallocationCount()
+ TraceType<MemStatAccumulator::DeallocationFacet>& deallocations()
{
- return static_cast<TraceType<MemStatAccumulator::DeallocationCountFacet>&>(*(TraceType<MemStatAccumulator>*)this);
+ return static_cast<TraceType<MemStatAccumulator::DeallocationFacet>&>(*(TraceType<MemStatAccumulator>*)this);
}
- TraceType<MemStatAccumulator::ShadowMemFacet>& childMem()
+ TraceType<MemStatAccumulator::ShadowAllocationFacet>& shadowAllocations()
{
- return static_cast<TraceType<MemStatAccumulator::ShadowMemFacet>&>(*(TraceType<MemStatAccumulator>*)this);
+ return static_cast<TraceType<MemStatAccumulator::ShadowAllocationFacet>&>(*(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++;
-}
+ TraceType<MemStatAccumulator::ShadowDeallocationFacet>& shadowDeallocations()
+ {
+ return static_cast<TraceType<MemStatAccumulator::ShadowDeallocationFacet>&>(*(TraceType<MemStatAccumulator>*)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<MemStatAccumulator::ShadowMemFacet>& shadowMem()
+ {
+ return static_cast<TraceType<MemStatAccumulator::ShadowMemFacet>&>(*(TraceType<MemStatAccumulator>*)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 TraceType<MemStatAccumulator::ShadowMemFa
return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowSize.getLastValue());
}
-U32 Recording::getSum(const TraceType<MemStatAccumulator::AllocationCountFacet>& stat)
+F64Bytes Recording::getSum(const TraceType<MemStatAccumulator::AllocationFacet>& stat)
{
- return mBuffers->mMemStats[stat.getIndex()].mAllocatedCount;
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mAllocated.getSum());
}
-U32 Recording::getSum(const TraceType<MemStatAccumulator::DeallocationCountFacet>& stat)
+F64Bytes Recording::getPerSec(const TraceType<MemStatAccumulator::AllocationFacet>& stat)
{
- return mBuffers->mMemStats[stat.getIndex()].mAllocatedCount;
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mAllocated.getSum() / mElapsedSeconds.value());
}
+U32 Recording::getSampleCount(const TraceType<MemStatAccumulator::AllocationFacet>& stat)
+{
+ return mBuffers->mMemStats[stat.getIndex()].mAllocated.getSampleCount();
+}
+
+F64Bytes Recording::getSum(const TraceType<MemStatAccumulator::DeallocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSum());
+}
+
+F64Bytes Recording::getPerSec(const TraceType<MemStatAccumulator::DeallocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSum() / mElapsedSeconds.value());
+}
+
+U32 Recording::getSampleCount(const TraceType<MemStatAccumulator::DeallocationFacet>& stat)
+{
+ return mBuffers->mMemStats[stat.getIndex()].mDeallocated.getSampleCount();
+}
+
+F64Bytes Recording::getSum(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSum());
+}
+
+F64Bytes Recording::getPerSec(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSum() / mElapsedSeconds.value());
+}
+
+U32 Recording::getSampleCount(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat)
+{
+ return mBuffers->mMemStats[stat.getIndex()].mShadowAllocated.getSampleCount();
+}
+
+F64Bytes Recording::getSum(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSum());
+}
+
+F64Bytes Recording::getPerSec(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat)
+{
+ return F64Bytes(mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSum() / mElapsedSeconds.value());
+}
+
+U32 Recording::getSampleCount(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat)
+{
+ return mBuffers->mMemStats[stat.getIndex()].mShadowDeallocated.getSampleCount();
+}
F64 Recording::getSum( const TraceType<CountAccumulator>& 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<TimeBlockAccumulator::CallCountFacet>& stat);
// Memory accessors
- bool hasValue(const TraceType<MemStatAccumulator>& stat);
+ bool hasValue(const TraceType<MemStatAccumulator>& stat);
bool hasValue(const TraceType<MemStatAccumulator::ShadowMemFacet>& stat);
F64Bytes getMin(const TraceType<MemStatAccumulator>& stat);
@@ -192,8 +192,21 @@ namespace LLTrace
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);
+ F64Bytes getSum(const TraceType<MemStatAccumulator::AllocationFacet>& stat);
+ F64Bytes getPerSec(const TraceType<MemStatAccumulator::AllocationFacet>& stat);
+ U32 getSampleCount(const TraceType<MemStatAccumulator::AllocationFacet>& stat);
+
+ F64Bytes getSum(const TraceType<MemStatAccumulator::DeallocationFacet>& stat);
+ F64Bytes getPerSec(const TraceType<MemStatAccumulator::DeallocationFacet>& stat);
+ U32 getSampleCount(const TraceType<MemStatAccumulator::DeallocationFacet>& stat);
+
+ F64Bytes getSum(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat);
+ F64Bytes getPerSec(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat);
+ U32 getSampleCount(const TraceType<MemStatAccumulator::ShadowAllocationFacet>& stat);
+
+ F64Bytes getSum(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat);
+ F64Bytes getPerSec(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat);
+ U32 getSampleCount(const TraceType<MemStatAccumulator::ShadowDeallocationFacet>& stat);
// CountStatHandle accessors
F64 getSum(const TraceType<CountAccumulator>& stat);