summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-06-17 01:18:21 -0700
committerRichard Linden <none@none>2013-06-17 01:18:21 -0700
commit3f2de87340b1c831ea59e4a3ca960d49f343c9fd (patch)
tree1663517a0e50fbd9f736b29603bbd957d38967eb /indra/llcommon
parent9fd3af3c389ed491b515cbb5136b344b069913e4 (diff)
SH-3931 WIP Interesting: Add graphs to visualize scene load metrics
added getAs and setAs to LLUnit to make it clearer how you specify units removed accidental 0-based indexing of periodicRecording history... should now be consistently 1-based, with 0 accessing current active recording removed per frame timer updates of all historical timer bars in fast timer display added missing assignment operator to recordings
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-xindra/llcommon/llfasttimer.cpp6
-rw-r--r--indra/llcommon/lltrace.h16
-rw-r--r--indra/llcommon/lltracerecording.cpp23
-rw-r--r--indra/llcommon/lltracerecording.h2
-rw-r--r--indra/llcommon/llunit.h182
-rw-r--r--indra/llcommon/tests/llunits_test.cpp8
6 files changed, 122 insertions, 115 deletions
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index 809a0327ca..d9670891f8 100755
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -365,11 +365,11 @@ void TimeBlock::dumpCurTimes()
++it)
{
TimeBlock* timerp = (*it);
- LLUnit<F64, LLUnits::Seconds> total_time_ms = last_frame_recording.getSum(*timerp);
+ LLUnit<F64, LLUnits::Seconds> total_time = last_frame_recording.getSum(*timerp);
U32 num_calls = last_frame_recording.getSum(timerp->callCount());
// Don't bother with really brief times, keep output concise
- if (total_time_ms < 0.1) continue;
+ if (total_time < LLUnit<F32, LLUnits::Milliseconds>(0.1)) continue;
std::ostringstream out_str;
TimeBlock* parent_timerp = timerp;
@@ -380,7 +380,7 @@ void TimeBlock::dumpCurTimes()
}
out_str << timerp->getName() << " "
- << std::setprecision(3) << total_time_ms.as<LLUnits::Milliseconds>().value() << " ms, "
+ << std::setprecision(3) << total_time.getAs<LLUnits::Milliseconds>() << " ms, "
<< num_calls << " calls";
llinfos << out_str.str() << llendl;
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h
index 1bf853c5c0..cd377531e8 100644
--- a/indra/llcommon/lltrace.h
+++ b/indra/llcommon/lltrace.h
@@ -66,6 +66,16 @@ typedef LLUnit<F64, LLUnits::Kilometers> Kilometers;
typedef LLUnit<F64, LLUnits::Centimeters> Centimeters;
typedef LLUnit<F64, LLUnits::Millimeters> Millimeters;
+
+template<typename T>
+T storage_value(T val) { return val; }
+
+template<typename UNIT_TYPE, typename STORAGE_TYPE>
+STORAGE_TYPE storage_value(LLUnit<STORAGE_TYPE, UNIT_TYPE> val) { return val.value(); }
+
+template<typename UNIT_TYPE, typename STORAGE_TYPE>
+STORAGE_TYPE storage_value(LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE> val) { return val.value(); }
+
void init();
void cleanup();
bool isInitialized();
@@ -678,7 +688,7 @@ template<typename T, typename VALUE_T>
void record(EventStatHandle<T>& measurement, VALUE_T value)
{
T converted_value(value);
- measurement.getPrimaryAccumulator()->record(LLUnits::storageValue(converted_value));
+ measurement.getPrimaryAccumulator()->record(storage_value(converted_value));
}
template <typename T = F64>
@@ -700,7 +710,7 @@ template<typename T, typename VALUE_T>
void sample(SampleStatHandle<T>& measurement, VALUE_T value)
{
T converted_value(value);
- measurement.getPrimaryAccumulator()->sample(LLUnits::storageValue(converted_value));
+ measurement.getPrimaryAccumulator()->sample(storage_value(converted_value));
}
template <typename T = F64>
@@ -722,7 +732,7 @@ template<typename T, typename VALUE_T>
void add(CountStatHandle<T>& count, VALUE_T value)
{
T converted_value(value);
- count.getPrimaryAccumulator()->add(LLUnits::storageValue(converted_value));
+ count.getPrimaryAccumulator()->add(storage_value(converted_value));
}
diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp
index ff90da3822..f2c5941011 100644
--- a/indra/llcommon/lltracerecording.cpp
+++ b/indra/llcommon/lltracerecording.cpp
@@ -122,21 +122,26 @@ Recording::Recording()
Recording::Recording( const Recording& other )
{
+ *this = other;
+}
+
+Recording& Recording::operator = (const Recording& other)
+{
// this will allow us to seamlessly start without affecting any data we've acquired from other
setPlayState(PAUSED);
Recording& mutable_other = const_cast<Recording&>(other);
+ mutable_other.update();
EPlayState other_play_state = other.getPlayState();
- mutable_other.pause();
- mBuffers = other.mBuffers;
+ mBuffers = mutable_other.mBuffers;
LLStopWatchControlsMixin<Recording>::setPlayState(other_play_state);
- mutable_other.setPlayState(other_play_state);
// above call will clear mElapsedSeconds as a side effect, so copy it here
mElapsedSeconds = other.mElapsedSeconds;
mSamplingTimer = other.mSamplingTimer;
+ return *this;
}
@@ -444,12 +449,8 @@ void PeriodicRecording::nextPeriod()
void PeriodicRecording::appendRecording(Recording& recording)
{
- // if I have a recording of any length, then close it off and start a fresh one
- if (getCurRecording().getDuration().value())
- {
- nextPeriod();
- }
getCurRecording().appendRecording(recording);
+ nextPeriod();
}
@@ -460,12 +461,6 @@ void PeriodicRecording::appendPeriodicRecording( PeriodicRecording& other )
getCurRecording().update();
other.getCurRecording().update();
- // if I have a recording of any length, then close it off and start a fresh one
- if (getCurRecording().getDuration().value())
- {
- nextPeriod();
- }
-
if (mAutoResize)
{
S32 other_index = (other.mCurPeriod + 1) % other.mRecordingPeriods.size();
diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h
index e3cef77b06..b839e85de0 100644
--- a/indra/llcommon/lltracerecording.h
+++ b/indra/llcommon/lltracerecording.h
@@ -135,6 +135,8 @@ namespace LLTrace
Recording(const Recording& other);
~Recording();
+ Recording& operator = (const Recording& other);
+
// accumulate data from subsequent, non-overlapping recording
void appendRecording(const Recording& other);
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index 5b961c81f0..5229fe69d7 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -30,31 +30,7 @@
#include "stdtypes.h"
#include "llpreprocessor.h"
#include "llerrorlegacy.h"
-
-namespace LLUnits
-{
-
-template<typename DERIVED_UNITS_TAG, typename BASE_UNITS_TAG, typename VALUE_TYPE>
-struct Convert
-{
- static VALUE_TYPE get(VALUE_TYPE val)
- {
- // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template
- llstatic_assert_template(DERIVED_UNITS_TAG, false, "Cannot convert between types.");
- return val;
- }
-};
-
-template<typename BASE_UNITS_TAG, typename VALUE_TYPE>
-struct Convert<BASE_UNITS_TAG, BASE_UNITS_TAG, VALUE_TYPE>
-{
- static VALUE_TYPE get(VALUE_TYPE val)
- {
- return val;
- }
-};
-
-}
+#include <boost/type_traits/is_same.hpp>
template<typename STORAGE_TYPE, typename UNIT_TYPE>
struct LLUnit
@@ -70,7 +46,7 @@ struct LLUnit
// unit initialization and conversion
template<typename OTHER_STORAGE, typename OTHER_UNIT>
LLUnit(LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
- : mValue(convert(other))
+ : mValue(convert(other).mValue)
{}
bool operator == (const self_t& other)
@@ -89,7 +65,7 @@ struct LLUnit
template<typename OTHER_STORAGE, typename OTHER_UNIT>
self_t& operator = (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
{
- mValue = convert(other);
+ mValue = convert(other).mValue;
return *this;
}
@@ -98,11 +74,17 @@ struct LLUnit
return mValue;
}
- template<typename NEW_UNIT_TYPE> LLUnit<STORAGE_TYPE, NEW_UNIT_TYPE> as()
+ template<typename NEW_UNIT_TYPE>
+ STORAGE_TYPE getAs()
{
- return LLUnit<STORAGE_TYPE, NEW_UNIT_TYPE>(*this);
+ return LLUnit<STORAGE_TYPE, NEW_UNIT_TYPE>(*this).value();
}
+ template<typename NEW_UNIT_TYPE>
+ STORAGE_TYPE setAs(STORAGE_TYPE val)
+ {
+ *this = LLUnit<STORAGE_TYPE, NEW_UNIT_TYPE>(val);
+ }
void operator += (storage_t value)
{
@@ -112,7 +94,7 @@ struct LLUnit
template<typename OTHER_STORAGE, typename OTHER_UNIT>
void operator += (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
{
- mValue += convert(other);
+ mValue += convert(other).mValue;
}
void operator -= (storage_t value)
@@ -123,7 +105,7 @@ struct LLUnit
template<typename OTHER_STORAGE, typename OTHER_UNIT>
void operator -= (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
{
- mValue -= convert(other);
+ mValue -= convert(other).mValue;
}
void operator *= (storage_t multiplicand)
@@ -151,19 +133,13 @@ struct LLUnit
}
template<typename SOURCE_STORAGE, typename SOURCE_UNITS>
- static storage_t convert(LLUnit<SOURCE_STORAGE, SOURCE_UNITS> v)
+ static self_t convert(LLUnit<SOURCE_STORAGE, SOURCE_UNITS> v)
{
- return (storage_t)LLUnits::Convert<typename UNIT_TYPE::base_unit_t, UNIT_TYPE, STORAGE_TYPE>::get((STORAGE_TYPE)
- LLUnits::Convert<SOURCE_UNITS, typename UNIT_TYPE::base_unit_t, SOURCE_STORAGE>::get(v.value()));
+ self_t result;
+ ll_convert_units(v, result);
+ return result;
}
- template<typename SOURCE_STORAGE>
- static storage_t convert(LLUnit<SOURCE_STORAGE, UNIT_TYPE> v)
- {
- return (storage_t)(v.value());
- }
-
-
protected:
storage_t mValue;
};
@@ -192,6 +168,39 @@ struct LLUnitImplicit : public LLUnit<STORAGE_TYPE, UNIT_TYPE>
}
};
+
+template<typename S1, typename T1, typename S2, typename T2>
+LL_FORCE_INLINE void ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out, ...)
+{
+ static_assert(boost::is_same<T1, T2>::value
+ || !boost::is_same<T1, typename T1::base_unit_t>::value
+ || !boost::is_same<T2, typename T2::base_unit_t>::value,
+ "invalid conversion");
+
+ if (boost::is_same<T1, typename T1::base_unit_t>::value)
+ {
+ if (boost::is_same<T2, typename T2::base_unit_t>::value)
+ {
+ // T1 and T2 fully reduced and equal...just copy
+ out = (S2)in.value();
+ }
+ else
+ {
+ // reduce T2
+ LLUnit<S2, typename T2::base_unit_t> new_out;
+ ll_convert_units(in, new_out);
+ ll_convert_units(new_out, out);
+ }
+ }
+ else
+ {
+ // reduce T1
+ LLUnit<S1, typename T1::base_unit_t> new_in;
+ ll_convert_units(in, new_in);
+ ll_convert_units(new_in, out);
+ }
+}
+
//
// operator +
//
@@ -415,17 +424,11 @@ struct LLGetUnitLabel<LLUnit<STORAGE_T, T> >
static const char* getUnitLabel() { return T::getUnitLabel(); }
};
-//
-// Unit declarations
-//
-namespace LLUnits
-{
-
template<typename VALUE_TYPE>
-struct LinearOps
+struct LLUnitLinearOps
{
- typedef LinearOps<VALUE_TYPE> self_t;
- LinearOps(VALUE_TYPE val) : mValue (val) {}
+ typedef LLUnitLinearOps<VALUE_TYPE> self_t;
+ LLUnitLinearOps(VALUE_TYPE val) : mValue (val) {}
operator VALUE_TYPE() const { return mValue; }
VALUE_TYPE mValue;
@@ -456,11 +459,11 @@ struct LinearOps
};
template<typename VALUE_TYPE>
-struct InverseLinearOps
+struct LLUnitInverseLinearOps
{
- typedef InverseLinearOps<VALUE_TYPE> self_t;
+ typedef LLUnitInverseLinearOps<VALUE_TYPE> self_t;
- InverseLinearOps(VALUE_TYPE val) : mValue (val) {}
+ LLUnitInverseLinearOps(VALUE_TYPE val) : mValue (val) {}
operator VALUE_TYPE() const { return mValue; }
VALUE_TYPE mValue;
@@ -489,16 +492,6 @@ struct InverseLinearOps
}
};
-
-template<typename T>
-T storageValue(T val) { return val; }
-
-template<typename UNIT_TYPE, typename STORAGE_TYPE>
-STORAGE_TYPE storageValue(LLUnit<STORAGE_TYPE, UNIT_TYPE> val) { return val.value(); }
-
-template<typename UNIT_TYPE, typename STORAGE_TYPE>
-STORAGE_TYPE storageValue(LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE> val) { return val.value(); }
-
#define LL_DECLARE_BASE_UNIT(base_unit_name, unit_label) \
struct base_unit_name { typedef base_unit_name base_unit_t; static const char* getUnitLabel() { return unit_label; }}
@@ -508,56 +501,57 @@ struct unit_name
typedef base_unit_name base_unit_t; \
static const char* getUnitLabel() { return unit_label; } \
}; \
-template<typename STORAGE_TYPE> \
-struct Convert<unit_name, base_unit_name, STORAGE_TYPE> \
-{ \
- static STORAGE_TYPE get(STORAGE_TYPE val) \
- { \
- return (LinearOps<STORAGE_TYPE>(val) conversion_operation).mValue; \
- } \
-}; \
\
-template<typename STORAGE_TYPE> \
-struct Convert<base_unit_name, unit_name, STORAGE_TYPE> \
+template<typename S1, typename S2> \
+void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \
{ \
- static STORAGE_TYPE get(STORAGE_TYPE val) \
- { \
- return (InverseLinearOps<STORAGE_TYPE>(val) conversion_operation).mValue; \
- } \
-}
+ out = (S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation).mValue; \
+} \
+ \
+template<typename S1, typename S2> \
+void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \
+{ \
+ out = (S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation).mValue; \
+}
+//
+// Unit declarations
+//
+
+namespace LLUnits
+{
LL_DECLARE_BASE_UNIT(Bytes, "B");
LL_DECLARE_DERIVED_UNIT(Kilobytes, "KB", Bytes, * 1000);
-LL_DECLARE_DERIVED_UNIT(Megabytes, "MB", Bytes, * 1000 * 1000);
-LL_DECLARE_DERIVED_UNIT(Gigabytes, "GB", Bytes, * 1000 * 1000 * 1000);
+LL_DECLARE_DERIVED_UNIT(Megabytes, "MB", Kilobytes, * 1000);
+LL_DECLARE_DERIVED_UNIT(Gigabytes, "GB", Megabytes, * 1000);
LL_DECLARE_DERIVED_UNIT(Kibibytes, "KiB", Bytes, * 1024);
-LL_DECLARE_DERIVED_UNIT(Mibibytes, "MiB", Bytes, * 1024 * 1024);
-LL_DECLARE_DERIVED_UNIT(Gibibytes, "GiB", Bytes, * 1024 * 1024 * 1024);
+LL_DECLARE_DERIVED_UNIT(Mibibytes, "MiB", Kibibytes, * 1024);
+LL_DECLARE_DERIVED_UNIT(Gibibytes, "GiB", Mibibytes, * 1024);
LL_DECLARE_DERIVED_UNIT(Bits, "b", Bytes, / 8);
-LL_DECLARE_DERIVED_UNIT(Kilobits, "Kb", Bytes, * (1000 / 8));
-LL_DECLARE_DERIVED_UNIT(Megabits, "Mb", Bytes, * (1000 / 8));
-LL_DECLARE_DERIVED_UNIT(Gigabits, "Gb", Bytes, * (1000 * 1000 * 1000 / 8));
-LL_DECLARE_DERIVED_UNIT(Kibibits, "Kib", Bytes, * (1024 / 8));
-LL_DECLARE_DERIVED_UNIT(Mibibits, "Mib", Bytes, * (1024 / 8));
-LL_DECLARE_DERIVED_UNIT(Gibibits, "Gib", Bytes, * (1024 * 1024 * 1024 / 8));
+LL_DECLARE_DERIVED_UNIT(Kilobits, "Kb", Bytes, * 1000 / 8);
+LL_DECLARE_DERIVED_UNIT(Megabits, "Mb", Kilobits, * 1000 / 8);
+LL_DECLARE_DERIVED_UNIT(Gigabits, "Gb", Megabits, * 1000 / 8);
+LL_DECLARE_DERIVED_UNIT(Kibibits, "Kib", Bytes, * 1024 / 8);
+LL_DECLARE_DERIVED_UNIT(Mibibits, "Mib", Kibibits, * 1024 / 8);
+LL_DECLARE_DERIVED_UNIT(Gibibits, "Gib", Mibibits, * 1024 / 8);
LL_DECLARE_BASE_UNIT(Seconds, "s");
LL_DECLARE_DERIVED_UNIT(Minutes, "min", Seconds, * 60);
LL_DECLARE_DERIVED_UNIT(Hours, "h", Seconds, * 60 * 60);
LL_DECLARE_DERIVED_UNIT(Milliseconds, "ms", Seconds, / 1000);
-LL_DECLARE_DERIVED_UNIT(Microseconds, "\x09\x3cs", Seconds, / 1000000);
-LL_DECLARE_DERIVED_UNIT(Nanoseconds, "ns", Seconds, / 1000000000);
+LL_DECLARE_DERIVED_UNIT(Microseconds, "\x09\x3cs", Milliseconds, / 1000);
+LL_DECLARE_DERIVED_UNIT(Nanoseconds, "ns", Microseconds, / 1000);
LL_DECLARE_BASE_UNIT(Meters, "m");
LL_DECLARE_DERIVED_UNIT(Kilometers, "km", Meters, * 1000);
-LL_DECLARE_DERIVED_UNIT(Centimeters, "cm", Meters, * 100);
-LL_DECLARE_DERIVED_UNIT(Millimeters, "mm", Meters, * 1000);
+LL_DECLARE_DERIVED_UNIT(Centimeters, "cm", Meters, / 100);
+LL_DECLARE_DERIVED_UNIT(Millimeters, "mm", Meters, / 1000);
LL_DECLARE_BASE_UNIT(Hertz, "Hz");
LL_DECLARE_DERIVED_UNIT(Kilohertz, "KHz", Hertz, * 1000);
-LL_DECLARE_DERIVED_UNIT(Megahertz, "MHz", Hertz, * 1000 * 1000);
-LL_DECLARE_DERIVED_UNIT(Gigahertz, "GHz", Hertz, * 1000 * 1000 * 1000);
+LL_DECLARE_DERIVED_UNIT(Megahertz, "MHz", Kilohertz, * 1000);
+LL_DECLARE_DERIVED_UNIT(Gigahertz, "GHz", Megahertz, * 1000);
LL_DECLARE_BASE_UNIT(Radians, "rad");
LL_DECLARE_DERIVED_UNIT(Degrees, "deg", Radians, * 0.01745329251994);
diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp
index 747e8d1827..04764f6c2f 100644
--- a/indra/llcommon/tests/llunits_test.cpp
+++ b/indra/llcommon/tests/llunits_test.cpp
@@ -35,7 +35,7 @@ namespace LLUnits
// using powers of 2 to allow strict floating point equality
LL_DECLARE_BASE_UNIT(Quatloos, "Quat");
LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, * 4);
- LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Quatloos, / 4);
+ LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, / 16);
}
namespace tut
@@ -206,5 +206,11 @@ namespace tut
S32 int_val = quatloos_implicit;
ensure(int_val == 16);
+
+ // conversion of implicits
+ LLUnitImplicit<F32, Latinum> latinum_implicit(2);
+ ensure(latinum_implicit == 2);
+
+ ensure(latinum_implicit * 2 == quatloos_implicit);
}
}