summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/lltrace.h44
-rw-r--r--indra/llcommon/lltracerecording.h95
-rw-r--r--indra/llcommon/llunit.h34
3 files changed, 125 insertions, 48 deletions
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h
index 1c6726605a..2a479b31d7 100644
--- a/indra/llcommon/lltrace.h
+++ b/indra/llcommon/lltrace.h
@@ -192,10 +192,12 @@ namespace LLTrace
template<typename ACCUMULATOR>
class LL_COMMON_API TraceType
+ : public LLInstanceTracker<TraceType<ACCUMULATOR>, std::string>
{
public:
TraceType(const char* name, const char* description = NULL)
- : mName(name),
+ : LLInstanceTracker(name),
+ mName(name),
mDescription(description ? description : "")
{
mAccumulatorIndex = AccumulatorBuffer<ACCUMULATOR>::getDefaultBuffer().reserveSlot();
@@ -355,18 +357,17 @@ namespace LLTrace
U32 mNumSamples;
};
+ typedef TraceType<MeasurementAccumulator<F64> > measurement_common_t;
+
template <typename T = F64, typename IS_UNIT = void>
class LL_COMMON_API Measurement
- : public TraceType<MeasurementAccumulator<T> >,
- public LLInstanceTracker<Measurement<T, IS_UNIT>, std::string>
+ : public TraceType<MeasurementAccumulator<T> >
{
public:
typedef T storage_t;
- typedef T base_unit_t;
Measurement(const char* name, const char* description = NULL)
- : TraceType(name),
- LLInstanceTracker(name)
+ : TraceType(name, description)
{}
void sample(T value)
@@ -376,37 +377,37 @@ namespace LLTrace
};
template <typename T>
- class LL_COMMON_API Measurement <T, typename T::is_unit_t>
- : public Measurement<typename T::storage_t>
+ class LL_COMMON_API Measurement <T, typename T::is_unit_tag_t>
+ : public TraceType<MeasurementAccumulator<typename T::storage_t> >
{
public:
typedef typename T::storage_t storage_t;
- typedef typename T::base_unit_t base_unit_t;
typedef Measurement<typename T::storage_t> base_measurement_t;
Measurement(const char* name, const char* description = NULL)
- : Measurement<typename T::storage_t>(name, description)
+ : TraceType(name, description)
{}
template<typename UNIT_T>
void sample(UNIT_T value)
{
- base_measurement_t::sample(((T)value).value());
+ T converted_value;
+ converted_value.assignFrom(value);
+ getPrimaryAccumulator().sample(converted_value.value());
}
};
+ typedef TraceType<CountAccumulator<F64> > count_common_t;
+
template <typename T = F64, typename IS_UNIT = void>
class LL_COMMON_API Count
- : public TraceType<CountAccumulator<T> >,
- public LLInstanceTracker<Count<T>, std::string>
+ : public TraceType<CountAccumulator<T> >
{
public:
typedef T storage_t;
- typedef T base_unit_t;
Count(const char* name, const char* description = NULL)
- : TraceType(name),
- LLInstanceTracker(name)
+ : TraceType(name)
{}
void add(T value)
@@ -416,22 +417,23 @@ namespace LLTrace
};
template <typename T>
- class LL_COMMON_API Count <T, typename T::is_unit_t>
- : public Count<typename T::storage_t>
+ class LL_COMMON_API Count <T, typename T::is_unit_tag_t>
+ : public TraceType<CountAccumulator<typename T::storage_t> >
{
public:
typedef typename T::storage_t storage_t;
- typedef typename T::base_unit_t base_unit_t;
typedef Count<typename T::storage_t> base_count_t;
Count(const char* name, const char* description = NULL)
- : Count<typename T::storage_t>(name)
+ : TraceType(name)
{}
template<typename UNIT_T>
void add(UNIT_T value)
{
- base_count_t::add(((T)value).value());
+ T converted_value;
+ converted_value.assignFrom(value);
+ getPrimaryAccumulator().add(converted_value.value());
}
};
diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h
index 5e7b0752c6..25f4f5c721 100644
--- a/indra/llcommon/lltracerecording.h
+++ b/indra/llcommon/lltracerecording.h
@@ -112,64 +112,121 @@ namespace LLTrace
void update();
// Count accessors
+ template <typename T>
+ T getSum(const TraceType<CountAccumulator<T> >& stat) const
+ {
+ return (T)stat.getAccumulator(mCounts).getSum();
+ }
+
template <typename T, typename IS_UNIT>
- typename Count<T, IS_UNIT>::base_unit_t getSum(const Count<T, IS_UNIT>& stat) const
+ T getSum(const Count<T, IS_UNIT>& stat) const
+ {
+ return (T)stat.getAccumulator(mCounts).getSum();
+ }
+
+ template <typename T>
+ T getPerSec(const TraceType<CountAccumulator<T> >& stat) const
{
- return (typename Count<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mCounts).getSum();
+ return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds;
}
template <typename T, typename IS_UNIT>
- typename Count<T, IS_UNIT>::base_unit_t getPerSec(const Count<T, IS_UNIT>& stat) const
+ T getPerSec(const Count<T, IS_UNIT>& stat) const
{
- return (typename Count<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds;
+ return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds;
}
// Measurement accessors
+ template <typename T>
+ T getSum(const TraceType<MeasurementAccumulator<T> >& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getSum();
+
+ }
+
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getSum(const Measurement<T, IS_UNIT>& stat) const
+ T getSum(const Measurement<T, IS_UNIT>& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getSum();
+ return (T)stat.getAccumulator(mMeasurements).getSum();
+
+ }
+ template <typename T>
+ T getPerSec(const TraceType<MeasurementAccumulator<T> >& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds;
}
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getPerSec(const Measurement<T, IS_UNIT>& stat) const
+ T getPerSec(const Measurement<T, IS_UNIT>& stat) const
{
return (typename Count<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds;
}
- template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getMin(const Measurement<T, IS_UNIT>& stat) const
+ template <typename T>
+ T getMin(const TraceType<MeasurementAccumulator<T> >& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getMin();
+ return (T)stat.getAccumulator(mMeasurements).getMin();
}
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getMax(const Measurement<T, IS_UNIT>& stat) const
+ T getMin(const Measurement<T, IS_UNIT>& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getMax();
+ return (T)stat.getAccumulator(mMeasurements).getMin();
+ }
+
+
+ template <typename T>
+ T getMax(const TraceType<MeasurementAccumulator<T> >& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getMax();
}
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getMean(Measurement<T, IS_UNIT>& stat) const
+ T getMax(const Measurement<T, IS_UNIT>& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getMax();
+ }
+
+ template <typename T>
+ T getMean(const TraceType<MeasurementAccumulator<T> >& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getMean();
+ return (T)stat.getAccumulator(mMeasurements).getMean();
}
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getStandardDeviation(const Measurement<T, IS_UNIT>& stat) const
+ T getMean(Measurement<T, IS_UNIT>& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getMean();
+ }
+
+ template <typename T>
+ T getStandardDeviation(const TraceType<MeasurementAccumulator<T> >& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getStandardDeviation();
+ return (T)stat.getAccumulator(mMeasurements).getStandardDeviation();
}
template <typename T, typename IS_UNIT>
- typename Measurement<T, IS_UNIT>::base_unit_t getLastValue(const Measurement<T, IS_UNIT>& stat) const
+ T getStandardDeviation(const Measurement<T, IS_UNIT>& stat) const
{
- return (typename Measurement<T, IS_UNIT>::base_unit_t)stat.getAccumulator(mMeasurements).getLastValue();
+ return (T)stat.getAccumulator(mMeasurements).getStandardDeviation();
+ }
+
+ template <typename T>
+ T getLastValue(const TraceType<MeasurementAccumulator<T> >& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getLastValue();
}
template <typename T, typename IS_UNIT>
- U32 getSampleCount(const Measurement<T, IS_UNIT>& stat) const
+ T getLastValue(const Measurement<T, IS_UNIT>& stat) const
+ {
+ return (T)stat.getAccumulator(mMeasurements).getLastValue();
+ }
+
+
+ template <typename T>
+ U32 getSampleCount(const TraceType<MeasurementAccumulator<T> >& stat) const
{
return stat.getAccumulator(mMeasurements).getSampleCount();
}
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index d980989c91..e778383959 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -36,7 +36,7 @@ struct LLUnitType : public BASE_UNIT
typedef DERIVED_UNIT unit_t;
typedef typename STORAGE_TYPE storage_t;
- typedef void is_unit_t;
+ typedef void is_unit_tag_t;
LLUnitType()
{}
@@ -57,7 +57,7 @@ struct LLUnitType : public BASE_UNIT
}
template<typename CONVERTED_TYPE>
- storage_t value() const
+ storage_t as() const
{
return CONVERTED_TYPE(*this).value();
}
@@ -80,8 +80,7 @@ struct LLUnitType<STORAGE_TYPE, T, T>
{
typedef T unit_t;
typedef STORAGE_TYPE storage_t;
- typedef void is_unit_t;
- typedef T base_unit_t;
+ typedef void is_unit_tag_t;
LLUnitType()
: mBaseValue()
@@ -105,6 +104,13 @@ struct LLUnitType<STORAGE_TYPE, T, T>
storage_t value() const { return mBaseValue; }
+ template<typename CONVERTED_TYPE>
+ storage_t as() const
+ {
+ return CONVERTED_TYPE(*this).value();
+ }
+
+
static storage_t convertToBase(storage_t derived_value)
{
return (storage_t)derived_value;
@@ -354,10 +360,16 @@ bool operator != (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUni
template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \
unit_name(LLUnitType<SOURCE_STORAGE_TYPE, unit_name<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \
{ \
- setBaseValue((storage_t)source.unit_name<SOURCE_STORAGE_TYPE>::unit_t::value()); \
+ assignFrom(source); \
} \
\
- };
+ template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \
+ void assignFrom(LLUnitType<SOURCE_STORAGE_TYPE, unit_name<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \
+ { \
+ setBaseValue((storage_t)source.unit_name<SOURCE_STORAGE_TYPE>::unit_t::value()); \
+ } \
+ \
+ }; \
#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \
template<typename STORAGE> \
@@ -372,12 +384,18 @@ bool operator != (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUni
template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \
derived_unit(LLUnitType<SOURCE_STORAGE_TYPE, base_unit<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \
{ \
- setBaseValue((storage_t)source.base_unit<SOURCE_STORAGE_TYPE>::unit_t::value()); \
+ assignFrom(source); \
+ } \
+ \
+ template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \
+ void assignFrom(LLUnitType<SOURCE_STORAGE_TYPE, base_unit<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \
+ { \
+ setBaseValue((storage_t)source.base_unit<SOURCE_STORAGE_TYPE>::unit_t::value()); \
} \
\
static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \
\
- };
+ }; \
namespace LLUnit
{