From e6ca5471a2a816a24888ae1b38332531b22b7254 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 17 Oct 2012 00:06:22 -0700 Subject: SH-3275 Update viewer metrics system to be more flexible put template parameter back in LLUnit units added free function operators for mathematical manipulation of unit values converted texture memory tracking to units --- indra/llcommon/lltrace.h | 36 +++- indra/llcommon/lltracerecording.h | 2 +- indra/llcommon/llunit.h | 376 ++++++++++++++++++++++++++------------ 3 files changed, 288 insertions(+), 126 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 3e19c83bd7..1c6726605a 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -46,6 +46,30 @@ namespace LLTrace { class Recording; + typedef LLUnit::Bytes Bytes; + typedef LLUnit::Kilobytes Kilobytes; + typedef LLUnit::Megabytes Megabytes; + typedef LLUnit::Gigabytes Gigabytes; + typedef LLUnit::Bits Bits; + typedef LLUnit::Kilobits Kilobits; + typedef LLUnit::Megabits Megabits; + typedef LLUnit::Gigabits Gigabits; + + typedef LLUnit::Seconds Seconds; + typedef LLUnit::Milliseconds Milliseconds; + typedef LLUnit::Minutes Minutes; + typedef LLUnit::Hours Hours; + typedef LLUnit::Days Days; + typedef LLUnit::Weeks Weeks; + typedef LLUnit::Milliseconds Milliseconds; + typedef LLUnit::Microseconds Microseconds; + typedef LLUnit::Nanoseconds Nanoseconds; + + typedef LLUnit::Meters Meters; + typedef LLUnit::Kilometers Kilometers; + typedef LLUnit::Centimeters Centimeters; + typedef LLUnit::Millimeters Millimeters; + void init(); void cleanup(); @@ -353,15 +377,15 @@ namespace LLTrace template class LL_COMMON_API Measurement - : public Measurement + : public Measurement { public: typedef typename T::storage_t storage_t; typedef typename T::base_unit_t base_unit_t; - typedef Measurement base_measurement_t; + typedef Measurement base_measurement_t; Measurement(const char* name, const char* description = NULL) - : Measurement(name) + : Measurement(name, description) {} template @@ -393,15 +417,15 @@ namespace LLTrace template class LL_COMMON_API Count - : public Count + : public Count { public: typedef typename T::storage_t storage_t; typedef typename T::base_unit_t base_unit_t; - typedef Count base_count_t; + typedef Count base_count_t; Count(const char* name, const char* description = NULL) - : Count(name) + : Count(name) {} template diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index bd4b944e5a..5e7b0752c6 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -214,7 +214,7 @@ namespace LLTrace return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; } - Recording getCurRecordingPeriod() + Recording& getCurRecordingPeriod() { return mRecordingPeriods[mCurPeriod]; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index e8f6b2b2ba..d980989c91 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -34,60 +34,43 @@ template(*this); } - value_t value() const + storage_t value() const { return convertToDerived(mBaseValue); } template - value_t value() const + storage_t value() const { return CONVERTED_TYPE(*this).value(); } - static value_t convertToBase(value_t derived_value) - { - return (value_t)((F32)derived_value * unit_t::conversionToBaseFactor()); - } - - static value_t convertToDerived(value_t base_value) - { - return (value_t)((F32)base_value / unit_t::conversionToBaseFactor()); - } - - unit_t operator + (const unit_t other) const - { - return unit_t(mBaseValue + other.mBaseValue); - } - - unit_t operator - (const unit_t other) const - { - return unit_t(mBaseValue - other.mBaseValue); - } - - unit_t operator * (value_t multiplicand) const +protected: + static storage_t convertToBase(storage_t derived_value) { - return unit_t(mBaseValue * multiplicand); + return (storage_t)((F32)derived_value * unit_t::conversionToBaseFactor()); } - unit_t operator / (value_t divisor) const + static storage_t convertToDerived(storage_t base_value) { - return unit_t(mBaseValue / divisor); + return (storage_t)((F32)base_value / unit_t::conversionToBaseFactor()); } }; @@ -96,43 +79,40 @@ template struct LLUnitType { typedef T unit_t; - typedef typename STORAGE_TYPE value_t; + typedef STORAGE_TYPE storage_t; typedef void is_unit_t; + typedef T base_unit_t; LLUnitType() : mBaseValue() {} - explicit LLUnitType(value_t value) + explicit LLUnitType(storage_t value) : mBaseValue(value) {} - unit_t& operator=(value_t value) + unit_t& operator=(storage_t value) { setBaseValue(value); return *this; } + //implicit downcast operator unit_t& () { return static_cast(*this); } - value_t value() const { return mBaseValue; } + storage_t value() const { return mBaseValue; } - static value_t convertToBase(value_t derived_value) + static storage_t convertToBase(storage_t derived_value) { - return (value_t)derived_value; + return (storage_t)derived_value; } - static value_t convertToDerived(value_t base_value) + static storage_t convertToDerived(storage_t base_value) { - return (value_t)base_value; - } - - unit_t operator + (const unit_t other) const - { - return unit_t(mBaseValue + other.mBaseValue); + return (storage_t)base_value; } void operator += (const unit_t other) @@ -140,108 +120,266 @@ struct LLUnitType mBaseValue += other.mBaseValue; } - unit_t operator - (const unit_t other) const - { - return unit_t(mBaseValue - other.mBaseValue); - } - void operator -= (const unit_t other) { mBaseValue -= other.mBaseValue; } - unit_t operator * (value_t multiplicand) const - { - return unit_t(mBaseValue * multiplicand); - } - - void operator *= (value_t multiplicand) + void operator *= (storage_t multiplicand) { mBaseValue *= multiplicand; } - unit_t operator / (value_t divisor) const - { - return unit_t(mBaseValue / divisor); - } - - void operator /= (value_t divisor) + void operator /= (storage_t divisor) { mBaseValue /= divisor; } protected: - void setBaseValue(value_t value) + void setBaseValue(storage_t value) { mBaseValue = value; } - value_t mBaseValue; + storage_t mBaseValue; }; -#define LL_DECLARE_BASE_UNIT(unit_name) \ - struct unit_name : public LLUnitType \ - { \ - typedef unit_name base_unit_t; \ - typedef LLUnitType unit_t; \ - typedef F64 storage_t; \ - \ - unit_name(F64 value) \ - : LLUnitType(value) \ - {} \ - \ - unit_name() \ - {} \ - \ - template \ - unit_name(const LLUnitType& source) \ - { \ - setBaseValue((F64)source.unit_name::unit_t::value()); \ - } \ - \ - using LLUnitType::operator +; \ - using LLUnitType::operator +=; \ - using LLUnitType::operator -; \ - using LLUnitType::operator -=; \ - using LLUnitType::operator *; \ - using LLUnitType::operator *=; \ - using LLUnitType::operator /; \ - using LLUnitType::operator /=; \ +// +// operator + +// +template +DERIVED_UNIT operator + (typename LLUnitType::storage_t first, LLUnitType second) +{ + return DERIVED_UNIT(first + second.value()); +} + +template +DERIVED_UNIT operator + (LLUnitType first, typename LLUnitType::storage_t second) +{ + return DERIVED_UNIT(first.value() + second); +} + +template +DERIVED_UNIT operator + (LLUnitType first, LLUnitType second) +{ + return DERIVED_UNIT(first.value() + second.value()); +} + +// +// operator - +// +template +DERIVED_UNIT operator - (typename LLUnitType::storage_t first, LLUnitType second) +{ + return DERIVED_UNIT(first - second.value()); +} + +template +DERIVED_UNIT operator - (LLUnitType first, typename LLUnitType::storage_t second) +{ + return DERIVED_UNIT(first.value() - second); +} + +template +DERIVED_UNIT operator - (LLUnitType first, LLUnitType second) +{ + return DERIVED_UNIT(first.value() - second.value()); +} + +// +// operator * +// +template +DERIVED_UNIT operator * (typename LLUnitType::storage_t first, LLUnitType second) +{ + return DERIVED_UNIT(first * second.value()); +} + +template +DERIVED_UNIT operator * (LLUnitType first, typename LLUnitType::storage_t second) +{ + return DERIVED_UNIT(first.value() * second); +} + +// +// operator / +// +template +DERIVED_UNIT operator / (typename LLUnitType::storage_t first, LLUnitType second) +{ + return DERIVED_UNIT(first * second.value()); +} + +template +DERIVED_UNIT operator / (LLUnitType first, typename LLUnitType::storage_t second) +{ + return DERIVED_UNIT(first.value() * second); +} + +// +// operator < +// +template +bool operator < (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first < second.value(); +} + +template +bool operator < (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() < second; +} + +template +bool operator < (LLUnitType first, LLUnitType second) +{ + return first.value() < second.value(); +} + +// +// operator <= +// +template +bool operator <= (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first <= second.value(); +} + +template +bool operator <= (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() <= second; +} + +template +bool operator <= (LLUnitType first, LLUnitType second) +{ + return first.value() <= second.value(); +} + +// +// operator > +// +template +bool operator > (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first > second.value(); +} + +template +bool operator > (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() > second; +} + +template +bool operator > (LLUnitType first, LLUnitType second) +{ + return first.value() > second.value(); +} +// +// operator >= +// +template +bool operator >= (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first >= second.value(); +} + +template +bool operator >= (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() >= second; +} + +template +bool operator >= (LLUnitType first, LLUnitType second) +{ + return first.value() >= second.value(); +} + +// +// operator == +// +template +bool operator == (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first == second.value(); +} + +template +bool operator == (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() == second; +} + +template +bool operator == (LLUnitType first, LLUnitType second) +{ + return first.value() == second.value(); +} + +// +// operator != +// +template +bool operator != (typename LLUnitType::storage_t first, LLUnitType second) +{ + return first != second.value(); +} + +template +bool operator != (LLUnitType first, typename LLUnitType::storage_t second) +{ + return first.value() != second; +} + +template +bool operator != (LLUnitType first, LLUnitType second) +{ + return first.value() != second.value(); +} + +#define LL_DECLARE_BASE_UNIT(unit_name) \ + template \ + struct unit_name : public LLUnitType, unit_name > \ + { \ + typedef LLUnitType unit_t; \ + \ + unit_name(storage_t value = 0) \ + : LLUnitType(value) \ + {} \ + \ + template \ + unit_name(LLUnitType, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.unit_name::unit_t::value()); \ + } \ + \ }; -#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ - struct derived_unit : public LLUnitType \ - { \ - typedef base_unit base_unit_t; \ - typedef LLUnitType unit_t; \ - typedef F64 storage_t; \ - \ - derived_unit(value_t value) \ - : LLUnitType(value) \ - {} \ - \ - derived_unit() \ - {} \ - \ - template \ - derived_unit(const LLUnitType& source) \ - { \ - setBaseValue((F64)source.base_unit::unit_t::value()); \ - } \ - \ - static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ - \ - using LLUnitType::operator +; \ - using LLUnitType::operator +=; \ - using LLUnitType::operator -; \ - using LLUnitType::operator -=; \ - using LLUnitType::operator *; \ - using LLUnitType::operator *=; \ - using LLUnitType::operator /; \ - using LLUnitType::operator /=; \ +#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ + template \ + struct derived_unit : public LLUnitType, derived_unit > \ + { \ + typedef LLUnitType, derived_unit > unit_t; \ + \ + derived_unit(storage_t value = 0) \ + : LLUnitType(value) \ + {} \ + \ + template \ + derived_unit(LLUnitType, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.base_unit::unit_t::value()); \ + } \ + \ + static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ + \ }; -namespace LLUnits +namespace LLUnit { LL_DECLARE_BASE_UNIT(Bytes); LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); -- cgit v1.2.3