From 3f2de87340b1c831ea59e4a3ca960d49f343c9fd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 17 Jun 2013 01:18:21 -0700 Subject: 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 --- indra/llcommon/llfasttimer.cpp | 6 +- indra/llcommon/lltrace.h | 16 ++- indra/llcommon/lltracerecording.cpp | 23 ++--- indra/llcommon/lltracerecording.h | 2 + indra/llcommon/llunit.h | 182 ++++++++++++++++------------------ indra/llcommon/tests/llunits_test.cpp | 8 +- 6 files changed, 122 insertions(+), 115 deletions(-) (limited to 'indra/llcommon') 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 total_time_ms = last_frame_recording.getSum(*timerp); + LLUnit 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(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().value() << " ms, " + << std::setprecision(3) << total_time.getAs() << " 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 Kilometers; typedef LLUnit Centimeters; typedef LLUnit Millimeters; + +template +T storage_value(T val) { return val; } + +template +STORAGE_TYPE storage_value(LLUnit val) { return val.value(); } + +template +STORAGE_TYPE storage_value(LLUnitImplicit val) { return val.value(); } + void init(); void cleanup(); bool isInitialized(); @@ -678,7 +688,7 @@ template void record(EventStatHandle& measurement, VALUE_T value) { T converted_value(value); - measurement.getPrimaryAccumulator()->record(LLUnits::storageValue(converted_value)); + measurement.getPrimaryAccumulator()->record(storage_value(converted_value)); } template @@ -700,7 +710,7 @@ template void sample(SampleStatHandle& measurement, VALUE_T value) { T converted_value(value); - measurement.getPrimaryAccumulator()->sample(LLUnits::storageValue(converted_value)); + measurement.getPrimaryAccumulator()->sample(storage_value(converted_value)); } template @@ -722,7 +732,7 @@ template void add(CountStatHandle& 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 @@ -121,22 +121,27 @@ 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(other); + mutable_other.update(); EPlayState other_play_state = other.getPlayState(); - mutable_other.pause(); - mBuffers = other.mBuffers; + mBuffers = mutable_other.mBuffers; LLStopWatchControlsMixin::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 -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 -struct Convert -{ - static VALUE_TYPE get(VALUE_TYPE val) - { - return val; - } -}; - -} +#include template struct LLUnit @@ -70,7 +46,7 @@ struct LLUnit // unit initialization and conversion template LLUnit(LLUnit other) - : mValue(convert(other)) + : mValue(convert(other).mValue) {} bool operator == (const self_t& other) @@ -89,7 +65,7 @@ struct LLUnit template self_t& operator = (LLUnit other) { - mValue = convert(other); + mValue = convert(other).mValue; return *this; } @@ -98,11 +74,17 @@ struct LLUnit return mValue; } - template LLUnit as() + template + STORAGE_TYPE getAs() { - return LLUnit(*this); + return LLUnit(*this).value(); } + template + STORAGE_TYPE setAs(STORAGE_TYPE val) + { + *this = LLUnit(val); + } void operator += (storage_t value) { @@ -112,7 +94,7 @@ struct LLUnit template void operator += (LLUnit other) { - mValue += convert(other); + mValue += convert(other).mValue; } void operator -= (storage_t value) @@ -123,7 +105,7 @@ struct LLUnit template void operator -= (LLUnit other) { - mValue -= convert(other); + mValue -= convert(other).mValue; } void operator *= (storage_t multiplicand) @@ -151,19 +133,13 @@ struct LLUnit } template - static storage_t convert(LLUnit v) + static self_t convert(LLUnit v) { - return (storage_t)LLUnits::Convert::get((STORAGE_TYPE) - LLUnits::Convert::get(v.value())); + self_t result; + ll_convert_units(v, result); + return result; } - template - static storage_t convert(LLUnit v) - { - return (storage_t)(v.value()); - } - - protected: storage_t mValue; }; @@ -192,6 +168,39 @@ struct LLUnitImplicit : public LLUnit } }; + +template +LL_FORCE_INLINE void ll_convert_units(LLUnit in, LLUnit& out, ...) +{ + static_assert(boost::is_same::value + || !boost::is_same::value + || !boost::is_same::value, + "invalid conversion"); + + if (boost::is_same::value) + { + if (boost::is_same::value) + { + // T1 and T2 fully reduced and equal...just copy + out = (S2)in.value(); + } + else + { + // reduce T2 + LLUnit new_out; + ll_convert_units(in, new_out); + ll_convert_units(new_out, out); + } + } + else + { + // reduce T1 + LLUnit new_in; + ll_convert_units(in, new_in); + ll_convert_units(new_in, out); + } +} + // // operator + // @@ -415,17 +424,11 @@ struct LLGetUnitLabel > static const char* getUnitLabel() { return T::getUnitLabel(); } }; -// -// Unit declarations -// -namespace LLUnits -{ - template -struct LinearOps +struct LLUnitLinearOps { - typedef LinearOps self_t; - LinearOps(VALUE_TYPE val) : mValue (val) {} + typedef LLUnitLinearOps self_t; + LLUnitLinearOps(VALUE_TYPE val) : mValue (val) {} operator VALUE_TYPE() const { return mValue; } VALUE_TYPE mValue; @@ -456,11 +459,11 @@ struct LinearOps }; template -struct InverseLinearOps +struct LLUnitInverseLinearOps { - typedef InverseLinearOps self_t; + typedef LLUnitInverseLinearOps 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 -T storageValue(T val) { return val; } - -template -STORAGE_TYPE storageValue(LLUnit val) { return val.value(); } - -template -STORAGE_TYPE storageValue(LLUnitImplicit 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; }} @@ -507,57 +500,58 @@ struct unit_name { \ typedef base_unit_name base_unit_t; \ static const char* getUnitLabel() { return unit_label; } \ -}; \ -template \ -struct Convert \ -{ \ - static STORAGE_TYPE get(STORAGE_TYPE val) \ - { \ - return (LinearOps(val) conversion_operation).mValue; \ - } \ }; \ \ -template \ -struct Convert \ +template \ +void ll_convert_units(LLUnit in, LLUnit& out) \ { \ - static STORAGE_TYPE get(STORAGE_TYPE val) \ - { \ - return (InverseLinearOps(val) conversion_operation).mValue; \ - } \ -} + out = (S2)(LLUnitLinearOps(in.value()) conversion_operation).mValue; \ +} \ + \ +template \ +void ll_convert_units(LLUnit in, LLUnit& out) \ +{ \ + out = (S2)(LLUnitInverseLinearOps(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 latinum_implicit(2); + ensure(latinum_implicit == 2); + + ensure(latinum_implicit * 2 == quatloos_implicit); } } -- cgit v1.2.3