diff options
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-x | indra/llcommon/llevent.h | 1 | ||||
-rwxr-xr-x | indra/llcommon/llpointer.h | 78 | ||||
-rwxr-xr-x | indra/llcommon/llrefcount.h | 85 | ||||
-rwxr-xr-x | indra/llcommon/llthread.h | 2 | ||||
-rw-r--r-- | indra/llcommon/lltraceaccumulators.h | 40 | ||||
-rw-r--r-- | indra/llcommon/lltracerecording.h | 15 | ||||
-rw-r--r-- | indra/llcommon/llunit.h | 100 |
7 files changed, 169 insertions, 152 deletions
diff --git a/indra/llcommon/llevent.h b/indra/llcommon/llevent.h index 9d3a7a654a..28ce7de102 100755 --- a/indra/llcommon/llevent.h +++ b/indra/llcommon/llevent.h @@ -29,6 +29,7 @@ #define LL_EVENT_H #include "llsd.h" +#include "llrefcount.h" #include "llpointer.h" namespace LLOldEvents diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h index 9a0726c338..e09741b0ec 100755 --- a/indra/llcommon/llpointer.h +++ b/indra/llcommon/llpointer.h @@ -214,82 +214,4 @@ private: bool mStayUnique; }; -//============================================================================ - -// see llmemory.h for LLPointer<> definition - -class LL_COMMON_API LLThreadSafeRefCount -{ -public: - static void initThreadSafeRefCount(); // creates sMutex - static void cleanupThreadSafeRefCount(); // destroys sMutex - -private: - static LLMutex* sMutex; - -protected: - virtual ~LLThreadSafeRefCount(); // use unref() - -public: - LLThreadSafeRefCount(); - LLThreadSafeRefCount(const LLThreadSafeRefCount&); - LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref) - { - if (sMutex) - { - sMutex->lock(); - } - mRef = 0; - if (sMutex) - { - sMutex->unlock(); - } - return *this; - } - - void ref() - { - if (sMutex) sMutex->lock(); - mRef++; - if (sMutex) sMutex->unlock(); - } - - S32 unref() - { - llassert(mRef >= 1); - if (sMutex) sMutex->lock(); - S32 res = --mRef; - if (sMutex) sMutex->unlock(); - if (0 == res) - { - delete this; - return 0; - } - return res; - } - S32 getNumRefs() const - { - return mRef; - } - -private: - S32 mRef; -}; - -/** - * intrusive pointer support for LLThreadSafeRefCount - * this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type - */ -namespace boost -{ - inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p) - { - p->ref(); - } - - inline void intrusive_ptr_release(LLThreadSafeRefCount* p) - { - p->unref(); - } -}; #endif diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h index 32ae15435a..3e472d0766 100755 --- a/indra/llcommon/llrefcount.h +++ b/indra/llcommon/llrefcount.h @@ -28,6 +28,7 @@ #include <boost/noncopyable.hpp> #include <boost/intrusive_ptr.hpp> +#include "llmutex.h" #define LL_REF_COUNT_DEBUG 0 #if LL_REF_COUNT_DEBUG @@ -87,22 +88,100 @@ private: #endif }; + +//============================================================================ + +// see llmemory.h for LLPointer<> definition + +class LL_COMMON_API LLThreadSafeRefCount +{ +public: + static void initThreadSafeRefCount(); // creates sMutex + static void cleanupThreadSafeRefCount(); // destroys sMutex + +private: + static LLMutex* sMutex; + +protected: + virtual ~LLThreadSafeRefCount(); // use unref() + +public: + LLThreadSafeRefCount(); + LLThreadSafeRefCount(const LLThreadSafeRefCount&); + LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref) + { + if (sMutex) + { + sMutex->lock(); + } + mRef = 0; + if (sMutex) + { + sMutex->unlock(); + } + return *this; + } + + void ref() + { + if (sMutex) sMutex->lock(); + mRef++; + if (sMutex) sMutex->unlock(); + } + + S32 unref() + { + llassert(mRef >= 1); + if (sMutex) sMutex->lock(); + S32 res = --mRef; + if (sMutex) sMutex->unlock(); + if (0 == res) + { + delete this; + return 0; + } + return res; + } + S32 getNumRefs() const + { + return mRef; + } + +private: + S32 mRef; +}; + /** * intrusive pointer support * this allows you to use boost::intrusive_ptr with any LLRefCount-derived type */ +/** + * intrusive pointer support for LLThreadSafeRefCount + * this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type + */ namespace boost { - inline void intrusive_ptr_add_ref(LLRefCount* p) + inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p) { p->ref(); } - inline void intrusive_ptr_release(LLRefCount* p) + inline void intrusive_ptr_release(LLThreadSafeRefCount* p) { - p->unref(); + p->unref(); + } + + inline void intrusive_ptr_add_ref(LLRefCount* p) + { + p->ref(); + } + + inline void intrusive_ptr_release(LLRefCount* p) + { + p->unref(); } }; + #endif diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index c2c6b8e7ac..d7abdc4970 100755 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -32,7 +32,7 @@ #include "apr_thread_cond.h" #include "boost/intrusive_ptr.hpp" #include "llmutex.h" -#include "llpointer.h" +#include "llrefcount.h" LL_COMMON_API void assert_main_thread(); diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h index efc8b43f6a..b1aa078f9a 100644 --- a/indra/llcommon/lltraceaccumulators.h +++ b/indra/llcommon/lltraceaccumulators.h @@ -223,7 +223,7 @@ namespace LLTrace mMin((std::numeric_limits<F64>::max)()), mMax((std::numeric_limits<F64>::min)()), mMean(0), - mVarianceSum(0), + mSumOfSquares(0), mNumSamples(0), mLastValue(0) {} @@ -243,7 +243,7 @@ namespace LLTrace } F64 old_mean = mMean; mMean += (value - old_mean) / (F64)mNumSamples; - mVarianceSum += (value - old_mean) * (value - mMean); + mSumOfSquares += (value - old_mean) * (value - mMean); mLastValue = value; } @@ -263,20 +263,20 @@ namespace LLTrace n_2 = (F64)other.mNumSamples; F64 m_1 = mMean, m_2 = other.mMean; - F64 v_1 = mVarianceSum / mNumSamples, - v_2 = other.mVarianceSum / other.mNumSamples; + F64 v_1 = mSumOfSquares / mNumSamples, + v_2 = other.mSumOfSquares / other.mNumSamples; if (n_1 == 0) { - mVarianceSum = other.mVarianceSum; + mSumOfSquares = other.mSumOfSquares; } else if (n_2 == 0) { // don't touch variance - // mVarianceSum = mVarianceSum; + // mSumOfSquares = mSumOfSquares; } else { - mVarianceSum = (F64)mNumSamples + mSumOfSquares = (F64)mNumSamples * ((((n_1 - 1.f) * v_1) + ((n_2 - 1.f) * v_2) + (((n_1 * n_2) / (n_1 + n_2)) @@ -298,7 +298,7 @@ namespace LLTrace mMin = std::numeric_limits<F64>::max(); mMax = std::numeric_limits<F64>::min(); mMean = 0; - mVarianceSum = 0; + mSumOfSquares = 0; mLastValue = other ? other->mLastValue : 0; } @@ -309,7 +309,7 @@ namespace LLTrace F64 getMax() const { return mMax; } F64 getLastValue() const { return mLastValue; } F64 getMean() const { return mMean; } - F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } + F64 getStandardDeviation() const { return sqrtf(mSumOfSquares / mNumSamples); } U32 getSampleCount() const { return mNumSamples; } private: @@ -319,7 +319,7 @@ namespace LLTrace mLastValue; F64 mMean, - mVarianceSum; + mSumOfSquares; U32 mNumSamples; }; @@ -336,7 +336,7 @@ namespace LLTrace mMin((std::numeric_limits<F64>::max)()), mMax((std::numeric_limits<F64>::min)()), mMean(0), - mVarianceSum(0), + mSumOfSquares(0), mLastSampleTimeStamp(LLTimer::getTotalSeconds()), mTotalSamplingTime(0), mNumSamples(0), @@ -361,7 +361,7 @@ namespace LLTrace F64 old_mean = mMean; mMean += (delta_time / mTotalSamplingTime) * (mLastValue - old_mean); - mVarianceSum += delta_time * (mLastValue - old_mean) * (mLastValue - mMean); + mSumOfSquares += delta_time * (mLastValue - old_mean) * (mLastValue - mMean); } mLastValue = value; @@ -385,20 +385,20 @@ namespace LLTrace n_2 = other.mTotalSamplingTime; F64 m_1 = mMean, m_2 = other.mMean; - F64 v_1 = mVarianceSum / mTotalSamplingTime, - v_2 = other.mVarianceSum / other.mTotalSamplingTime; + F64 v_1 = mSumOfSquares / mTotalSamplingTime, + v_2 = other.mSumOfSquares / other.mTotalSamplingTime; if (n_1 == 0) { - mVarianceSum = other.mVarianceSum; + mSumOfSquares = other.mSumOfSquares; } else if (n_2 == 0) { // variance is unchanged - // mVarianceSum = mVarianceSum; + // mSumOfSquares = mSumOfSquares; } else { - mVarianceSum = mTotalSamplingTime + mSumOfSquares = mTotalSamplingTime * ((((n_1 - 1.f) * v_1) + ((n_2 - 1.f) * v_2) + (((n_1 * n_2) / (n_1 + n_2)) @@ -427,7 +427,7 @@ namespace LLTrace mMin = std::numeric_limits<F64>::max(); mMax = std::numeric_limits<F64>::min(); mMean = other ? other->mLastValue : 0; - mVarianceSum = 0; + mSumOfSquares = 0; mLastSampleTimeStamp = LLTimer::getTotalSeconds(); mTotalSamplingTime = 0; mLastValue = other ? other->mLastValue : 0; @@ -451,7 +451,7 @@ namespace LLTrace F64 getMax() const { return mMax; } F64 getLastValue() const { return mLastValue; } F64 getMean() const { return mMean; } - F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mTotalSamplingTime); } + F64 getStandardDeviation() const { return sqrtf(mSumOfSquares / mTotalSamplingTime); } U32 getSampleCount() const { return mNumSamples; } private: @@ -463,7 +463,7 @@ namespace LLTrace bool mHasValue; F64 mMean, - mVarianceSum; + mSumOfSquares; LLUnitImplicit<F64, LLUnits::Seconds> mLastSampleTimeStamp, mTotalSamplingTime; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 31616a52cc..f5e4ea603c 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -333,6 +333,21 @@ namespace LLTrace const Recording& getPrevRecording(U32 offset) const; Recording snapshotCurRecording() const; + template <typename T> + size_t getSampleCount(const TraceType<T>& stat, size_t num_periods = U32_MAX) + { + size_t total_periods = mNumPeriods; + num_periods = llmin(num_periods, isStarted() ? total_periods - 1 : total_periods); + + size_t num_samples = 0; + for (S32 i = 1; i <= num_periods; i++) + { + S32 index = (mCurPeriod + total_periods - i) % total_periods; + num_samples += mRecordingPeriods[index].getSampleCount(stat); + } + return num_samples; + } + // // PERIODIC MIN // diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index f81e746c77..d6d8d9da6a 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -542,28 +542,28 @@ struct base_unit_name } -#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation) \ -struct unit_name \ -{ \ - typedef base_unit_name base_unit_t; \ - static const char* getUnitLabel() { return unit_label; } \ - template<typename T> \ - static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); } \ - template<typename STORAGE_T, typename UNIT_T> \ - static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value) \ - { return LLUnit<STORAGE_T, unit_name>(value); } \ -}; \ - \ -template<typename S1, typename S2> \ -void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \ -{ \ - out = LLUnit<S2, base_unit_name>((S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation)); \ -} \ - \ -template<typename S1, typename S2> \ -void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \ -{ \ - out = LLUnit<S2, unit_name>((S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation)); \ +#define LL_DECLARE_DERIVED_UNIT(base_unit_name, conversion_operation, unit_name, unit_label) \ +struct unit_name \ +{ \ + typedef base_unit_name base_unit_t; \ + static const char* getUnitLabel() { return unit_label; } \ + template<typename T> \ + static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); } \ + template<typename STORAGE_T, typename UNIT_T> \ + static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value) \ + { return LLUnit<STORAGE_T, unit_name>(value); } \ +}; \ + \ +template<typename S1, typename S2> \ +void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \ +{ \ + out = LLUnit<S2, base_unit_name>((S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation)); \ +} \ + \ +template<typename S1, typename S2> \ +void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \ +{ \ + out = LLUnit<S2, unit_name>((S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation)); \ } // @@ -573,46 +573,46 @@ void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) namespace LLUnits { LL_DECLARE_BASE_UNIT(Bytes, "B"); -LL_DECLARE_DERIVED_UNIT(Kilobytes, "KB", Bytes, * 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", 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", 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_DERIVED_UNIT(Bytes, * 1000, Kilobytes, "KB"); +LL_DECLARE_DERIVED_UNIT(Kilobytes, * 1000, Megabytes, "MB"); +LL_DECLARE_DERIVED_UNIT(Megabytes, * 1000, Gigabytes, "GB"); +LL_DECLARE_DERIVED_UNIT(Bytes, * 1024, Kibibytes, "KiB"); +LL_DECLARE_DERIVED_UNIT(Kibibytes, * 1024, Mibibytes, "MiB"); +LL_DECLARE_DERIVED_UNIT(Mibibytes, * 1024, Gibibytes, "GiB"); + +LL_DECLARE_DERIVED_UNIT(Bytes, / 8, Bits, "b"); +LL_DECLARE_DERIVED_UNIT(Bits, * 1000, Kilobits, "Kb"); +LL_DECLARE_DERIVED_UNIT(Kilobits, * 1000, Megabits, "Mb"); +LL_DECLARE_DERIVED_UNIT(Megabits, * 1000, Gigabits, "Gb"); +LL_DECLARE_DERIVED_UNIT(Bits, * 1024, Kibibits, "Kib"); +LL_DECLARE_DERIVED_UNIT(Kibibits, * 1024, Mibibits, "Mib"); +LL_DECLARE_DERIVED_UNIT(Mibibits, * 1024, Gibibits, "Gib"); 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", Milliseconds, / 1000); -LL_DECLARE_DERIVED_UNIT(Nanoseconds, "ns", Microseconds, / 1000); +LL_DECLARE_DERIVED_UNIT(Seconds, * 60, Minutes, "min"); +LL_DECLARE_DERIVED_UNIT(Minutes, * 60, Hours, "h"); +LL_DECLARE_DERIVED_UNIT(Seconds, / 1000, Milliseconds, "ms"); +LL_DECLARE_DERIVED_UNIT(Milliseconds, / 1000, Microseconds, "\x09\x3cs"); +LL_DECLARE_DERIVED_UNIT(Microseconds, / 1000, Nanoseconds, "ns"); 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(Meters, * 1000, Kilometers, "km"); +LL_DECLARE_DERIVED_UNIT(Meters, / 100, Centimeters, "cm"); +LL_DECLARE_DERIVED_UNIT(Meters, / 1000, Millimeters, "mm"); LL_DECLARE_BASE_UNIT(Hertz, "Hz"); -LL_DECLARE_DERIVED_UNIT(Kilohertz, "KHz", Hertz, * 1000); -LL_DECLARE_DERIVED_UNIT(Megahertz, "MHz", Kilohertz, * 1000); -LL_DECLARE_DERIVED_UNIT(Gigahertz, "GHz", Megahertz, * 1000); +LL_DECLARE_DERIVED_UNIT(Hertz, * 1000, Kilohertz, "KHz"); +LL_DECLARE_DERIVED_UNIT(Kilohertz, * 1000, Megahertz, "MHz"); +LL_DECLARE_DERIVED_UNIT(Megahertz, * 1000, Gigahertz, "GHz"); LL_DECLARE_BASE_UNIT(Radians, "rad"); -LL_DECLARE_DERIVED_UNIT(Degrees, "deg", Radians, * 0.01745329251994); +LL_DECLARE_DERIVED_UNIT(Radians, / 57.29578f, Degrees, "deg"); LL_DECLARE_BASE_UNIT(Percent, "%"); -LL_DECLARE_DERIVED_UNIT(Ratio, "x", Percent, / 100); +LL_DECLARE_DERIVED_UNIT(Percent, * 100, Ratio, "x"); LL_DECLARE_BASE_UNIT(Triangles, "tris"); -LL_DECLARE_DERIVED_UNIT(Kilotriangles, "ktris", Triangles, * 1000); +LL_DECLARE_DERIVED_UNIT(Triangles, * 1000, Kilotriangles, "ktris"); } // namespace LLUnits |