diff options
Diffstat (limited to 'indra/llcommon/lltrace.h')
-rw-r--r-- | indra/llcommon/lltrace.h | 259 |
1 files changed, 167 insertions, 92 deletions
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6dfe9e4b4e..37196d9f63 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -46,13 +46,13 @@ namespace LLTrace class Recording; typedef LLUnit<LLUnits::Bytes, F64> Bytes; -typedef LLUnit<LLUnits::Kilobytes, F64> Kilobytes; -typedef LLUnit<LLUnits::Megabytes, F64> Megabytes; -typedef LLUnit<LLUnits::Gigabytes, F64> Gigabytes; +typedef LLUnit<LLUnits::Kibibytes, F64> Kibibytes; +typedef LLUnit<LLUnits::Mibibytes, F64> Mibibytes; +typedef LLUnit<LLUnits::Gibibytes, F64> Gibibytes; typedef LLUnit<LLUnits::Bits, F64> Bits; -typedef LLUnit<LLUnits::Kilobits, F64> Kilobits; -typedef LLUnit<LLUnits::Megabits, F64> Megabits; -typedef LLUnit<LLUnits::Gigabits, F64> Gigabits; +typedef LLUnit<LLUnits::Kibibits, F64> Kibibits; +typedef LLUnit<LLUnits::Mibibits, F64> Mibibits; +typedef LLUnit<LLUnits::Gibibits, F64> Gibibits; typedef LLUnit<LLUnits::Seconds, F64> Seconds; typedef LLUnit<LLUnits::Milliseconds, F64> Milliseconds; @@ -265,6 +265,8 @@ public: size_t getIndex() const { return mAccumulatorIndex; } + virtual const char* getUnitLabel() { return ""; } + const std::string& getName() const { return mName; } protected: @@ -273,25 +275,23 @@ protected: const size_t mAccumulatorIndex; }; -template<typename T> class EventAccumulator { public: - typedef T value_t; + typedef F64 value_t; typedef F64 mean_t; - typedef EventAccumulator<T> self_t; EventAccumulator() : mSum(0), - mMin((std::numeric_limits<T>::max)()), - mMax((std::numeric_limits<T>::min)()), + mMin((std::numeric_limits<F64>::max)()), + mMax((std::numeric_limits<F64>::min)()), mMean(0), mVarianceSum(0), mNumSamples(0), mLastValue(0) {} - void record(T value) + void record(F64 value) { mNumSamples++; mSum += value; @@ -305,12 +305,12 @@ public: mMax = value; } F64 old_mean = mMean; - mMean += ((F64)value - old_mean) / (F64)mNumSamples; - mVarianceSum += ((F64)value - old_mean) * ((F64)value - mMean); + mMean += (value - old_mean) / (F64)mNumSamples; + mVarianceSum += (value - old_mean) * (value - mMean); mLastValue = value; } - void addSamples(const self_t& other, bool append) + void addSamples(const EventAccumulator& other, bool append) { if (other.mNumSamples) { @@ -354,12 +354,12 @@ public: } } - void reset(const self_t* other) + void reset(const EventAccumulator* other) { mNumSamples = 0; mSum = 0; - mMin = std::numeric_limits<T>::max(); - mMax = std::numeric_limits<T>::min(); + mMin = std::numeric_limits<F64>::max(); + mMax = std::numeric_limits<F64>::min(); mMean = 0; mVarianceSum = 0; mLastValue = other ? other->mLastValue : 0; @@ -367,16 +367,16 @@ public: void flush() {} - T getSum() const { return (T)mSum; } - T getMin() const { return (T)mMin; } - T getMax() const { return (T)mMax; } - T getLastValue() const { return (T)mLastValue; } + F64 getSum() const { return mSum; } + F64 getMin() const { return mMin; } + F64 getMax() const { return mMax; } + F64 getLastValue() const { return mLastValue; } F64 getMean() const { return mMean; } F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } U32 getSampleCount() const { return mNumSamples; } private: - T mSum, + F64 mSum, mMin, mMax, mLastValue; @@ -388,18 +388,16 @@ private: }; -template<typename T> class SampleAccumulator { public: - typedef T value_t; + typedef F64 value_t; typedef F64 mean_t; - typedef SampleAccumulator<T> self_t; SampleAccumulator() : mSum(0), - mMin((std::numeric_limits<T>::max)()), - mMax((std::numeric_limits<T>::min)()), + mMin((std::numeric_limits<F64>::max)()), + mMax((std::numeric_limits<F64>::min)()), mMean(0), mVarianceSum(0), mLastSampleTimeStamp(LLTimer::getTotalSeconds()), @@ -409,7 +407,7 @@ public: mHasValue(false) {} - void sample(T value) + void sample(F64 value) { LLUnitImplicit<LLUnits::Seconds, F64> time_stamp = LLTimer::getTotalSeconds(); LLUnitImplicit<LLUnits::Seconds, F64> delta_time = time_stamp - mLastSampleTimeStamp; @@ -418,15 +416,15 @@ public: if (mHasValue) { mTotalSamplingTime += delta_time; - mSum += (F64)mLastValue * delta_time; + mSum += mLastValue * delta_time; // NOTE: both conditions will hold first time through if (value < mMin) { mMin = value; } if (value > mMax) { mMax = value; } F64 old_mean = mMean; - mMean += (delta_time / mTotalSamplingTime) * ((F64)mLastValue - old_mean); - mVarianceSum += delta_time * ((F64)mLastValue - old_mean) * ((F64)mLastValue - mMean); + mMean += (delta_time / mTotalSamplingTime) * (mLastValue - old_mean); + mVarianceSum += delta_time * (mLastValue - old_mean) * (mLastValue - mMean); } mLastValue = value; @@ -434,7 +432,7 @@ public: mHasValue = true; } - void addSamples(const self_t& other, bool append) + void addSamples(const SampleAccumulator& other, bool append) { if (other.mTotalSamplingTime) { @@ -485,12 +483,12 @@ public: } } - void reset(const self_t* other) + void reset(const SampleAccumulator* other) { mNumSamples = 0; mSum = 0; - mMin = std::numeric_limits<T>::max(); - mMax = std::numeric_limits<T>::min(); + mMin = std::numeric_limits<F64>::max(); + mMax = std::numeric_limits<F64>::min(); mMean = other ? other->mLastValue : 0; mVarianceSum = 0; mLastSampleTimeStamp = LLTimer::getTotalSeconds(); @@ -504,22 +502,24 @@ public: LLUnitImplicit<LLUnits::Seconds, F64> time_stamp = LLTimer::getTotalSeconds(); LLUnitImplicit<LLUnits::Seconds, F64> delta_time = time_stamp - mLastSampleTimeStamp; - mSum += (F64)mLastValue * delta_time; - - mTotalSamplingTime += delta_time; + if (mHasValue) + { + mSum += mLastValue * delta_time; + mTotalSamplingTime += delta_time; + } mLastSampleTimeStamp = time_stamp; } - T getSum() const { return (T)mSum; } - T getMin() const { return (T)mMin; } - T getMax() const { return (T)mMax; } - T getLastValue() const { return (T)mLastValue; } + F64 getSum() const { return mSum; } + F64 getMin() const { return mMin; } + F64 getMax() const { return mMax; } + F64 getLastValue() const { return mLastValue; } F64 getMean() const { return mMean; } F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mTotalSamplingTime); } U32 getSampleCount() const { return mNumSamples; } private: - T mSum, + F64 mSum, mMin, mMax, mLastValue; @@ -535,12 +535,10 @@ private: U32 mNumSamples; }; -template<typename T> class CountAccumulator { public: - typedef CountAccumulator<T> self_t; - typedef T value_t; + typedef F64 value_t; typedef F64 mean_t; CountAccumulator() @@ -548,19 +546,19 @@ public: mNumSamples(0) {} - void add(T value) + void add(F64 value) { mNumSamples++; mSum += value; } - void addSamples(const CountAccumulator<T>& other, bool /*append*/) + void addSamples(const CountAccumulator& other, bool /*append*/) { mSum += other.mSum; mNumSamples += other.mNumSamples; } - void reset(const self_t* other) + void reset(const CountAccumulator* other) { mNumSamples = 0; mSum = 0; @@ -568,12 +566,12 @@ public: void flush() {} - T getSum() const { return (T)mSum; } + F64 getSum() const { return mSum; } U32 getSampleCount() const { return mNumSamples; } private: - T mSum; + F64 mSum; U32 mNumSamples; }; @@ -585,14 +583,14 @@ public: typedef LLUnit<LLUnits::Seconds, F64> mean_t; typedef TimeBlockAccumulator self_t; - // fake class that allows us to view call count aspect of timeblock accumulator - struct CallCountAspect + // fake classes that allows us to view different facets of underlying statistic + struct CallCountFacet { typedef U32 value_t; typedef F32 mean_t; }; - struct SelfTimeAspect + struct SelfTimeFacet { typedef LLUnit<LLUnits::Seconds, F64> value_t; typedef LLUnit<LLUnits::Seconds, F64> mean_t; @@ -618,7 +616,7 @@ public: }; template<> -class TraceType<TimeBlockAccumulator::CallCountAspect> +class TraceType<TimeBlockAccumulator::CallCountFacet> : public TraceType<TimeBlockAccumulator> { public: @@ -629,7 +627,7 @@ public: }; template<> -class TraceType<TimeBlockAccumulator::SelfTimeAspect> +class TraceType<TimeBlockAccumulator::SelfTimeFacet> : public TraceType<TimeBlockAccumulator> { public: @@ -657,15 +655,18 @@ public: template <typename T = F64> class EventStatHandle -: public TraceType<EventAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > +: public TraceType<EventAccumulator> { public: - typedef typename LLUnits::HighestPrecisionType<T>::type_t storage_t; - typedef TraceType<EventAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > trace_t; + typedef typename F64 storage_t; + typedef TraceType<EventAccumulator> trace_t; EventStatHandle(const char* name, const char* description = NULL) : trace_t(name, description) {} + + /*virtual*/ const char* getUnitLabel() { return LLGetUnitLabel<T>::getUnitLabel(); } + }; template<typename T, typename VALUE_T> @@ -677,15 +678,17 @@ void record(EventStatHandle<T>& measurement, VALUE_T value) template <typename T = F64> class SampleStatHandle -: public TraceType<SampleAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > +: public TraceType<SampleAccumulator> { public: - typedef typename LLUnits::HighestPrecisionType<T>::type_t storage_t; - typedef TraceType<SampleAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > trace_t; + typedef F64 storage_t; + typedef TraceType<SampleAccumulator> trace_t; SampleStatHandle(const char* name, const char* description = NULL) : trace_t(name, description) {} + + /*virtual*/ const char* getUnitLabel() { return LLGetUnitLabel<T>::getUnitLabel(); } }; template<typename T, typename VALUE_T> @@ -697,16 +700,17 @@ void sample(SampleStatHandle<T>& measurement, VALUE_T value) template <typename T = F64> class CountStatHandle -: public TraceType<CountAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > +: public TraceType<CountAccumulator> { public: - typedef typename LLUnits::HighestPrecisionType<T>::type_t storage_t; - typedef TraceType<CountAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> > trace_t; + typedef typename F64 storage_t; + typedef TraceType<CountAccumulator> trace_t; CountStatHandle(const char* name, const char* description = NULL) : trace_t(name) {} + /*virtual*/ const char* getUnitLabel() { return LLGetUnitLabel<T>::getUnitLabel(); } }; template<typename T, typename VALUE_T> @@ -721,35 +725,90 @@ struct MemStatAccumulator { typedef MemStatAccumulator self_t; + // fake classes that allows us to view different facets of underlying statistic + struct AllocationCountFacet + { + typedef U32 value_t; + typedef F32 mean_t; + }; + + struct DeallocationCountFacet + { + typedef U32 value_t; + typedef F32 mean_t; + }; + + struct ChildMemFacet + { + typedef LLUnit<LLUnits::Bytes, F64> value_t; + typedef LLUnit<LLUnits::Bytes, F64> mean_t; + }; + MemStatAccumulator() - : mSize(0), - mChildSize(0), - mAllocatedCount(0), + : mAllocatedCount(0), mDeallocatedCount(0) {} - void addSamples(const MemStatAccumulator& other, bool /*append*/) + void addSamples(const MemStatAccumulator& other, bool append) { - mSize += other.mSize; - mChildSize += other.mChildSize; + mSize.addSamples(other.mSize, append); + mChildSize.addSamples(other.mChildSize, append); mAllocatedCount += other.mAllocatedCount; mDeallocatedCount += other.mDeallocatedCount; } void reset(const MemStatAccumulator* other) { - mSize = 0; - mChildSize = 0; + mSize.reset(other ? &other->mSize : NULL); + mChildSize.reset(other ? &other->mChildSize : NULL); mAllocatedCount = 0; mDeallocatedCount = 0; } - void flush() {} + void flush() + { + mSize.flush(); + mChildSize.flush(); + } - size_t mSize, - mChildSize; - int mAllocatedCount, - mDeallocatedCount; + SampleAccumulator mSize, + mChildSize; + int mAllocatedCount, + mDeallocatedCount; +}; + + +template<> +class TraceType<MemStatAccumulator::AllocationCountFacet> +: public TraceType<MemStatAccumulator> +{ +public: + + TraceType(const char* name, const char* description = "") + : TraceType<MemStatAccumulator>(name, description) + {} +}; + +template<> +class TraceType<MemStatAccumulator::DeallocationCountFacet> +: public TraceType<MemStatAccumulator> +{ +public: + + TraceType(const char* name, const char* description = "") + : TraceType<MemStatAccumulator>(name, description) + {} +}; + +template<> +class TraceType<MemStatAccumulator::ChildMemFacet> + : public TraceType<MemStatAccumulator> +{ +public: + + TraceType(const char* name, const char* description = "") + : TraceType<MemStatAccumulator>(name, description) + {} }; class MemStatHandle : public TraceType<MemStatAccumulator> @@ -759,6 +818,23 @@ public: MemStatHandle(const char* name) : trace_t(name) {} + + /*virtual*/ const char* getUnitLabel() { return "B"; } + + TraceType<MemStatAccumulator::AllocationCountFacet>& allocationCount() + { + return static_cast<TraceType<MemStatAccumulator::AllocationCountFacet>&>(*(TraceType<MemStatAccumulator>*)this); + } + + TraceType<MemStatAccumulator::DeallocationCountFacet>& deallocationCount() + { + return static_cast<TraceType<MemStatAccumulator::DeallocationCountFacet>&>(*(TraceType<MemStatAccumulator>*)this); + } + + TraceType<MemStatAccumulator::ChildMemFacet>& childMem() + { + return static_cast<TraceType<MemStatAccumulator::ChildMemFacet>&>(*(TraceType<MemStatAccumulator>*)this); + } }; // measures effective memory footprint of specified type @@ -859,7 +935,7 @@ public: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize += size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); accumulator->mAllocatedCount++; } @@ -871,7 +947,7 @@ public: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } @@ -883,7 +959,7 @@ public: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize += size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); accumulator->mAllocatedCount++; } @@ -895,7 +971,7 @@ public: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } @@ -918,13 +994,13 @@ public: } - void memClaim(size_t size) + void memClaimAmount(size_t size) { MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); mMemFootprint += size; if (accumulator) { - accumulator->mSize += size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); } } @@ -943,14 +1019,13 @@ public: return value; } - void memDisclaim(size_t size) + void memDisclaimAmount(size_t size) { MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= size; + accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); } - mMemFootprint -= size; } private: @@ -965,7 +1040,7 @@ private: if (accumulator) { size_t footprint = MemFootprint<TRACKED>::measure(tracked); - accumulator->mSize += footprint; + accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)footprint); tracker.mMemFootprint += footprint; } } @@ -976,7 +1051,7 @@ private: if (accumulator) { size_t footprint = MemFootprint<TRACKED>::measure(tracked); - accumulator->mSize -= footprint; + accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)footprint); tracker.mMemFootprint -= footprint; } } @@ -990,7 +1065,7 @@ private: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mChildSize += MemFootprint<TRACKED>::measure(tracked); + accumulator->mChildSize.sample(accumulator->mChildSize.getLastValue() + (F64)MemFootprint<TRACKED>::measure(tracked)); } } @@ -999,7 +1074,7 @@ private: MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mChildSize -= MemFootprint<TRACKED>::measure(tracked); + accumulator->mChildSize.sample(accumulator->mChildSize.getLastValue() - (F64)MemFootprint<TRACKED>::measure(tracked)); } } }; |