summaryrefslogtreecommitdiff
path: root/indra/llcommon/lltrace.h
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-09-07 22:15:41 -0700
committerRichard Linden <none@none>2013-09-07 22:15:41 -0700
commitebd62051a5b2cb1ffcfa2fccc6e6d4292039fdda (patch)
treecba06a5efe40425e8715ef89c97d61e4ab2e75aa /indra/llcommon/lltrace.h
parentc6b6ae7a45f7ab473dd839515a1717bae68af03a (diff)
memory stat for MemTrackable has name lazily initialized in an attempt
to get around link time error for unit tests on gcc
Diffstat (limited to 'indra/llcommon/lltrace.h')
-rw-r--r--indra/llcommon/lltrace.h42
1 files changed, 28 insertions, 14 deletions
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h
index 6436570492..9713bd6c04 100644
--- a/indra/llcommon/lltrace.h
+++ b/indra/llcommon/lltrace.h
@@ -62,8 +62,8 @@ public:
const std::string& getDescription() const { return mDescription; }
protected:
- const std::string mName;
- const std::string mDescription;
+ std::string mName;
+ std::string mDescription;
};
template<typename ACCUMULATOR>
@@ -240,6 +240,11 @@ public:
: trace_t(name)
{}
+ void setName(const char* name)
+ {
+ mName = name;
+ }
+
/*virtual*/ const char* getUnitLabel() const { return "B"; }
TraceType<MemStatAccumulator::AllocationCountFacet>& allocationCount()
@@ -346,6 +351,16 @@ class MemTrackable
public:
typedef void mem_trackable_tag_t;
+ MemTrackable()
+ {
+ static bool name_initialized = false;
+ if (!name_initialized)
+ {
+ name_initialized = true;
+ sMemStat.setName(typeid(DERIVED).name());
+ }
+ }
+
virtual ~MemTrackable()
{
memDisclaim(mMemFootprint);
@@ -353,7 +368,7 @@ public:
void* operator new(size_t size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size);
accumulator.mAllocatedCount++;
@@ -377,7 +392,7 @@ public:
void operator delete(void* ptr, size_t size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size);
accumulator.mAllocatedCount--;
accumulator.mDeallocatedCount++;
@@ -402,7 +417,7 @@ public:
void *operator new [](size_t size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size);
accumulator.mAllocatedCount++;
@@ -426,7 +441,7 @@ public:
void operator delete[](void* ptr, size_t size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size);
accumulator.mAllocatedCount--;
accumulator.mDeallocatedCount++;
@@ -468,7 +483,7 @@ public:
template<typename AMOUNT_T>
AMOUNT_T& memClaimAmount(AMOUNT_T& size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
mMemFootprint += (size_t)size;
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size);
return size;
@@ -492,7 +507,7 @@ public:
template<typename AMOUNT_T>
AMOUNT_T& memDisclaimAmount(AMOUNT_T& size)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size);
return size;
}
@@ -505,7 +520,7 @@ private:
{
static void claim(mem_trackable_t& tracker, const TRACKED& tracked)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
size_t footprint = MemFootprint<TRACKED>::measure(tracked);
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)footprint : (F64)footprint);
tracker.mMemFootprint += footprint;
@@ -513,7 +528,7 @@ private:
static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
size_t footprint = MemFootprint<TRACKED>::measure(tracked);
accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)footprint : -(F64)footprint);
tracker.mMemFootprint -= footprint;
@@ -525,21 +540,20 @@ private:
{
static void claim(mem_trackable_t& tracker, TRACKED& tracked)
{
- MemStatAccumulator& accumulator = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
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 = DERIVED::sMemStat.getCurrentAccumulator();
+ MemStatAccumulator& accumulator = sMemStat.getCurrentAccumulator();
accumulator.mChildSize.sample(accumulator.mChildSize.hasValue() ? accumulator.mChildSize.getLastValue() - (F64)MemFootprint<TRACKED>::measure(tracked) : -(F64)MemFootprint<TRACKED>::measure(tracked));
}
};
};
-// pretty sure typeid of containing class in static object constructor doesn't work in gcc
template<typename DERIVED, size_t ALIGNMENT>
-MemStatHandle MemTrackable<DERIVED, ALIGNMENT>::sMemStat(typeid(DERIVED).name());
+MemStatHandle MemTrackable<DERIVED, ALIGNMENT>::sMemStat("");
}
#endif // LL_LLTRACE_H