diff options
author | Richard Linden <none@none> | 2012-10-03 19:32:59 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2012-10-03 19:32:59 -0700 |
commit | 8f5e83789254d19a1a31737b0d7515cd7e967b26 (patch) | |
tree | e010acddfb59491fe805371b91167e679b8fa598 /indra/llcommon | |
parent | 7196619b4a0823a332e10b7f98464a1649e0dfd2 (diff) |
SH-3405 WIP convert existing stats to lltrace system
SH-3403 FIX implement unit conversion
LLUnit implements unit tracking and conversion
added support for LLUnit to LLTrace
duplicated most llstats into LLTrace equivalents
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/CMakeLists.txt | 1 | ||||
-rw-r--r-- | indra/llcommon/lltrace.h | 62 | ||||
-rw-r--r-- | indra/llcommon/lltracerecording.h | 18 | ||||
-rw-r--r-- | indra/llcommon/llunit.h | 226 |
4 files changed, 291 insertions, 16 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 1ccee23e1e..471558ea01 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -247,6 +247,7 @@ set(llcommon_HEADER_FILES lltracerecording.h lltreeiterators.h lltypeinfolookup.h + llunit.h lluri.h lluuid.h lluuidhashmap.h diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 39de79e4c1..6a889f74df 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -35,6 +35,7 @@ #include "lltimer.h" #include "llrefcount.h" #include "lltracerecording.h" +#include "llunit.h" #include <list> @@ -42,11 +43,8 @@ #define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) #define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); - namespace LLTrace { - class Recording; - void init(); void cleanup(); @@ -325,10 +323,10 @@ namespace LLTrace U32 mNumSamples; }; - template <typename T> + template <typename T, typename IS_UNIT = void> class LL_COMMON_API Measurement : public TraceType<MeasurementAccumulator<T> >, - public LLInstanceTracker<Measurement<T>, std::string> + public LLInstanceTracker<Measurement<T, IS_UNIT>, std::string> { public: Measurement(const std::string& name) @@ -343,13 +341,37 @@ namespace LLTrace }; template <typename T> + class LL_COMMON_API Measurement <T, typename T::is_unit_t> + : public Measurement<typename T::value_t> + { + public: + typedef Measurement<typename T::value_t> base_measurement_t; + Measurement(const std::string& name) + : Measurement<typename T::value_t>(name) + {} + + template<typename UNIT_T> + void sample(UNIT_T value) + { + base_measurement_t::sample(value.get()); + } + + template<typename UNIT_T> + typename T::value_t get() + { + UNIT_T value(*this); + return value.get(); + } + }; + + template <typename T, typename IS_UNIT = void> class LL_COMMON_API Rate - : public TraceType<RateAccumulator<T> >, + : public TraceType<RateAccumulator<T> >, public LLInstanceTracker<Rate<T>, std::string> { public: Rate(const std::string& name) - : TraceType(name), + : TraceType(name), LLInstanceTracker(name) {} @@ -359,6 +381,30 @@ namespace LLTrace } }; + template <typename T> + class LL_COMMON_API Rate <T, typename T::is_unit_t> + : public Rate<typename T::value_t> + { + public: + Rate(const std::string& name) + : Rate<typename T::value_t>(name) + {} + + template<typename UNIT_T> + void add(UNIT_T value) + { + getPrimaryAccumulator().add(value.get()); + } + + template<typename UNIT_T> + typename T::value_t get() + { + UNIT_T value(*this); + return value.get(); + } + + }; + class LL_COMMON_API TimerAccumulator { public: @@ -482,6 +528,8 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; + class Recording; + class LL_COMMON_API ThreadRecorder { public: diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 0a54e4cedf..4d5793014f 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -35,8 +35,8 @@ namespace LLTrace { - template<typename T> class Rate; - template<typename T> class Measurement; + template<typename T, typename IS_UNIT> class Rate; + template<typename T, typename IS_UNIT> class Measurement; template<typename T> class AccumulatorBuffer; template<typename T> class RateAccumulator; template<typename T> class MeasurementAccumulator; @@ -63,14 +63,14 @@ namespace LLTrace bool isStarted() { return mIsStarted; } - F32 getSum(Rate<F32>& stat); - F32 getPerSec(Rate<F32>& stat); + F32 getSum(Rate<F32, void>& stat); + F32 getPerSec(Rate<F32, void>& stat); - F32 getSum(Measurement<F32>& stat); - F32 getMin(Measurement<F32>& stat); - F32 getMax(Measurement<F32>& stat); - F32 getMean(Measurement<F32>& stat); - F32 getStandardDeviation(Measurement<F32>& stat); + F32 getSum(Measurement<F32, void>& stat); + F32 getMin(Measurement<F32, void>& stat); + F32 getMax(Measurement<F32, void>& stat); + F32 getMean(Measurement<F32, void>& stat); + F32 getStandardDeviation(Measurement<F32, void>& stat); F64 getSampleTime() { return mElapsedSeconds; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h new file mode 100644 index 0000000000..9d78df7cae --- /dev/null +++ b/indra/llcommon/llunit.h @@ -0,0 +1,226 @@ +/** + * @file llunit.h + * @brief Unit conversion classes + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLUNIT_H +#define LL_LLUNIT_H + +#include "stdtypes.h" +#include "llpreprocessor.h" + +template<typename BASE_UNIT, typename DERIVED_UNIT = BASE_UNIT> +struct LLUnit : public BASE_UNIT +{ + typedef LLUnit<BASE_UNIT, DERIVED_UNIT> unit_t; + typedef typename BASE_UNIT::value_t value_t; + typedef void is_unit_t; + + LLUnit() + {} + + explicit LLUnit(value_t value) + : BASE_UNIT(convertToBase(value)) + {} + + operator value_t() { return get(); } + + value_t get() const + { + return convertToDerived(mValue); + } + + static value_t convertToBase(value_t derived_value) + { + return (value_t)((F32)derived_value * DERIVED_UNIT::conversionToBaseFactor()); + } + + static value_t convertToDerived(value_t base_value) + { + return (value_t)((F32)base_value / DERIVED_UNIT::conversionToBaseFactor()); + } + +}; + +template<typename T> +struct LLUnit<T, T> +{ + typedef LLUnit<T, T> unit_t; + typedef T value_t; + typedef void is_unit_t; + + LLUnit() + : mValue() + {} + + explicit LLUnit(T value) + : mValue(value) + {} + + unit_t& operator=(T value) + { + setBaseValue(value); + return *this; + } + + value_t get() { return mValue; } + + static value_t convertToBase(value_t derived_value) + { + return (value_t)1; + } + + static value_t convertToDerived(value_t base_value) + { + return (value_t)1; + } + + unit_t operator + (const unit_t other) const + { + return unit_t(mValue + other.mValue); + } + + void operator += (const unit_t other) + { + mValue += other.mValue; + } + + unit_t operator - (const unit_t other) const + { + return unit_t(mValue - other.mValue); + } + + void operator -= (const unit_t other) + { + mValue -= other.mValue; + } + + unit_t operator * (value_t multiplicand) const + { + return unit_t(mValue * multiplicand); + } + + void operator *= (value_t multiplicand) + { + mValue *= multiplicand; + } + + unit_t operator / (value_t divisor) const + { + return unit_t(mValue / divisor); + } + + void operator /= (value_t divisor) + { + mValue /= divisor; + } + +protected: + void setBaseValue(T value) + { + mValue = value; + } + + T mValue; +}; + +#define LL_DECLARE_BASE_UNIT(unit_name) \ + template<typename STORAGE_TYPE> \ + struct unit_name : public LLUnit<STORAGE_TYPE> \ + { \ + unit_name(STORAGE_TYPE value) \ + : LLUnit(value) \ + {} \ + \ + unit_name() \ + {} \ + \ + template <typename T> \ + unit_name(const LLUnit<unit_name, T>& other) \ + { \ + setBaseValue(other.unit_name::get()); \ + } \ + \ + using LLUnit<STORAGE_TYPE>::operator +; \ + using LLUnit<STORAGE_TYPE>::operator +=; \ + using LLUnit<STORAGE_TYPE>::operator -; \ + using LLUnit<STORAGE_TYPE>::operator -=; \ + using LLUnit<STORAGE_TYPE>::operator *; \ + using LLUnit<STORAGE_TYPE>::operator *=; \ + using LLUnit<STORAGE_TYPE>::operator /; \ + using LLUnit<STORAGE_TYPE>::operator /=; \ + }; + +#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ + template<typename STORAGE_TYPE> \ + struct derived_unit : public LLUnit<base_unit<STORAGE_TYPE>, derived_unit<STORAGE_TYPE> > \ + { \ + derived_unit(value_t value) \ + : LLUnit(value) \ + {} \ + \ + derived_unit() \ + {} \ + \ + template <typename T> \ + derived_unit(const LLUnit<base_unit<STORAGE_TYPE>, T>& other) \ + { \ + setBaseValue(other.base_unit<STORAGE_TYPE>::get()); \ + } \ + \ + static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ + \ + using LLUnit<STORAGE_TYPE>::operator +; \ + using LLUnit<STORAGE_TYPE>::operator +=; \ + using LLUnit<STORAGE_TYPE>::operator -; \ + using LLUnit<STORAGE_TYPE>::operator -=; \ + using LLUnit<STORAGE_TYPE>::operator *; \ + using LLUnit<STORAGE_TYPE>::operator *=; \ + using LLUnit<STORAGE_TYPE>::operator /; \ + using LLUnit<STORAGE_TYPE>::operator /=; \ + }; + +namespace LLUnits +{ + LL_DECLARE_BASE_UNIT(Bytes); + LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.f / 8.f)); + LL_DECLARE_DERIVED_UNIT(Bytes, Kilobit, (1024 / 8)); + LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); + LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); + + LL_DECLARE_BASE_UNIT(Seconds); + LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); + LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); + LL_DECLARE_DERIVED_UNIT(Seconds, Days, 60 * 60 * 24); + LL_DECLARE_DERIVED_UNIT(Seconds, Weeks, 60 * 60 * 24 * 7); + LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.f / 1000.f)); + LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.f / (1000000.f))); + LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.f / (1000000000.f))); + +} + +#endif // LL_LLUNIT_H |