From b3e9c46c94dad0c81a5adcb9152521b5368c66a7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 29 Aug 2012 22:50:56 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages further cleanup of LLStat removed llfloaterlagmeter --- indra/llcommon/llstat.cpp | 84 +++++++++-------------------------------------- indra/llcommon/llstat.h | 31 +++++------------ 2 files changed, 25 insertions(+), 90 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llstat.cpp b/indra/llcommon/llstat.cpp index 3678c8e1c1..b46d2e58b2 100644 --- a/indra/llcommon/llstat.cpp +++ b/indra/llcommon/llstat.cpp @@ -51,9 +51,10 @@ void LLStat::reset() mNextBin = 0; } -LLStat::LLStat(std::string name, S32 num_bins, BOOL use_frame_timer) -: mUseFrameTimer(use_frame_timer), - mNumBins(num_bins), +LLStat::LLStat(std::string name, BOOL use_frame_timer) +: LLInstanceTracker(name), + mUseFrameTimer(use_frame_timer), + mNumBins(50), mName(name), mBins(NULL) { @@ -61,48 +62,24 @@ LLStat::LLStat(std::string name, S32 num_bins, BOOL use_frame_timer) mLastTime = 0.f; reset(); - - if (!mName.empty()) - { - stat_map_t::iterator iter = getStatList().find(mName); - if (iter != getStatList().end()) - llwarns << "LLStat with duplicate name: " << mName << llendl; - getStatList().insert(std::make_pair(mName, this)); - } -} - -LLStat::stat_map_t& LLStat::getStatList() -{ - static LLStat::stat_map_t stat_list; - return stat_list; } - LLStat::~LLStat() { delete[] mBins; - - if (!mName.empty()) - { - // handle multiple entries with the same name - stat_map_t::iterator iter = getStatList().find(mName); - while (iter != getStatList().end() && iter->second != this) - ++iter; - getStatList().erase(iter); - } -} - -void LLStat::start() -{ - if (mUseFrameTimer) - { - mBins[mNextBin].mBeginTime = sFrameTimer.getElapsedSeconds(); - } - else - { - mBins[mNextBin].mBeginTime = sTimer.getElapsedTimeF64(); - } } +// +//void LLStat::start() +//{ +// if (mUseFrameTimer) +// { +// mBins[mNextBin].mBeginTime = sFrameTimer.getElapsedSeconds(); +// } +// else +// { +// mBins[mNextBin].mBeginTime = sTimer.getElapsedTimeF64(); +// } +//} void LLStat::addValue(const F32 value) { @@ -299,31 +276,6 @@ F32 LLStat::getMeanPerSec() const } } -F32 LLStat::getMeanDuration() const -{ - F32 dur = 0.0f; - S32 count = 0; - for (S32 i=0; (i < mNumBins) && (i < mNumValues); i++) - { - if (i == mNextBin) - { - continue; - } - dur += mBins[i].mDT; - count++; - } - - if (count > 0) - { - dur /= F32(count); - return dur; - } - else - { - return 0.f; - } -} - F32 LLStat::getMaxPerSec() const { F32 value; @@ -398,7 +350,3 @@ S32 LLStat::getNextBin() const return mNextBin; } -F64 LLStat::getLastTime() const -{ - return mLastTime; -} diff --git a/indra/llcommon/llstat.h b/indra/llcommon/llstat.h index 38377a010b..82a246275d 100644 --- a/indra/llcommon/llstat.h +++ b/indra/llcommon/llstat.h @@ -31,22 +31,18 @@ #include "lltimer.h" #include "llframetimer.h" +#include "llinstancetracker.h" class LLSD; // ---------------------------------------------------------------------------- -class LL_COMMON_API LLStat +class LL_COMMON_API LLStat : public LLInstanceTracker { -private: - typedef std::multimap stat_map_t; - - static stat_map_t& getStatList(); - public: - LLStat(std::string name = std::string(), S32 num_bins = 32, BOOL use_frame_timer = FALSE); + LLStat(std::string name = std::string(), BOOL use_frame_timer = FALSE); ~LLStat(); - void start(); // Start the timer for the current "frame", otherwise uses the time tracked from + //void start(); // Start the timer for the current "frame", otherwise uses the time tracked from // the last addValue void reset(); void addValue(const F32 value = 1.f); // Adds the current value being tracked, and tracks the DT. @@ -57,23 +53,24 @@ public: F32 getPrev(S32 age) const; // Age is how many "addValues" previously - zero is current F32 getPrevPerSec(S32 age) const; // Age is how many "addValues" previously - zero is current + F32 getCurrent() const; F32 getCurrentPerSec() const; F32 getMin() const; F32 getMinPerSec() const; + F32 getMean() const; F32 getMeanPerSec() const; - F32 getMeanDuration() const; + F32 getMax() const; F32 getMaxPerSec() const; U32 getNumValues() const; S32 getNumBins() const; - F64 getLastTime() const; private: - BOOL mUseFrameTimer; + bool mUseFrameTimer; U32 mNumValues; U32 mNumBins; F32 mLastValue; @@ -93,6 +90,7 @@ private: F32 mDT; }; ValueEntry* mBins; + S32 mCurBin; S32 mNextBin; @@ -100,17 +98,6 @@ private: static LLTimer sTimer; static LLFrameTimer sFrameTimer; - -public: - static LLStat* getStat(const std::string& name) - { - // return the first stat that matches 'name' - stat_map_t::iterator iter = getStatList().find(name); - if (iter != getStatList().end()) - return iter->second; - else - return NULL; - } }; #endif // LL_STAT_ -- cgit v1.2.3 From 62fcbb063a191fa4789145c3937e7bef6ce544bd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 5 Sep 2012 18:49:28 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages first pass at LLTrace framework --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llfasttimer.cpp | 12 +-- indra/llcommon/llfasttimer.h | 9 ++- indra/llcommon/lltrace.h | 169 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 indra/llcommon/lltrace.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 87fffec0c3..05477c5fa6 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -238,6 +238,7 @@ set(llcommon_HEADER_FILES llthread.h llthreadsafequeue.h lltimer.h + lltrace.h lltreeiterators.h lltypeinfolookup.h lluri.h diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 6970c29092..939e332c3b 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -216,7 +216,7 @@ LLFastTimer::NamedTimer::NamedTimer(const std::string& name) : mName(name), mCollapsed(true), mParent(NULL), - mTotalTimeCounter(0), + mTreeTimeCounter(0), mCountAverage(0), mCallAverage(0), mNeedsSorting(false), @@ -389,6 +389,8 @@ void LLFastTimer::NamedTimer::accumulateTimings() U32 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; cur_timer->mFrameState->mSelfTimeCounter += self_time_delta; + cur_timer->mFrameState->mTotalTimeCounter += cumulative_time_delta; + cur_timer->mStartTime = cur_time; cur_data = &cur_timer->mLastTimerData; @@ -403,10 +405,10 @@ void LLFastTimer::NamedTimer::accumulateTimings() ++it) { NamedTimer* timerp = (*it); - timerp->mTotalTimeCounter = timerp->getFrameState().mSelfTimeCounter; + timerp->mTreeTimeCounter = timerp->getFrameState().mSelfTimeCounter; for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) { - timerp->mTotalTimeCounter += (*child_it)->mTotalTimeCounter; + timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; } S32 cur_frame = sCurFrameIndex; @@ -415,8 +417,8 @@ void LLFastTimer::NamedTimer::accumulateTimings() // update timer history int hidx = cur_frame % HISTORY_NUM; - timerp->mCountHistory[hidx] = timerp->mTotalTimeCounter; - timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTotalTimeCounter) / (cur_frame+1); + timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; + timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); timerp->mCallHistory[hidx] = timerp->getFrameState().mCalls; timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + timerp->getFrameState().mCalls) / (cur_frame+1); } diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index e42e549df5..061a37ae31 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -45,18 +45,17 @@ LL_COMMON_API void assert_main_thread(); class LL_COMMON_API LLFastTimer { public: - class NamedTimer; - struct LL_COMMON_API FrameState { FrameState(); void setNamedTimer(NamedTimer* timerp) { mTimer = timerp; } U32 mSelfTimeCounter; + U32 mTotalTimeCounter; U32 mCalls; FrameState* mParent; // info for caller timer FrameState* mLastCaller; // used to bootstrap tree construction - NamedTimer* mTimer; + class NamedTimer* mTimer; U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame }; @@ -120,7 +119,8 @@ public: std::string mName; - U32 mTotalTimeCounter; + // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete + U32 mTreeTimeCounter; U32 mCountAverage; U32 mCallAverage; @@ -186,6 +186,7 @@ public: U32 total_time = getCPUClockCount32() - mStartTime; frame_state->mSelfTimeCounter += total_time - LLFastTimer::sCurTimerData.mChildTime; + frame_state->mTotalTimeCounter += total_time; frame_state->mActiveCount--; // store last caller to bootstrap tree creation diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h new file mode 100644 index 0000000000..3d3ee18100 --- /dev/null +++ b/indra/llcommon/lltrace.h @@ -0,0 +1,169 @@ +/** + * @file lltrace.h + * @brief Runtime statistics accumulation. + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTRACE_H +#define LL_LLTRACE_H + +namespace LLTrace +{ + class Stat + { + public: + Stat(const char* name) + : mName(name) + {} + void record() {} + void record(int value) {} + void record(float value) {} + private: + const std::string mName; + }; + + class BlockTimer + { + public: + BlockTimer(const char* name) + : mName(name) + {} + + struct Accumulator + { + U32 mSelfTimeCounter; + U32 mTotalTimeCounter; + U32 mCalls; + Accumulator* mParent; // info for caller timer + Accumulator* mLastCaller; // used to bootstrap tree construction + const BlockTimer* mTimer; // points to block timer associated with this storage + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame + std::vector mChildren; // currently assumed child timers + }; + + struct RecorderHead + { + struct Recorder* mRecorder; + Accumulator* mAccumulator; + U32 mChildTime; + }; + + struct Recorder + { + LL_FORCE_INLINE Recorder(BlockTimer& block_timer) + : mLastHead(sRecorderHead) + { + mStartTime = getCPUClockCount32(); + Accumulator* accumulator = ???; // get per-thread accumulator + accumulator->mActiveCount++; + accumulator->mCalls++; + accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); + + // push new timer on stack + sRecorderHead->mRecorder = this; + sRecorderHead->mAccumulator = accumulator; + sRecorderHead->mChildTime = 0; + } + + LL_FORCE_INLINE ~Recorder() + { + U32 total_time = getCPUClockCount32() - mStartTime; + + Accumulator* accumulator = sRecorderHead->mAccumulator; + accumulator->mSelfTimeCounter += total_time- sRecorderHead.mChildTime; + accumulator->mTotalTimeCounter += total_time; + accumulator->mActiveCount--; + + accumulator->mLastCaller = mLastHead->mAccumulator; + mLastHead->mChildTime += total_time; + + // pop stack + sRecorderHead = mLastHead; + } + + AccumulatorHead mLastHead; + U32 mStartTime; + }; + + private: + U32 getCPUClockCount32() + { + U32 ret_val; + __asm + { + _emit 0x0f + _emit 0x31 + shr eax,8 + shl edx,24 + or eax, edx + mov dword ptr [ret_val], eax + } + return ret_val; + } + + // return full timer value, *not* shifted by 8 bits + static U64 getCPUClockCount64() + { + U64 ret_val; + __asm + { + _emit 0x0f + _emit 0x31 + mov eax,eax + mov edx,edx + mov dword ptr [ret_val+4], edx + mov dword ptr [ret_val], eax + } + return ret_val; + } + + const std::string mName; + static RecorderHead* sRecorderHead; + }; + + BlockTimer::RecorderHead BlockTimer::sRecorderHead; + + class TimeInterval + { + public: + void start() {} + void stop() {} + void resume() {} + }; + + class SamplingTimeInterval + { + public: + void start() {} + void stop() {} + void resume() {} + }; + +} + +#define TOKEN_PASTE_ACTUAL(x, y) x##y +#define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) +#define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); + +#endif // LL_LLTRACE_H -- cgit v1.2.3 From 6814906fec95aeb90dbc99605f74f241a72af12b Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 5 Sep 2012 18:54:26 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages build fix --- indra/llcommon/llfasttimer.cpp | 26 +++++++++++++------------- indra/llcommon/llfasttimer.h | 12 ++++++------ indra/llcommon/lltrace.h | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 939e332c3b..0abaf73063 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -388,8 +388,8 @@ void LLFastTimer::NamedTimer::accumulateTimings() U32 cumulative_time_delta = cur_time - cur_timer->mStartTime; U32 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; - cur_timer->mFrameState->mSelfTimeCounter += self_time_delta; - cur_timer->mFrameState->mTotalTimeCounter += cumulative_time_delta; + cur_data->mFrameState->mSelfTimeCounter += self_time_delta; + cur_data->mFrameState->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; @@ -643,16 +643,16 @@ const LLFastTimer::NamedTimer* LLFastTimer::getTimerByName(const std::string& na return NamedTimerFactory::instance().getTimerByName(name); } -LLFastTimer::LLFastTimer(LLFastTimer::FrameState* state) -: mFrameState(state) -{ - U32 start_time = getCPUClockCount32(); - mStartTime = start_time; - mFrameState->mActiveCount++; - LLFastTimer::sCurTimerData.mCurTimer = this; - LLFastTimer::sCurTimerData.mFrameState = mFrameState; - LLFastTimer::sCurTimerData.mChildTime = 0; - mLastTimerData = LLFastTimer::sCurTimerData; -} +//LLFastTimer::LLFastTimer(LLFastTimer::FrameState* state) +//: mFrameState(state) +//{ +// U32 start_time = getCPUClockCount32(); +// mStartTime = start_time; +// mFrameState->mActiveCount++; +// LLFastTimer::sCurTimerData.mCurTimer = this; +// LLFastTimer::sCurTimerData.mFrameState = mFrameState; +// LLFastTimer::sCurTimerData.mChildTime = 0; +// mLastTimerData = LLFastTimer::sCurTimerData; +//} diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 061a37ae31..4660fad5e3 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -45,10 +45,12 @@ LL_COMMON_API void assert_main_thread(); class LL_COMMON_API LLFastTimer { public: + class NamedTimer; + struct LL_COMMON_API FrameState { FrameState(); - void setNamedTimer(NamedTimer* timerp) { mTimer = timerp; } + void setNamedTimer(class NamedTimer* timerp) { mTimer = timerp; } U32 mSelfTimeCounter; U32 mTotalTimeCounter; @@ -152,13 +154,12 @@ public: }; public: - LLFastTimer(LLFastTimer::FrameState* state); + //LLFastTimer(LLFastTimer::FrameState* state); LL_FORCE_INLINE LLFastTimer(LLFastTimer::DeclareTimer& timer) - : mFrameState(&timer.mFrameState) { #if FAST_TIMER_ON - LLFastTimer::FrameState* frame_state = mFrameState; + LLFastTimer::FrameState* frame_state = &timer.mFrameState; mStartTime = getCPUClockCount32(); frame_state->mActiveCount++; @@ -182,7 +183,7 @@ public: LL_FORCE_INLINE ~LLFastTimer() { #if FAST_TIMER_ON - LLFastTimer::FrameState* frame_state = mFrameState; + LLFastTimer::FrameState* frame_state = LLFastTimer::sCurTimerData.mFrameState; U32 total_time = getCPUClockCount32() - mStartTime; frame_state->mSelfTimeCounter += total_time - LLFastTimer::sCurTimerData.mChildTime; @@ -380,7 +381,6 @@ private: static U64 sLastFrameTime; U32 mStartTime; - LLFastTimer::FrameState* mFrameState; LLFastTimer::CurTimerData mLastTimerData; }; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 3d3ee18100..6323091cb8 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -81,16 +81,16 @@ namespace LLTrace accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); // push new timer on stack - sRecorderHead->mRecorder = this; - sRecorderHead->mAccumulator = accumulator; - sRecorderHead->mChildTime = 0; + sRecorderHead.mRecorder = this; + sRecorderHead.mAccumulator = accumulator; + sRecorderHead.mChildTime = 0; } LL_FORCE_INLINE ~Recorder() { U32 total_time = getCPUClockCount32() - mStartTime; - Accumulator* accumulator = sRecorderHead->mAccumulator; + Accumulator* accumulator = sRecorderHead.mAccumulator; accumulator->mSelfTimeCounter += total_time- sRecorderHead.mChildTime; accumulator->mTotalTimeCounter += total_time; accumulator->mActiveCount--; -- cgit v1.2.3 From 2cdfb170216c798c637081b0e28ec8921f0b777b Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 5 Sep 2012 19:04:53 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages renamed some variables in lltrace --- indra/llcommon/lltrace.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6323091cb8..f3ee90a721 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -51,18 +51,18 @@ namespace LLTrace struct Accumulator { - U32 mSelfTimeCounter; U32 mTotalTimeCounter; + U32 mChildTimeCounter; U32 mCalls; Accumulator* mParent; // info for caller timer Accumulator* mLastCaller; // used to bootstrap tree construction const BlockTimer* mTimer; // points to block timer associated with this storage - U16 mActiveCount; // number of timers with this ID active on stack + U8 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame std::vector mChildren; // currently assumed child timers }; - struct RecorderHead + struct RecorderStackEntry { struct Recorder* mRecorder; Accumulator* mAccumulator; @@ -72,7 +72,7 @@ namespace LLTrace struct Recorder { LL_FORCE_INLINE Recorder(BlockTimer& block_timer) - : mLastHead(sRecorderHead) + : mLastRecorder(sCurRecorder) { mStartTime = getCPUClockCount32(); Accumulator* accumulator = ???; // get per-thread accumulator @@ -81,28 +81,28 @@ namespace LLTrace accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); // push new timer on stack - sRecorderHead.mRecorder = this; - sRecorderHead.mAccumulator = accumulator; - sRecorderHead.mChildTime = 0; + sCurRecorder.mRecorder = this; + sCurRecorder.mAccumulator = accumulator; + sCurRecorder.mChildTime = 0; } LL_FORCE_INLINE ~Recorder() { U32 total_time = getCPUClockCount32() - mStartTime; - Accumulator* accumulator = sRecorderHead.mAccumulator; - accumulator->mSelfTimeCounter += total_time- sRecorderHead.mChildTime; + Accumulator* accumulator = sCurRecorder.mAccumulator; accumulator->mTotalTimeCounter += total_time; + accumulator->mChildTimeCounter += sCurRecorder.mChildTime; accumulator->mActiveCount--; - accumulator->mLastCaller = mLastHead->mAccumulator; - mLastHead->mChildTime += total_time; + accumulator->mLastCaller = mLastRecorder->mAccumulator; + mLastRecorder->mChildTime += total_time; // pop stack - sRecorderHead = mLastHead; + sCurRecorder = mLastRecorder; } - AccumulatorHead mLastHead; + RecorderStackEntry mLastRecorder; U32 mStartTime; }; @@ -139,10 +139,10 @@ namespace LLTrace } const std::string mName; - static RecorderHead* sRecorderHead; + static RecorderStackEntry* sCurRecorder; }; - BlockTimer::RecorderHead BlockTimer::sRecorderHead; + BlockTimer::RecorderStackEntry BlockTimer::sCurRecorder; class TimeInterval { -- cgit v1.2.3 From d18a3f395fb2b29dbf83092896a5ed5eb9f75f16 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 6 Sep 2012 17:18:12 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages lltrace cleanup --- indra/llcommon/lltrace.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index f3ee90a721..1d2dcff9b7 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -27,6 +27,8 @@ #ifndef LL_LLTRACE_H #define LL_LLTRACE_H +#include + namespace LLTrace { class Stat @@ -51,11 +53,11 @@ namespace LLTrace struct Accumulator { - U32 mTotalTimeCounter; - U32 mChildTimeCounter; - U32 mCalls; - Accumulator* mParent; // info for caller timer - Accumulator* mLastCaller; // used to bootstrap tree construction + U32 mTotalTimeCounter, + mChildTimeCounter, + mCalls; + Accumulator* mParent, // info for caller timer + mLastCaller; // used to bootstrap tree construction const BlockTimer* mTimer; // points to block timer associated with this storage U8 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame -- cgit v1.2.3 From 8d4ceab6a34d58c5f4235baa870eb88d86df30f3 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 6 Sep 2012 23:00:32 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages further development of lltrace (accumulator and storage classes) --- indra/llcommon/lltrace.h | 111 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 16 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 1d2dcff9b7..c6940c12a2 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -27,28 +27,108 @@ #ifndef LL_LLTRACE_H #define LL_LLTRACE_H +#include "stdtypes.h" +#include "llpreprocessor.h" + #include +#include namespace LLTrace { - class Stat + //TODO figure out best way to do this and proper naming convention + + static + void init() + { + + } + + template + class Accumulator { public: - Stat(const char* name) - : mName(name) + Accumulator() + : mSum(), + mMin(), + mMax(), + mNumSamples(0) + {} + + void sample(T value) + { + mNumSamples++; + mSum += value; + if (value < mMin) + { + mMin = value; + } + else if (value > mMax) + { + mMax = value; + } + } + + private: + T mSum, + mMin, + mMax; + + U32 mNumSamples; + }; + + class TraceStorage + { + protected: + TraceStorage(const size_t size, const size_t alignment) + { + mRecordOffset = sNextOffset + (alignment - 1); + mRecordOffset -= mRecordOffset % alignment; + sNextOffset = mRecordOffset + size; + sStorage.reserve((size_t)sNextOffset); + } + + // this needs to be thread local + static std::vector sStorage; + static ptrdiff_t sNextOffset; + + ptrdiff_t mRecordOffset; + }; + + std::vector TraceStorage::sStorage; + ptrdiff_t TraceStorage::sNextOffset = 0; + + template + class Trace : public TraceStorage + { + public: + Trace(const std::string& name) + : TraceStorage(sizeof(Accumulator), boost::alignment_of >::value), + mName(name) {} - void record() {} - void record(int value) {} - void record(float value) {} + + void record(T value) + { + (reinterpret_cast* >(sStorage + mRecordOffset))->sample(value); + } + private: - const std::string mName; + std::string mName; + }; + + template + class Stat : public Trace + { + public: + Stat(const char* name) + : Trace(name) + {} }; - class BlockTimer + class BlockTimer : public Trace { public: BlockTimer(const char* name) - : mName(name) + : Trace(name) {} struct Accumulator @@ -56,8 +136,8 @@ namespace LLTrace U32 mTotalTimeCounter, mChildTimeCounter, mCalls; - Accumulator* mParent, // info for caller timer - mLastCaller; // used to bootstrap tree construction + Accumulator* mParent; // info for caller timer + Accumulator* mLastCaller; // used to bootstrap tree construction const BlockTimer* mTimer; // points to block timer associated with this storage U8 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame @@ -97,8 +177,8 @@ namespace LLTrace accumulator->mChildTimeCounter += sCurRecorder.mChildTime; accumulator->mActiveCount--; - accumulator->mLastCaller = mLastRecorder->mAccumulator; - mLastRecorder->mChildTime += total_time; + accumulator->mLastCaller = mLastRecorder.mAccumulator; + mLastRecorder.mChildTime += total_time; // pop stack sCurRecorder = mLastRecorder; @@ -109,7 +189,7 @@ namespace LLTrace }; private: - U32 getCPUClockCount32() + static U32 getCPUClockCount32() { U32 ret_val; __asm @@ -140,8 +220,7 @@ namespace LLTrace return ret_val; } - const std::string mName; - static RecorderStackEntry* sCurRecorder; + static RecorderStackEntry sCurRecorder; }; BlockTimer::RecorderStackEntry BlockTimer::sCurRecorder; -- cgit v1.2.3 From a8c0d23bdeb009f6797f1dfa727e8c0cf4f6bc96 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Sep 2012 18:51:38 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages created buffer type for storing trace data added merging logic for different trace types --- indra/llcommon/lltrace.h | 156 +++++++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 66 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index c6940c12a2..c5bde0330a 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -37,24 +37,57 @@ namespace LLTrace { //TODO figure out best way to do this and proper naming convention - static - void init() + static void init() { } + template + class Trace + { + public: + Trace(const std::string& name) + : mName(name) + { + mStorageIndex = sNextIndex++; + sStorage.reserve(sNextIndex); + } + + LL_FORCE_INLINE ACCUMULATOR& getAccumulator() + { + return sStorage[mStorageIndex]; + } + + void mergeFrom(const Trace& other) + { + getAccumulator().mergeFrom(other.getAccumulator()); + } + + + private: + std::string mName; + ptrdiff_t mStorageIndex; + + // this needs to be thread local + static std::vector sStorage; + static size_t sNextIndex; + }; + + template std::vector Trace::sStorage; + template size_t Trace::sNextIndex = 0; + template class Accumulator { public: Accumulator() - : mSum(), + : mSum(), mMin(), mMax(), mNumSamples(0) {} - void sample(T value) + LL_FORCE_INLINE void sample(T value) { mNumSamples++; mSum += value; @@ -68,6 +101,20 @@ namespace LLTrace } } + void mergeFrom(const Accumulator& other) + { + mSum += other.mSum; + if (other.mMin < mMin) + { + mMin = other.mMin; + } + if (other.mMax > mMax) + { + mMax = other.mMax; + } + mNumSamples += other.mNumSamples; + } + private: T mSum, mMin, @@ -76,78 +123,55 @@ namespace LLTrace U32 mNumSamples; }; - class TraceStorage - { - protected: - TraceStorage(const size_t size, const size_t alignment) - { - mRecordOffset = sNextOffset + (alignment - 1); - mRecordOffset -= mRecordOffset % alignment; - sNextOffset = mRecordOffset + size; - sStorage.reserve((size_t)sNextOffset); - } - - // this needs to be thread local - static std::vector sStorage; - static ptrdiff_t sNextOffset; - - ptrdiff_t mRecordOffset; - }; - - std::vector TraceStorage::sStorage; - ptrdiff_t TraceStorage::sNextOffset = 0; template - class Trace : public TraceStorage + class Stat : public Trace > { public: - Trace(const std::string& name) - : TraceStorage(sizeof(Accumulator), boost::alignment_of >::value), - mName(name) + Stat(const char* name) + : Trace(name) {} - void record(T value) + void sample(T value) { - (reinterpret_cast* >(sStorage + mRecordOffset))->sample(value); + getAccumulator().sample(value); } - private: - std::string mName; }; - template - class Stat : public Trace + struct TimerAccumulator { - public: - Stat(const char* name) - : Trace(name) - {} + U32 mTotalTimeCounter, + mChildTimeCounter, + mCalls; + TimerAccumulator* mParent; // info for caller timer + TimerAccumulator* mLastCaller; // used to bootstrap tree construction + const BlockTimer* mTimer; // points to block timer associated with this storage + U8 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame + std::vector mChildren; // currently assumed child timers + + void mergeFrom(const TimerAccumulator& other) + { + mTotalTimeCounter += other.mTotalTimeCounter; + mChildTimeCounter += other.mChildTimeCounter; + mCalls += other.mCalls; + } }; - class BlockTimer : public Trace + class BlockTimer : public Trace { public: BlockTimer(const char* name) : Trace(name) {} - struct Accumulator - { - U32 mTotalTimeCounter, - mChildTimeCounter, - mCalls; - Accumulator* mParent; // info for caller timer - Accumulator* mLastCaller; // used to bootstrap tree construction - const BlockTimer* mTimer; // points to block timer associated with this storage - U8 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - std::vector mChildren; // currently assumed child timers - }; + struct Recorder; struct RecorderStackEntry { - struct Recorder* mRecorder; - Accumulator* mAccumulator; + Recorder* mRecorder; + TimerAccumulator* mAccumulator; U32 mChildTime; }; @@ -157,7 +181,7 @@ namespace LLTrace : mLastRecorder(sCurRecorder) { mStartTime = getCPUClockCount32(); - Accumulator* accumulator = ???; // get per-thread accumulator + TimerAccumulator* accumulator = &block_timer.getAccumulator(); // get per-thread accumulator accumulator->mActiveCount++; accumulator->mCalls++; accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); @@ -172,7 +196,7 @@ namespace LLTrace { U32 total_time = getCPUClockCount32() - mStartTime; - Accumulator* accumulator = sCurRecorder.mAccumulator; + TimerAccumulator* accumulator = sCurRecorder.mAccumulator; accumulator->mTotalTimeCounter += total_time; accumulator->mChildTimeCounter += sCurRecorder.mChildTime; accumulator->mActiveCount--; @@ -195,11 +219,11 @@ namespace LLTrace __asm { _emit 0x0f - _emit 0x31 - shr eax,8 - shl edx,24 - or eax, edx - mov dword ptr [ret_val], eax + _emit 0x31 + shr eax,8 + shl edx,24 + or eax, edx + mov dword ptr [ret_val], eax } return ret_val; } @@ -211,11 +235,11 @@ namespace LLTrace __asm { _emit 0x0f - _emit 0x31 - mov eax,eax - mov edx,edx - mov dword ptr [ret_val+4], edx - mov dword ptr [ret_val], eax + _emit 0x31 + mov eax,eax + mov edx,edx + mov dword ptr [ret_val+4], edx + mov dword ptr [ret_val], eax } return ret_val; } @@ -233,7 +257,7 @@ namespace LLTrace void resume() {} }; - class SamplingTimeInterval + class Sampler { public: void start() {} -- cgit v1.2.3 From fa91ea69cca32e0dabcfabe18070f57cc4a4cfd0 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Sep 2012 19:12:41 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages added buffer merging and copying --- indra/llcommon/lltrace.h | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index c5bde0330a..6272492945 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -31,7 +31,6 @@ #include "llpreprocessor.h" #include -#include namespace LLTrace { @@ -42,6 +41,35 @@ namespace LLTrace } + template + struct AccumulatorStorage + { + std::vector mStorage; + + ACCUMULATOR& operator[](size_t index) { return mStorage[index]; } + + void mergeFrom(const AccumulatorStorage& other) + { + llassert(mStorage.size() == other.mStorage.size()); + + for (size_t i = 0; i < mStorage.size(); i++) + { + mStorage[i].mergeFrom(other.mStorage[i]); + } + } + + void copyFrom(const AccumulatorStorage& other) + { + mStorage = other.mStorage; + } + + void resize(size_t size) + { + //TODO: get this grow more rapidly (as if with push back) + mStorage.reserve(size); + } + }; + template class Trace { @@ -50,7 +78,7 @@ namespace LLTrace : mName(name) { mStorageIndex = sNextIndex++; - sStorage.reserve(sNextIndex); + sStorage.resize(sNextIndex); } LL_FORCE_INLINE ACCUMULATOR& getAccumulator() @@ -69,8 +97,8 @@ namespace LLTrace ptrdiff_t mStorageIndex; // this needs to be thread local - static std::vector sStorage; - static size_t sNextIndex; + static AccumulatorStorage sStorage; + static size_t sNextIndex; }; template std::vector Trace::sStorage; @@ -81,7 +109,7 @@ namespace LLTrace { public: Accumulator() - : mSum(), + : mSum(), mMin(), mMax(), mNumSamples(0) -- cgit v1.2.3 From 917ed449daec0e0f91e2ff66a7d9b82866ed8b1e Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 14 Sep 2012 00:04:38 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages added multi-threaded sampling to LLTrace first pass at data aggregation --- indra/llcommon/lltrace.h | 305 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 256 insertions(+), 49 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6272492945..1b9a8db1c0 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -30,45 +30,90 @@ #include "stdtypes.h" #include "llpreprocessor.h" -#include +#include "llthread.h" + +#include namespace LLTrace { //TODO figure out best way to do this and proper naming convention - static void init() { } + // one per thread per type template - struct AccumulatorStorage + struct AccumulatorBuffer : public AccumulatorBufferBase { - std::vector mStorage; + ACCUMULATOR* mStorage; + size_t mStorageSize; + size_t mNextStorageSlot; + static S32 sStorageKey; // key used to access thread local storage pointer to accumulator values - ACCUMULATOR& operator[](size_t index) { return mStorage[index]; } + AccumulatorBuffer() + : mStorageSize(64), + mStorage(new ACCUMULATOR[64]), + mNextStorageSlot(0) + {} + + AccumulatorBuffer(const AccumulatorBuffer& other) + : mStorageSize(other.mStorageSize), + mStorage(new ACCUMULATOR[other.mStorageSize]), + mNextStorageSlot(other.mNextStorageSlot) + { + + } + + LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) { return (*mStorage)[index]; } - void mergeFrom(const AccumulatorStorage& other) + void mergeFrom(const AccumulatorBuffer& other) { - llassert(mStorage.size() == other.mStorage.size()); + llassert(mNextStorageSlot == other.mNextStorageSlot); - for (size_t i = 0; i < mStorage.size(); i++) + for (size_t i = 0; i < mNextStorageSlot; i++) { mStorage[i].mergeFrom(other.mStorage[i]); } } - void copyFrom(const AccumulatorStorage& other) + void copyFrom(const AccumulatorBuffer& other) + { + for (size_t i = 0; i < mNextStorageSlot; i++) + { + mStorage[i] = other.mStorage[i]; + } + } + + void reset() + { + for (size_t i = 0; i < mNextStorageSlot; i++) + { + mStorage[i].reset(); + } + } + + void makePrimary() { - mStorage = other.mStorage; + //TODO: use sStorageKey to set mStorage as active buffer } - void resize(size_t size) + // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned + size_t reserveSlot() { - //TODO: get this grow more rapidly (as if with push back) - mStorage.reserve(size); + size_t next_slot = mNextStorageSlot++; + if (next_slot >= mStorageSize) + { + size_t new_size = mStorageSize + (mStorageSize >> 2); + delete [] mStorage; + mStorage = new mStorage(new_size); + mStorageSize = new_size; + } + llassert(next_slot < mStorageSize); + return next_slot; } }; + template S32 AccumulatorBuffer::sStorageKey; template class Trace @@ -77,38 +122,29 @@ namespace LLTrace Trace(const std::string& name) : mName(name) { - mStorageIndex = sNextIndex++; - sStorage.resize(sNextIndex); + mAccumulatorIndex = sAccumulatorBuffer.reserveSlot(); } LL_FORCE_INLINE ACCUMULATOR& getAccumulator() { - return sStorage[mStorageIndex]; - } - - void mergeFrom(const Trace& other) - { - getAccumulator().mergeFrom(other.getAccumulator()); + return sAccumulatorBuffer[mAccumulatorIndex]; } - private: - std::string mName; - ptrdiff_t mStorageIndex; + std::string mName; + size_t mAccumulatorIndex; // this needs to be thread local - static AccumulatorStorage sStorage; - static size_t sNextIndex; + static AccumulatorBuffer sAccumulatorBuffer; }; - template std::vector Trace::sStorage; - template size_t Trace::sNextIndex = 0; + template std::vector Trace::sAccumulatorBuffer; template - class Accumulator + class StatAccumulator { public: - Accumulator() + StatAccumulator() : mSum(), mMin(), mMax(), @@ -129,7 +165,7 @@ namespace LLTrace } } - void mergeFrom(const Accumulator& other) + void mergeFrom(const Stat& other) { mSum += other.mSum; if (other.mMin < mMin) @@ -143,6 +179,14 @@ namespace LLTrace mNumSamples += other.mNumSamples; } + void reset() + { + mNumSamples = 0; + mSum = 0; + mMin = 0; + mMax = 0; + } + private: T mSum, mMin, @@ -151,12 +195,11 @@ namespace LLTrace U32 mNumSamples; }; - - template - class Stat : public Trace > + template + class Stat : public Trace > { public: - Stat(const char* name) + Stat(const std::string& name) : Trace(name) {} @@ -164,7 +207,6 @@ namespace LLTrace { getAccumulator().sample(value); } - }; struct TimerAccumulator @@ -174,7 +216,7 @@ namespace LLTrace mCalls; TimerAccumulator* mParent; // info for caller timer TimerAccumulator* mLastCaller; // used to bootstrap tree construction - const BlockTimer* mTimer; // points to block timer associated with this storage + const class BlockTimer* mTimer; // points to block timer associated with this storage U8 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame std::vector mChildren; // currently assumed child timers @@ -185,6 +227,14 @@ namespace LLTrace mChildTimeCounter += other.mChildTimeCounter; mCalls += other.mCalls; } + + void reset() + { + mTotalTimeCounter = 0; + mChildTimeCounter = 0; + mCalls = 0; + } + }; class BlockTimer : public Trace @@ -194,17 +244,15 @@ namespace LLTrace : Trace(name) {} - struct Recorder; - - struct RecorderStackEntry - { - Recorder* mRecorder; - TimerAccumulator* mAccumulator; - U32 mChildTime; - }; - struct Recorder { + struct StackEntry + { + Recorder* mRecorder; + TimerAccumulator* mAccumulator; + U32 mChildTime; + }; + LL_FORCE_INLINE Recorder(BlockTimer& block_timer) : mLastRecorder(sCurRecorder) { @@ -236,7 +284,7 @@ namespace LLTrace sCurRecorder = mLastRecorder; } - RecorderStackEntry mLastRecorder; + StackEntry mLastRecorder; U32 mStartTime; }; @@ -272,10 +320,169 @@ namespace LLTrace return ret_val; } - static RecorderStackEntry sCurRecorder; + static Recorder::StackEntry sCurRecorder; + }; + + BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; + + class Sampler + { + public: + Sampler(const Sampler& other) + : mF32Stats(other.mF32Stats), + mS32Stats(other.mS32Stats), + mTimers(other.mTimers) + {} + + ~Sampler() + { + stop(); + } + + void makePrimary() + { + mF32Stats.makePrimary(); + mS32Stats.makePrimary(); + mTimers.makePrimary(); + } + + void start() + { + reset(); + resume(); + } + + void stop() + { + getThreadData()->deactivate(this); + } + + void resume() + { + ThreadData* thread_data = getThreadData(); + thread_data->flushPrimarySampler(); + thread_data->activate(this); + } + + void mergeFrom(const Sampler& other) + { + mF32Stats.mergeFrom(other.mF32Stats); + mS32Stats.mergeFrom(other.mS32Stats); + mTimers.mergeFrom(other.mTimers); + } + + void reset() + { + mF32Stats.reset(); + mS32Stats.reset(); + mTimers.reset(); + } + + private: + // returns data for current thread + struct ThreadData* getThreadData() { return NULL; } + + AccumulatorBuffer > mF32Stats; + AccumulatorBuffer > mS32Stats; + + AccumulatorBuffer mTimers; + }; + + struct ThreadData + { + ThreadData(LLThread& this_thread, ThreadData& parent_data) + : mPrimarySampler(parent_data.mPrimarySampler), + mSharedSampler(parent_data.mSharedSampler), + mSharedSamplerMutex(this_thread.getAPRPool()), + mParent(parent_data) + { + mPrimarySampler.makePrimary(); + parent_data.addChildThread(this); + } + + ~ThreadData() + { + mParent.removeChildThread(this); + } + + void addChildThread(ThreadData* child) + { + mChildThreadData.push_back(child); + } + + void removeChildThread(ThreadData* child) + { + // TODO: replace with intrusive list + std::list::iterator found_it = std::find(mChildThreadData.begin(), mChildThreadData.end(), child); + if (found_it != mChildThreadData.end()) + { + mChildThreadData.erase(found_it); + } + } + + void flushPrimarySampler() + { + for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); + it != end_it; + ++it) + { + (*it)->mergeFrom(mPrimarySampler); + } + mPrimarySampler.reset(); + } + + void activate(Sampler* sampler) + { + mActiveSamplers.push_back(sampler); + } + + void deactivate(Sampler* sampler) + { + // TODO: replace with intrusive list + std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); + if (found_it != mActiveSamplers.end()) + { + mActiveSamplers.erase(found_it); + } + } + + // call this periodically to gather stats data in parent thread + void publishToParent() + { + mSharedSamplerMutex.lock(); + { + mSharedSampler.mergeFrom(mPrimarySampler); + } + mSharedSamplerMutex.unlock(); + } + + // call this periodically to gather stats data from children + void gatherChildData() + { + for (std::list::iterator child_it = mChildThreadData.begin(), end_it = mChildThreadData.end(); + child_it != end_it; + ++child_it) + { + (*child_it)->mSharedSamplerMutex.lock(); + { + //TODO for now, just aggregate, later keep track of thread data independently + mPrimarySampler.mergeFrom((*child_it)->mSharedSampler); + } + (*child_it)->mSharedSamplerMutex.unlock(); + } + } + + Sampler mPrimarySampler; + + ThreadData& mParent; + std::list mActiveSamplers; + std::list mChildThreadData; + + // TODO: add unused space here to avoid false sharing? + LLMutex mSharedSamplerMutex; + Sampler mSharedSampler; }; - BlockTimer::RecorderStackEntry BlockTimer::sCurRecorder; class TimeInterval { -- cgit v1.2.3 From d5fce3a8093bb101b7a536f3611d3135167b05c4 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 14 Sep 2012 00:08:20 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages renamed some variables/methods --- indra/llcommon/lltrace.h | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 1b9a8db1c0..7da182df1e 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -36,11 +36,6 @@ namespace LLTrace { - //TODO figure out best way to do this and proper naming convention - static void init() - { - - } // one per thread per type template @@ -354,13 +349,13 @@ namespace LLTrace void stop() { - getThreadData()->deactivate(this); + getThreadTracer()->deactivate(this); } void resume() { - ThreadData* thread_data = getThreadData(); - thread_data->flushPrimarySampler(); + ThreadTracer* thread_data = getThreadTracer(); + thread_data->flushData(); thread_data->activate(this); } @@ -380,7 +375,7 @@ namespace LLTrace private: // returns data for current thread - struct ThreadData* getThreadData() { return NULL; } + struct ThreadTracer* getThreadTracer() { return NULL; } AccumulatorBuffer > mF32Stats; AccumulatorBuffer > mS32Stats; @@ -388,9 +383,9 @@ namespace LLTrace AccumulatorBuffer mTimers; }; - struct ThreadData + struct ThreadTracer { - ThreadData(LLThread& this_thread, ThreadData& parent_data) + ThreadTracer(LLThread& this_thread, ThreadTracer& parent_data) : mPrimarySampler(parent_data.mPrimarySampler), mSharedSampler(parent_data.mSharedSampler), mSharedSamplerMutex(this_thread.getAPRPool()), @@ -400,27 +395,27 @@ namespace LLTrace parent_data.addChildThread(this); } - ~ThreadData() + ~ThreadTracer() { mParent.removeChildThread(this); } - void addChildThread(ThreadData* child) + void addChildThread(ThreadTracer* child) { - mChildThreadData.push_back(child); + mChildThreadTracers.push_back(child); } - void removeChildThread(ThreadData* child) + void removeChildThread(ThreadTracer* child) { // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mChildThreadData.begin(), mChildThreadData.end(), child); - if (found_it != mChildThreadData.end()) + std::list::iterator found_it = std::find(mChildThreadTracers.begin(), mChildThreadTracers.end(), child); + if (found_it != mChildThreadTracers.end()) { - mChildThreadData.erase(found_it); + mChildThreadTracers.erase(found_it); } } - void flushPrimarySampler() + void flushData() { for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); it != end_it; @@ -459,7 +454,7 @@ namespace LLTrace // call this periodically to gather stats data from children void gatherChildData() { - for (std::list::iterator child_it = mChildThreadData.begin(), end_it = mChildThreadData.end(); + for (std::list::iterator child_it = mChildThreadTracers.begin(), end_it = mChildThreadTracers.end(); child_it != end_it; ++child_it) { @@ -474,9 +469,9 @@ namespace LLTrace Sampler mPrimarySampler; - ThreadData& mParent; - std::list mActiveSamplers; - std::list mChildThreadData; + ThreadTracer& mParent; + std::list mActiveSamplers; + std::list mChildThreadTracers; // TODO: add unused space here to avoid false sharing? LLMutex mSharedSamplerMutex; -- cgit v1.2.3 From 735fde8c742188d019e41faf26ff67aab6a24d25 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 21 Sep 2012 18:52:08 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages added LLThreadLocalPtr broke llmutex out into llmutex.h got primary sampling buffer under thread local storage --- indra/llcommon/CMakeLists.txt | 4 + indra/llcommon/llmemory.h | 5 + indra/llcommon/llmutex.cpp | 229 ++++++++++++++++++++++++++++++++ indra/llcommon/llmutex.h | 168 ++++++++++++++++++++++++ indra/llcommon/llthread.cpp | 214 +++--------------------------- indra/llcommon/llthread.h | 171 +++--------------------- indra/llcommon/llthreadlocalptr.h | 141 ++++++++++++++++++++ indra/llcommon/lltrace.cpp | 95 ++++++++++++++ indra/llcommon/lltrace.h | 265 +++++++++++++++++++++----------------- 9 files changed, 826 insertions(+), 466 deletions(-) create mode 100644 indra/llcommon/llmutex.cpp create mode 100644 indra/llcommon/llmutex.h create mode 100644 indra/llcommon/llthreadlocalptr.h create mode 100644 indra/llcommon/lltrace.cpp (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 1812e39b36..eec2695dde 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -74,6 +74,7 @@ set(llcommon_SOURCE_FILES llmetrics.cpp llmetricperformancetester.cpp llmortician.cpp + llmutex.cpp lloptioninterface.cpp llptrto.cpp llprocess.cpp @@ -99,6 +100,7 @@ set(llcommon_SOURCE_FILES llthread.cpp llthreadsafequeue.cpp lltimer.cpp + lltrace.cpp lluri.cpp lluuid.cpp llworkerthread.cpp @@ -197,6 +199,7 @@ set(llcommon_HEADER_FILES llmetrics.h llmetricperformancetester.h llmortician.h + llmutex.h llnametable.h lloptioninterface.h llpointer.h @@ -237,6 +240,7 @@ set(llcommon_HEADER_FILES llstringtable.h llsys.h llthread.h + llthreadlocalptr.h llthreadsafequeue.h lltimer.h lltrace.h diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 6a2323e7d8..4480e381e8 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -30,6 +30,11 @@ class LLMutex ; +#ifdef LL_WINDOWS +#define LL_ALIGNED(x) __declspec(align(x)) +#else +#define LL_ALIGNED(x) __attribute__ ((aligned (16))) +#endif inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp new file mode 100644 index 0000000000..2ce14b3a2e --- /dev/null +++ b/indra/llcommon/llmutex.cpp @@ -0,0 +1,229 @@ +/** + * @file llmutex.cpp + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "llapr.h" + +#include "apr_portable.h" + +#include "llmutex.h" +#include "llthread.h" + +//============================================================================ + +LLMutex::LLMutex(apr_pool_t *poolp) : + mAPRMutexp(NULL), mCount(0), mLockingThread(NO_THREAD) +{ + //if (poolp) + //{ + // mIsLocalPool = FALSE; + // mAPRPoolp = poolp; + //} + //else + { + mIsLocalPool = TRUE; + apr_pool_create(&mAPRPoolp, NULL); // Create a subpool for this thread + } + apr_thread_mutex_create(&mAPRMutexp, APR_THREAD_MUTEX_UNNESTED, mAPRPoolp); +} + + +LLMutex::~LLMutex() +{ +#if MUTEX_DEBUG + //bad assertion, the subclass LLSignal might be "locked", and that's OK + //llassert_always(!isLocked()); // better not be locked! +#endif + apr_thread_mutex_destroy(mAPRMutexp); + mAPRMutexp = NULL; + if (mIsLocalPool) + { + apr_pool_destroy(mAPRPoolp); + } +} + + +void LLMutex::lock() +{ + if(isSelfLocked()) + { //redundant lock + mCount++; + return; + } + + apr_thread_mutex_lock(mAPRMutexp); + +#if MUTEX_DEBUG + // Have to have the lock before we can access the debug info + U32 id = LLThread::currentID(); + if (mIsLocked[id] != FALSE) + llerrs << "Already locked in Thread: " << id << llendl; + mIsLocked[id] = TRUE; +#endif + +#if LL_DARWIN + mLockingThread = LLThread::currentID(); +#else + mLockingThread = LLThread::sThreadIndex; +#endif +} + +void LLMutex::unlock() +{ + if (mCount > 0) + { //not the root unlock + mCount--; + return; + } + +#if MUTEX_DEBUG + // Access the debug info while we have the lock + U32 id = LLThread::currentID(); + if (mIsLocked[id] != TRUE) + llerrs << "Not locked in Thread: " << id << llendl; + mIsLocked[id] = FALSE; +#endif + + mLockingThread = NO_THREAD; + apr_thread_mutex_unlock(mAPRMutexp); +} + +bool LLMutex::isLocked() +{ + apr_status_t status = apr_thread_mutex_trylock(mAPRMutexp); + if (APR_STATUS_IS_EBUSY(status)) + { + return true; + } + else + { + apr_thread_mutex_unlock(mAPRMutexp); + return false; + } +} + +bool LLMutex::isSelfLocked() +{ +#if LL_DARWIN + return mLockingThread == LLThread::currentID(); +#else + return mLockingThread == LLThread::sThreadIndex; +#endif +} + +U32 LLMutex::lockingThread() const +{ + return mLockingThread; +} + +//============================================================================ + +LLCondition::LLCondition(apr_pool_t *poolp) : + LLMutex(poolp) +{ + // base class (LLMutex) has already ensured that mAPRPoolp is set up. + + apr_thread_cond_create(&mAPRCondp, mAPRPoolp); +} + + +LLCondition::~LLCondition() +{ + apr_thread_cond_destroy(mAPRCondp); + mAPRCondp = NULL; +} + + +void LLCondition::wait() +{ + if (!isLocked()) + { //mAPRMutexp MUST be locked before calling apr_thread_cond_wait + apr_thread_mutex_lock(mAPRMutexp); +#if MUTEX_DEBUG + // avoid asserts on destruction in non-release builds + U32 id = LLThread::currentID(); + mIsLocked[id] = TRUE; +#endif + } + apr_thread_cond_wait(mAPRCondp, mAPRMutexp); +} + +void LLCondition::signal() +{ + apr_thread_cond_signal(mAPRCondp); +} + +void LLCondition::broadcast() +{ + apr_thread_cond_broadcast(mAPRCondp); +} + + +//============================================================================ + +//---------------------------------------------------------------------------- + +//static +LLMutex* LLThreadSafeRefCount::sMutex = 0; + +//static +void LLThreadSafeRefCount::initThreadSafeRefCount() +{ + if (!sMutex) + { + sMutex = new LLMutex(0); + } +} + +//static +void LLThreadSafeRefCount::cleanupThreadSafeRefCount() +{ + delete sMutex; + sMutex = NULL; +} + + +//---------------------------------------------------------------------------- + +LLThreadSafeRefCount::LLThreadSafeRefCount() : +mRef(0) +{ +} + +LLThreadSafeRefCount::~LLThreadSafeRefCount() +{ + if (mRef != 0) + { + llerrs << "deleting non-zero reference" << llendl; + } +} + +//============================================================================ + +LLResponder::~LLResponder() +{ +} + +//============================================================================ diff --git a/indra/llcommon/llmutex.h b/indra/llcommon/llmutex.h new file mode 100644 index 0000000000..bd0a59b577 --- /dev/null +++ b/indra/llcommon/llmutex.h @@ -0,0 +1,168 @@ +/** + * @file llmutex.h + * @brief Base classes for mutex and condition handling. + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLMUTEX_H +#define LL_LLMUTEX_H + +#include "llapr.h" +#include "apr_thread_cond.h" + +//============================================================================ + +#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO) + +class LL_COMMON_API LLMutex +{ +public: + typedef enum + { + NO_THREAD = 0xFFFFFFFF + } e_locking_thread; + + LLMutex(apr_pool_t *apr_poolp = NULL); // NULL pool constructs a new pool for the mutex + virtual ~LLMutex(); + + void lock(); // blocks + void unlock(); + bool isLocked(); // non-blocking, but does do a lock/unlock so not free + bool isSelfLocked(); //return true if locked in a same thread + U32 lockingThread() const; //get ID of locking thread + +protected: + apr_thread_mutex_t *mAPRMutexp; + mutable U32 mCount; + mutable U32 mLockingThread; + + apr_pool_t *mAPRPoolp; + BOOL mIsLocalPool; + +#if MUTEX_DEBUG + std::map mIsLocked; +#endif +}; + +// Actually a condition/mutex pair (since each condition needs to be associated with a mutex). +class LL_COMMON_API LLCondition : public LLMutex +{ +public: + LLCondition(apr_pool_t *apr_poolp); // Defaults to global pool, could use the thread pool as well. + ~LLCondition(); + + void wait(); // blocks + void signal(); + void broadcast(); + +protected: + apr_thread_cond_t *mAPRCondp; +}; + +class LLMutexLock +{ +public: + LLMutexLock(LLMutex* mutex) + { + mMutex = mutex; + + if(mMutex) + mMutex->lock(); + } + ~LLMutexLock() + { + if(mMutex) + mMutex->unlock(); + } +private: + LLMutex* mMutex; +}; + + +//============================================================================ + +// 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; + +private: + LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented + LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented + +protected: + virtual ~LLThreadSafeRefCount(); // use unref() + +public: + LLThreadSafeRefCount(); + + 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; +}; + + +//============================================================================ + +// Simple responder for self destructing callbacks +// Pure virtual class +class LL_COMMON_API LLResponder : public LLThreadSafeRefCount +{ +protected: + virtual ~LLResponder(); +public: + virtual void completed(bool success) = 0; +}; + + +#endif // LL_LLTHREAD_H diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index a6ad6b125c..f3ab8aa40c 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -29,6 +29,7 @@ #include "apr_portable.h" #include "llthread.h" +#include "llmutex.h" #include "lltimer.h" @@ -56,12 +57,20 @@ // //---------------------------------------------------------------------------- -#if !LL_DARWIN -U32 ll_thread_local sThreadID = 0; -#endif +#if LL_DARWIN +// statically allocated thread local storage not supported in Darwin executable formats +#elif LL_WINDOWS +U32 __declspec(thread) LLThread::sThreadIndex = 0; +#elif LL_LINUX +U32 __thread LLThread::sThreadID = 0; +#endif U32 LLThread::sIDIter = 0; +LLTrace::MasterThreadTrace gMasterThreadTrace; +LLThreadLocalPtr LLThread::sTraceData(&gMasterThreadTrace); + + LL_COMMON_API void assert_main_thread() { static U32 s_thread_id = LLThread::currentID(); @@ -78,8 +87,10 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; + sTraceData = new LLTrace::SlaveThreadTrace(gMasterThreadTrace); + #if !LL_DARWIN - sThreadID = threadp->mID; + sThreadIndex = threadp->mID; #endif // Run the user supplied function @@ -93,7 +104,6 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap return NULL; } - LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : mPaused(FALSE), mName(name), @@ -301,198 +311,12 @@ void LLThread::wakeLocked() } } -//============================================================================ - -LLMutex::LLMutex(apr_pool_t *poolp) : - mAPRMutexp(NULL), mCount(0), mLockingThread(NO_THREAD) -{ - //if (poolp) - //{ - // mIsLocalPool = FALSE; - // mAPRPoolp = poolp; - //} - //else - { - mIsLocalPool = TRUE; - apr_pool_create(&mAPRPoolp, NULL); // Create a subpool for this thread - } - apr_thread_mutex_create(&mAPRMutexp, APR_THREAD_MUTEX_UNNESTED, mAPRPoolp); -} - - -LLMutex::~LLMutex() -{ -#if MUTEX_DEBUG - //bad assertion, the subclass LLSignal might be "locked", and that's OK - //llassert_always(!isLocked()); // better not be locked! -#endif - apr_thread_mutex_destroy(mAPRMutexp); - mAPRMutexp = NULL; - if (mIsLocalPool) - { - apr_pool_destroy(mAPRPoolp); - } -} - - -void LLMutex::lock() -{ - if(isSelfLocked()) - { //redundant lock - mCount++; - return; - } - - apr_thread_mutex_lock(mAPRMutexp); - -#if MUTEX_DEBUG - // Have to have the lock before we can access the debug info - U32 id = LLThread::currentID(); - if (mIsLocked[id] != FALSE) - llerrs << "Already locked in Thread: " << id << llendl; - mIsLocked[id] = TRUE; -#endif - -#if LL_DARWIN - mLockingThread = LLThread::currentID(); -#else - mLockingThread = sThreadID; -#endif -} - -void LLMutex::unlock() -{ - if (mCount > 0) - { //not the root unlock - mCount--; - return; - } - -#if MUTEX_DEBUG - // Access the debug info while we have the lock - U32 id = LLThread::currentID(); - if (mIsLocked[id] != TRUE) - llerrs << "Not locked in Thread: " << id << llendl; - mIsLocked[id] = FALSE; -#endif - - mLockingThread = NO_THREAD; - apr_thread_mutex_unlock(mAPRMutexp); -} - -bool LLMutex::isLocked() -{ - apr_status_t status = apr_thread_mutex_trylock(mAPRMutexp); - if (APR_STATUS_IS_EBUSY(status)) - { - return true; - } - else - { - apr_thread_mutex_unlock(mAPRMutexp); - return false; - } -} - -bool LLMutex::isSelfLocked() -{ -#if LL_DARWIN - return mLockingThread == LLThread::currentID(); -#else - return mLockingThread == sThreadID; -#endif -} - -U32 LLMutex::lockingThread() const -{ - return mLockingThread; -} - -//============================================================================ - -LLCondition::LLCondition(apr_pool_t *poolp) : - LLMutex(poolp) -{ - // base class (LLMutex) has already ensured that mAPRPoolp is set up. - - apr_thread_cond_create(&mAPRCondp, mAPRPoolp); -} - - -LLCondition::~LLCondition() -{ - apr_thread_cond_destroy(mAPRCondp); - mAPRCondp = NULL; -} - - -void LLCondition::wait() -{ - if (!isLocked()) - { //mAPRMutexp MUST be locked before calling apr_thread_cond_wait - apr_thread_mutex_lock(mAPRMutexp); -#if MUTEX_DEBUG - // avoid asserts on destruction in non-release builds - U32 id = LLThread::currentID(); - mIsLocked[id] = TRUE; -#endif - } - apr_thread_cond_wait(mAPRCondp, mAPRMutexp); -} - -void LLCondition::signal() -{ - apr_thread_cond_signal(mAPRCondp); -} - -void LLCondition::broadcast() -{ - apr_thread_cond_broadcast(mAPRCondp); -} - -//============================================================================ - -//---------------------------------------------------------------------------- - -//static -LLMutex* LLThreadSafeRefCount::sMutex = 0; - -//static -void LLThreadSafeRefCount::initThreadSafeRefCount() -{ - if (!sMutex) - { - sMutex = new LLMutex(0); - } -} - -//static -void LLThreadSafeRefCount::cleanupThreadSafeRefCount() +void LLThread::lockData() { - delete sMutex; - sMutex = NULL; -} - - -//---------------------------------------------------------------------------- - -LLThreadSafeRefCount::LLThreadSafeRefCount() : - mRef(0) -{ -} - -LLThreadSafeRefCount::~LLThreadSafeRefCount() -{ - if (mRef != 0) - { - llerrs << "deleting non-zero reference" << llendl; - } + mRunCondition->lock(); } -//============================================================================ - -LLResponder::~LLResponder() +void LLThread::unlockData() { + mRunCondition->unlock(); } - -//============================================================================ diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index b52e70ab2e..e2de4c8b85 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -30,21 +30,21 @@ #include "llapp.h" #include "llapr.h" #include "apr_thread_cond.h" - -class LLThread; -class LLMutex; -class LLCondition; - -#if LL_WINDOWS -#define ll_thread_local __declspec(thread) -#else -#define ll_thread_local __thread -#endif +#include "lltrace.h" +#include "llthreadlocalptr.h" class LL_COMMON_API LLThread { private: + friend class LLMutex; static U32 sIDIter; +#if LL_DARWIN + // statically allocated thread local storage not supported in Darwin executable formats +#elif LL_WINDOWS + static U32 __declspec(thread) LLThread::sThreadIndex; +#elif LL_LINUX + static U32 __thread LLThread::sThreadID ; +#endif public: typedef enum e_thread_status @@ -88,6 +88,8 @@ public: U32 getID() const { return mID; } + static LLTrace::ThreadTraceData* getTraceData() { return sTraceData.get(); } + private: BOOL mPaused; @@ -96,7 +98,7 @@ private: protected: std::string mName; - LLCondition* mRunCondition; + class LLCondition* mRunCondition; apr_thread_t *mAPRThreadp; apr_pool_t *mAPRPoolp; @@ -104,6 +106,8 @@ protected: EThreadStatus mStatus; U32 mID; + static LLThreadLocalPtr sTraceData; + //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. // otherwise it will cause severe memory leaking!!! --bao @@ -135,149 +139,4 @@ protected: //============================================================================ -#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO) - -class LL_COMMON_API LLMutex -{ -public: - typedef enum - { - NO_THREAD = 0xFFFFFFFF - } e_locking_thread; - - LLMutex(apr_pool_t *apr_poolp); // NULL pool constructs a new pool for the mutex - virtual ~LLMutex(); - - void lock(); // blocks - void unlock(); - bool isLocked(); // non-blocking, but does do a lock/unlock so not free - bool isSelfLocked(); //return true if locked in a same thread - U32 lockingThread() const; //get ID of locking thread - -protected: - apr_thread_mutex_t *mAPRMutexp; - mutable U32 mCount; - mutable U32 mLockingThread; - - apr_pool_t *mAPRPoolp; - BOOL mIsLocalPool; - -#if MUTEX_DEBUG - std::map mIsLocked; -#endif -}; - -// Actually a condition/mutex pair (since each condition needs to be associated with a mutex). -class LL_COMMON_API LLCondition : public LLMutex -{ -public: - LLCondition(apr_pool_t *apr_poolp); // Defaults to global pool, could use the thread pool as well. - ~LLCondition(); - - void wait(); // blocks - void signal(); - void broadcast(); - -protected: - apr_thread_cond_t *mAPRCondp; -}; - -class LLMutexLock -{ -public: - LLMutexLock(LLMutex* mutex) - { - mMutex = mutex; - - if(mMutex) - mMutex->lock(); - } - ~LLMutexLock() - { - if(mMutex) - mMutex->unlock(); - } -private: - LLMutex* mMutex; -}; - -//============================================================================ - -void LLThread::lockData() -{ - mRunCondition->lock(); -} - -void LLThread::unlockData() -{ - mRunCondition->unlock(); -} - - -//============================================================================ - -// 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; - -private: - LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented - LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented - -protected: - virtual ~LLThreadSafeRefCount(); // use unref() - -public: - LLThreadSafeRefCount(); - - 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; -}; - -//============================================================================ - -// Simple responder for self destructing callbacks -// Pure virtual class -class LL_COMMON_API LLResponder : public LLThreadSafeRefCount -{ -protected: - virtual ~LLResponder(); -public: - virtual void completed(bool success) = 0; -}; - -//============================================================================ - #endif // LL_LLTHREAD_H diff --git a/indra/llcommon/llthreadlocalptr.h b/indra/llcommon/llthreadlocalptr.h new file mode 100644 index 0000000000..f02f4849ca --- /dev/null +++ b/indra/llcommon/llthreadlocalptr.h @@ -0,0 +1,141 @@ +/** + * @file llthreadlocalptr.h + * @brief manage thread local storage through non-copyable pointer + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTHREAD_LOCAL_PTR_H +#define LL_LLTHREAD_LOCAL_PTR_H + +#include "llapr.h" + +template +class LLThreadLocalPtr +{ +public: + LLThreadLocalPtr(T* value = NULL, apr_pool_t* pool = NULL) + { + apr_status_t result = apr_threadkey_private_create(&mThreadKey, cleanup, pool); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to allocate thread local data" << llendl; + } + set(value); + } + + + ~LLThreadLocalPtr() + { + apr_status_t result = apr_threadkey_private_delete(mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to delete thread local data" << llendl; + } + } + + T* operator -> () + { + return get(); + } + + const T* operator -> () const + { + return get(); + } + + T& operator*() + { + return *get(); + } + + const T& operator*() const + { + return *get(); + } + + LLThreadLocalPtr& operator = (T* value) + { + set(value); + return *this; + } + + void copyFrom(const LLThreadLocalPtr& other) + { + set(other.get()); + } + + LL_FORCE_INLINE void set(T* value) + { + apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to set thread local data" << llendl; + } + } + + LL_FORCE_INLINE T* get() + { + T* ptr; + //apr_status_t result = + apr_threadkey_private_get((void**)&ptr, mThreadKey); + //if (result != APR_SUCCESS) + //{ + // ll_apr_warn_status(s); + // llerrs << "Failed to get thread local data" << llendl; + //} + return ptr; + } + + LL_FORCE_INLINE const T* get() const + { + T* ptr; + //apr_status_t result = + apr_threadkey_private_get((void**)&ptr, mThreadKey); + //if (result != APR_SUCCESS) + //{ + // ll_apr_warn_status(s); + // llerrs << "Failed to get thread local data" << llendl; + //} + return ptr; + } + + +private: + static void cleanup(void* ptr) + { + delete reinterpret_cast(ptr); + } + + LLThreadLocalPtr(const LLThreadLocalPtr& other) + { + // do not copy construct + llassert(false); + } + + apr_threadkey_t* mThreadKey; +}; + +#endif // LL_LLTHREAD_LOCAL_PTR_H diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp new file mode 100644 index 0000000000..037c52f8c1 --- /dev/null +++ b/indra/llcommon/lltrace.cpp @@ -0,0 +1,95 @@ +/** + * @file lltrace.cpp + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltrace.h" +#include "llthread.h" + +namespace LLTrace +{ + +BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; +LLThreadLocalPtr ThreadTraceData::sCurThreadTrace; + +/////////////////////////////////////////////////////////////////////// +// Sampler +/////////////////////////////////////////////////////////////////////// + +void Sampler::stop() +{ + getThreadTrace()->deactivate(this); +} + +void Sampler::resume() +{ + getThreadTrace()->activate(this); +} + +class ThreadTraceData* Sampler::getThreadTrace() +{ + return LLThread::getTraceData(); +} + +/////////////////////////////////////////////////////////////////////// +// MasterThreadTrace +/////////////////////////////////////////////////////////////////////// + +void MasterThreadTrace::pullFromWorkerThreads() +{ + LLMutexLock lock(&mSlaveListMutex); + + for (worker_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + it != end_it; + ++it) + { + it->mWorkerTrace->mSharedData.copyTo(it->mSamplerStorage); + } +} + +void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) +{ + LLMutexLock lock(&mSlaveListMutex); + + mSlaveThreadTraces.push_back(WorkerThreadTraceProxy(child)); +} + +void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) +{ + LLMutexLock lock(&mSlaveListMutex); + + for (worker_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + it != end_it; + ++it) + { + if (it->mWorkerTrace == child) + { + mSlaveThreadTraces.erase(it); + break; + } + } +} + +} diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 7da182df1e..401ddfd6f3 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -30,25 +30,27 @@ #include "stdtypes.h" #include "llpreprocessor.h" -#include "llthread.h" +#include "llmutex.h" +#include "llmemory.h" +#include "llthreadlocalptr.h" #include +#define TOKEN_PASTE_ACTUAL(x, y) x##y +#define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) +#define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); + namespace LLTrace { - // one per thread per type template - struct AccumulatorBuffer : public AccumulatorBufferBase + class AccumulatorBuffer { - ACCUMULATOR* mStorage; - size_t mStorageSize; - size_t mNextStorageSlot; - static S32 sStorageKey; // key used to access thread local storage pointer to accumulator values - + static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; + public: AccumulatorBuffer() : mStorageSize(64), - mStorage(new ACCUMULATOR[64]), + mStorage(new ACCUMULATOR[DEFAULT_ACCUMULATOR_BUFFER_SIZE]), mNextStorageSlot(0) {} @@ -56,12 +58,13 @@ namespace LLTrace : mStorageSize(other.mStorageSize), mStorage(new ACCUMULATOR[other.mStorageSize]), mNextStorageSlot(other.mNextStorageSlot) - { + {} + LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) + { + return mStorage[index]; } - LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) { return (*mStorage)[index]; } - void mergeFrom(const AccumulatorBuffer& other) { llassert(mNextStorageSlot == other.mNextStorageSlot); @@ -72,7 +75,7 @@ namespace LLTrace } } - void copyFrom(const AccumulatorBuffer& other) + void copyFrom(const AccumulatorBuffer& other) { for (size_t i = 0; i < mNextStorageSlot; i++) { @@ -90,7 +93,12 @@ namespace LLTrace void makePrimary() { - //TODO: use sStorageKey to set mStorage as active buffer + sPrimaryStorage = mStorage; + } + + LL_FORCE_INLINE static ACCUMULATOR* getPrimaryStorage() + { + return sPrimaryStorage.get(); } // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned @@ -101,14 +109,29 @@ namespace LLTrace { size_t new_size = mStorageSize + (mStorageSize >> 2); delete [] mStorage; - mStorage = new mStorage(new_size); + mStorage = new ACCUMULATOR[new_size]; mStorageSize = new_size; } llassert(next_slot < mStorageSize); return next_slot; } + + private: + ACCUMULATOR* mStorage; + size_t mStorageSize; + size_t mNextStorageSlot; + static LLThreadLocalPtr sPrimaryStorage; + }; + template LLThreadLocalPtr AccumulatorBuffer::sPrimaryStorage; + + template + class PrimaryAccumulatorBuffer : public AccumulatorBuffer S32 AccumulatorBuffer::sStorageKey; template class Trace @@ -117,32 +140,34 @@ namespace LLTrace Trace(const std::string& name) : mName(name) { - mAccumulatorIndex = sAccumulatorBuffer.reserveSlot(); + mAccumulatorIndex = getPrimaryBuffer().reserveSlot(); } LL_FORCE_INLINE ACCUMULATOR& getAccumulator() { - return sAccumulatorBuffer[mAccumulatorIndex]; + return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; + } + + static PrimaryAccumulatorBuffer& getPrimaryBuffer() + { + static PrimaryAccumulatorBuffer sBuffer; + return sBuffer; } private: std::string mName; size_t mAccumulatorIndex; - - // this needs to be thread local - static AccumulatorBuffer sAccumulatorBuffer; }; - template std::vector Trace::sAccumulatorBuffer; template class StatAccumulator { public: StatAccumulator() - : mSum(), - mMin(), - mMax(), + : mSum(0), + mMin(0), + mMax(0), mNumSamples(0) {} @@ -160,7 +185,7 @@ namespace LLTrace } } - void mergeFrom(const Stat& other) + void mergeFrom(const StatAccumulator& other) { mSum += other.mSum; if (other.mMin < mMin) @@ -318,21 +343,13 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; - BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; - class Sampler { public: - Sampler(const Sampler& other) - : mF32Stats(other.mF32Stats), - mS32Stats(other.mS32Stats), - mTimers(other.mTimers) - {} + Sampler() {} + Sampler(const Sampler& other); - ~Sampler() - { - stop(); - } + ~Sampler(); void makePrimary() { @@ -347,17 +364,8 @@ namespace LLTrace resume(); } - void stop() - { - getThreadTracer()->deactivate(this); - } - - void resume() - { - ThreadTracer* thread_data = getThreadTracer(); - thread_data->flushData(); - thread_data->activate(this); - } + void stop(); + void resume(); void mergeFrom(const Sampler& other) { @@ -375,7 +383,7 @@ namespace LLTrace private: // returns data for current thread - struct ThreadTracer* getThreadTracer() { return NULL; } + class ThreadTraceData* getThreadTrace(); AccumulatorBuffer > mF32Stats; AccumulatorBuffer > mS32Stats; @@ -383,39 +391,39 @@ namespace LLTrace AccumulatorBuffer mTimers; }; - struct ThreadTracer + class ThreadTraceData { - ThreadTracer(LLThread& this_thread, ThreadTracer& parent_data) - : mPrimarySampler(parent_data.mPrimarySampler), - mSharedSampler(parent_data.mSharedSampler), - mSharedSamplerMutex(this_thread.getAPRPool()), - mParent(parent_data) + public: + ThreadTraceData() { mPrimarySampler.makePrimary(); - parent_data.addChildThread(this); } - ~ThreadTracer() + ThreadTraceData(const ThreadTraceData& other) + : mPrimarySampler(other.mPrimarySampler) { - mParent.removeChildThread(this); + mPrimarySampler.makePrimary(); } - void addChildThread(ThreadTracer* child) + void activate(Sampler* sampler) { - mChildThreadTracers.push_back(child); + flushPrimary(); + mActiveSamplers.push_back(sampler); } - void removeChildThread(ThreadTracer* child) + void deactivate(Sampler* sampler) { + sampler->mergeFrom(mPrimarySampler); + // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mChildThreadTracers.begin(), mChildThreadTracers.end(), child); - if (found_it != mChildThreadTracers.end()) + std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); + if (found_it != mActiveSamplers.end()) { - mChildThreadTracers.erase(found_it); + mActiveSamplers.erase(found_it); } } - void flushData() + void flushPrimary() { for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); it != end_it; @@ -426,56 +434,96 @@ namespace LLTrace mPrimarySampler.reset(); } - void activate(Sampler* sampler) + Sampler* getPrimarySampler() { return &mPrimarySampler; } + protected: + Sampler mPrimarySampler; + std::list mActiveSamplers; + static LLThreadLocalPtr sCurThreadTrace; + }; + + class MasterThreadTrace : public ThreadTraceData + { + public: + MasterThreadTrace() + {} + + void addSlaveThread(class SlaveThreadTrace* child); + void removeSlaveThread(class SlaveThreadTrace* child); + + // call this periodically to gather stats data from worker threads + void pullFromWorkerThreads(); + + private: + struct WorkerThreadTraceProxy { - mActiveSamplers.push_back(sampler); + WorkerThreadTraceProxy(class SlaveThreadTrace* trace) + : mWorkerTrace(trace) + {} + class SlaveThreadTrace* mWorkerTrace; + Sampler mSamplerStorage; + }; + typedef std::list worker_thread_trace_list_t; + + worker_thread_trace_list_t mSlaveThreadTraces; + LLMutex mSlaveListMutex; + }; + + class SlaveThreadTrace : public ThreadTraceData + { + public: + explicit + SlaveThreadTrace(MasterThreadTrace& master_trace) + : mMaster(master_trace), + ThreadTraceData(master_trace), + mSharedData(mPrimarySampler) + { + master_trace.addSlaveThread(this); } - void deactivate(Sampler* sampler) + ~SlaveThreadTrace() { - // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); - if (found_it != mActiveSamplers.end()) - { - mActiveSamplers.erase(found_it); - } + mMaster.removeSlaveThread(this); } - - // call this periodically to gather stats data in parent thread - void publishToParent() + + // call this periodically to gather stats data for master thread to consume + void pushToParent() { - mSharedSamplerMutex.lock(); - { - mSharedSampler.mergeFrom(mPrimarySampler); - } - mSharedSamplerMutex.unlock(); + mSharedData.copyFrom(mPrimarySampler); } - // call this periodically to gather stats data from children - void gatherChildData() + MasterThreadTrace& mMaster; + + // this data is accessed by other threads, so give it a 64 byte alignment + // to avoid false sharing on most x86 processors + LL_ALIGNED(64) class SharedData { - for (std::list::iterator child_it = mChildThreadTracers.begin(), end_it = mChildThreadTracers.end(); - child_it != end_it; - ++child_it) + public: + explicit + SharedData(const Sampler& other_sampler) + : mSampler(other_sampler) + {} + + void copyFrom(Sampler& source) { - (*child_it)->mSharedSamplerMutex.lock(); - { - //TODO for now, just aggregate, later keep track of thread data independently - mPrimarySampler.mergeFrom((*child_it)->mSharedSampler); + LLMutexLock lock(&mSamplerMutex); + { + mSampler.mergeFrom(source); } - (*child_it)->mSharedSamplerMutex.unlock(); } - } - Sampler mPrimarySampler; - - ThreadTracer& mParent; - std::list mActiveSamplers; - std::list mChildThreadTracers; - - // TODO: add unused space here to avoid false sharing? - LLMutex mSharedSamplerMutex; - Sampler mSharedSampler; + void copyTo(Sampler& sink) + { + LLMutexLock lock(&mSamplerMutex); + { + sink.mergeFrom(mSampler); + } + } + private: + // add a cache line's worth of unused space to avoid any potential of false sharing + LLMutex mSamplerMutex; + Sampler mSampler; + }; + SharedData mSharedData; }; @@ -486,19 +534,6 @@ namespace LLTrace void stop() {} void resume() {} }; - - class Sampler - { - public: - void start() {} - void stop() {} - void resume() {} - }; - } -#define TOKEN_PASTE_ACTUAL(x, y) x##y -#define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) -#define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); - #endif // LL_LLTRACE_H -- cgit v1.2.3 From adeeabfc13c91dc99a1ea1949cd2f820c4150995 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 24 Sep 2012 18:56:01 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages moved LLThreadLocalPtr to llapr fixed various startup race conditions for LLThreadLocalPtr --- indra/llcommon/CMakeLists.txt | 1 - indra/llcommon/llapr.cpp | 82 ++++++++++++++++++++++ indra/llcommon/llapr.h | 117 +++++++++++++++++++++++++++++++ indra/llcommon/llcommon.cpp | 2 + indra/llcommon/llthread.cpp | 8 +-- indra/llcommon/llthread.h | 1 - indra/llcommon/llthreadlocalptr.h | 141 -------------------------------------- indra/llcommon/lltrace.cpp | 16 ++++- indra/llcommon/lltrace.h | 57 +++++++-------- 9 files changed, 249 insertions(+), 176 deletions(-) delete mode 100644 indra/llcommon/llthreadlocalptr.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index eec2695dde..f78751601c 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -240,7 +240,6 @@ set(llcommon_HEADER_FILES llstringtable.h llsys.h llthread.h - llthreadlocalptr.h llthreadsafequeue.h lltimer.h lltrace.h diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index d1c44c9403..76749f8a91 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -54,6 +54,8 @@ void ll_init_apr() { LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ; } + + LLThreadLocalPtrBase::initAllThreadLocalStorage(); } @@ -476,6 +478,86 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) return LLAPRFile::seek(mFile, where, offset) ; } +// +//LLThreadLocalPtrBase +// +bool LLThreadLocalPtrBase::sInitialized = false; + +LLThreadLocalPtrBase::LLThreadLocalPtrBase(void (*cleanup_func)(void*)) +: mCleanupFunc(cleanup_func), + mThreadKey(NULL) +{ + if (sInitialized) + { + initStorage(); + } +} + +LLThreadLocalPtrBase::LLThreadLocalPtrBase( const LLThreadLocalPtrBase& other) +: mCleanupFunc(other.mCleanupFunc), + mThreadKey(NULL) +{ + if (sInitialized) + { + initStorage(); + } +} + +LLThreadLocalPtrBase::~LLThreadLocalPtrBase() +{ + destroyStorage(); +} + +void LLThreadLocalPtrBase::set( void* value ) +{ + llassert(sInitialized && mThreadKey); + + apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to set thread local data" << llendl; + } +} + +void LLThreadLocalPtrBase::initStorage( ) +{ + apr_status_t result = apr_threadkey_private_create(&mThreadKey, mCleanupFunc, gAPRPoolp); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to allocate thread local data" << llendl; + } +} + +void LLThreadLocalPtrBase::destroyStorage() +{ + if (mThreadKey) + { + apr_status_t result = apr_threadkey_private_delete(mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to delete thread local data" << llendl; + } + } +} + +void LLThreadLocalPtrBase::initAllThreadLocalStorage() +{ + if (!sInitialized) + { + sInitialized = true; + for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + it != end_it; + ++it) + { + (*it).initStorage(); + } + } +} + + // //******************************************************************************************************************************* //static components of LLAPRFile diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index af33ce666f..eb0bf627a0 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -49,6 +49,7 @@ #include "apr_signal.h" #include "apr_atomic.h" #include "llstring.h" +#include "llinstancetracker.h" extern LL_COMMON_API apr_thread_mutex_t* gLogMutexp; extern apr_thread_mutex_t* gCallStacksLogMutexp; @@ -255,6 +256,122 @@ public: //******************************************************************************************************************************* }; +class LLThreadLocalPtrBase : LLInstanceTracker +{ +public: + LLThreadLocalPtrBase(void (*cleanup_func)(void*) ); + LLThreadLocalPtrBase(const LLThreadLocalPtrBase& other); + ~LLThreadLocalPtrBase(); + +protected: + friend void LL_COMMON_API ll_init_apr(); + void set(void* value); + + LL_FORCE_INLINE void* get() + { + void* ptr; + //apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + //if (result != APR_SUCCESS) + //{ + // ll_apr_warn_status(s); + // llerrs << "Failed to get thread local data" << llendl; + //} + return ptr; + } + + LL_FORCE_INLINE const void* get() const + { + void* ptr; + //apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + //if (result != APR_SUCCESS) + //{ + // ll_apr_warn_status(s); + // llerrs << "Failed to get thread local data" << llendl; + //} + return ptr; + } + + void initStorage(); + + void destroyStorage(); + + static void initAllThreadLocalStorage(); + +private: + void (*mCleanupFunc)(void*); + apr_threadkey_t* mThreadKey; + static bool sInitialized; +}; + +template +class LLThreadLocalPtr : public LLThreadLocalPtrBase +{ +public: + + LLThreadLocalPtr() + : LLThreadLocalPtrBase(&cleanup) + {} + + LLThreadLocalPtr(T* value) + : LLThreadLocalPtrBase(&cleanup) + { + set(value); + } + + + LLThreadLocalPtr(const LLThreadLocalPtr& other) + : LLThreadLocalPtrBase(other, &cleanup) + { + set(other.get()); + } + + T* get() + { + return (T*)LLThreadLocalPtrBase::get(); + } + + const T* get() const + { + return (const T*)LLThreadLocalPtrBase::get(); + } + + T* operator -> () + { + return (T*)get(); + } + + const T* operator -> () const + { + return (T*)get(); + } + + T& operator*() + { + return *(T*)get(); + } + + const T& operator*() const + { + return *(T*)get(); + } + + LLThreadLocalPtr& operator = (T* value) + { + set((void*)value); + return *this; + } + +private: + + static void cleanup(void* ptr) + { + delete reinterpret_cast(ptr); + } + +}; + /** * @brief Function which appropriately logs error or remains quiet on * APR_SUCCESS. diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 8be9e4f4de..512e7da840 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -44,6 +44,7 @@ void LLCommon::initClass() } LLTimer::initClass(); LLThreadSafeRefCount::initThreadSafeRefCount(); + LLTrace::init(); // LLWorkerThread::initClass(); // LLFrameCallbackManager::initClass(); } @@ -61,4 +62,5 @@ void LLCommon::cleanupClass() sAprInitialized = FALSE; } LLMemory::cleanupClass(); + LLTrace::cleanup(); } diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index f3ab8aa40c..023004eedd 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -66,9 +66,7 @@ U32 __thread LLThread::sThreadID = 0; #endif U32 LLThread::sIDIter = 0; - -LLTrace::MasterThreadTrace gMasterThreadTrace; -LLThreadLocalPtr LLThread::sTraceData(&gMasterThreadTrace); +LLThreadLocalPtr LLThread::sTraceData; LL_COMMON_API void assert_main_thread() @@ -87,7 +85,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; - sTraceData = new LLTrace::SlaveThreadTrace(gMasterThreadTrace); + sTraceData = new LLTrace::SlaveThreadTrace(); #if !LL_DARWIN sThreadIndex = threadp->mID; @@ -155,7 +153,7 @@ void LLThread::shutdown() //llinfos << "LLThread::~LLThread() Killing thread " << mName << " Status: " << mStatus << llendl; // Now wait a bit for the thread to exit // It's unclear whether I should even bother doing this - this destructor - // should netver get called unless we're already stopped, really... + // should never get called unless we're already stopped, really... S32 counter = 0; const S32 MAX_WAIT = 600; while (counter < MAX_WAIT) diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index e2de4c8b85..e50fa7653d 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -31,7 +31,6 @@ #include "llapr.h" #include "apr_thread_cond.h" #include "lltrace.h" -#include "llthreadlocalptr.h" class LL_COMMON_API LLThread { diff --git a/indra/llcommon/llthreadlocalptr.h b/indra/llcommon/llthreadlocalptr.h deleted file mode 100644 index f02f4849ca..0000000000 --- a/indra/llcommon/llthreadlocalptr.h +++ /dev/null @@ -1,141 +0,0 @@ -/** - * @file llthreadlocalptr.h - * @brief manage thread local storage through non-copyable pointer - * - * $LicenseInfo:firstyear=2004&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLTHREAD_LOCAL_PTR_H -#define LL_LLTHREAD_LOCAL_PTR_H - -#include "llapr.h" - -template -class LLThreadLocalPtr -{ -public: - LLThreadLocalPtr(T* value = NULL, apr_pool_t* pool = NULL) - { - apr_status_t result = apr_threadkey_private_create(&mThreadKey, cleanup, pool); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to allocate thread local data" << llendl; - } - set(value); - } - - - ~LLThreadLocalPtr() - { - apr_status_t result = apr_threadkey_private_delete(mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to delete thread local data" << llendl; - } - } - - T* operator -> () - { - return get(); - } - - const T* operator -> () const - { - return get(); - } - - T& operator*() - { - return *get(); - } - - const T& operator*() const - { - return *get(); - } - - LLThreadLocalPtr& operator = (T* value) - { - set(value); - return *this; - } - - void copyFrom(const LLThreadLocalPtr& other) - { - set(other.get()); - } - - LL_FORCE_INLINE void set(T* value) - { - apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to set thread local data" << llendl; - } - } - - LL_FORCE_INLINE T* get() - { - T* ptr; - //apr_status_t result = - apr_threadkey_private_get((void**)&ptr, mThreadKey); - //if (result != APR_SUCCESS) - //{ - // ll_apr_warn_status(s); - // llerrs << "Failed to get thread local data" << llendl; - //} - return ptr; - } - - LL_FORCE_INLINE const T* get() const - { - T* ptr; - //apr_status_t result = - apr_threadkey_private_get((void**)&ptr, mThreadKey); - //if (result != APR_SUCCESS) - //{ - // ll_apr_warn_status(s); - // llerrs << "Failed to get thread local data" << llendl; - //} - return ptr; - } - - -private: - static void cleanup(void* ptr) - { - delete reinterpret_cast(ptr); - } - - LLThreadLocalPtr(const LLThreadLocalPtr& other) - { - // do not copy construct - llassert(false); - } - - apr_threadkey_t* mThreadKey; -}; - -#endif // LL_LLTHREAD_LOCAL_PTR_H diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 037c52f8c1..501414ebf3 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -32,7 +32,21 @@ namespace LLTrace { BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; -LLThreadLocalPtr ThreadTraceData::sCurThreadTrace; + +MasterThreadTrace *gMasterThreadTrace = NULL; +LLThreadLocalPtr gCurThreadTrace; + +void init() +{ + gMasterThreadTrace = new MasterThreadTrace(); + gCurThreadTrace = gMasterThreadTrace; +} + +void cleanup() +{ + delete gMasterThreadTrace; +} + /////////////////////////////////////////////////////////////////////// // Sampler diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 401ddfd6f3..3af05d67f9 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -32,7 +32,6 @@ #include "llmutex.h" #include "llmemory.h" -#include "llthreadlocalptr.h" #include @@ -42,19 +41,29 @@ namespace LLTrace { + void init(); + void cleanup(); + + extern class MasterThreadTrace *gMasterThreadTrace; + extern LLThreadLocalPtr gCurThreadTrace; + // one per thread per type template class AccumulatorBuffer { static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; - public: - AccumulatorBuffer() + private: + enum StaticAllocationMarker { STATIC_ALLOC }; + + AccumulatorBuffer(StaticAllocationMarker m) : mStorageSize(64), - mStorage(new ACCUMULATOR[DEFAULT_ACCUMULATOR_BUFFER_SIZE]), - mNextStorageSlot(0) - {} + mNextStorageSlot(0), + mStorage(new ACCUMULATOR[DEFAULT_ACCUMULATOR_BUFFER_SIZE]) + { + } + public: - AccumulatorBuffer(const AccumulatorBuffer& other) + AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) : mStorageSize(other.mStorageSize), mStorage(new ACCUMULATOR[other.mStorageSize]), mNextStorageSlot(other.mNextStorageSlot) @@ -116,6 +125,12 @@ namespace LLTrace return next_slot; } + static AccumulatorBuffer& getDefaultBuffer() + { + static AccumulatorBuffer sBuffer; + return sBuffer; + } + private: ACCUMULATOR* mStorage; size_t mStorageSize; @@ -124,15 +139,6 @@ namespace LLTrace }; template LLThreadLocalPtr AccumulatorBuffer::sPrimaryStorage; - template - class PrimaryAccumulatorBuffer : public AccumulatorBuffer class Trace { @@ -140,7 +146,7 @@ namespace LLTrace Trace(const std::string& name) : mName(name) { - mAccumulatorIndex = getPrimaryBuffer().reserveSlot(); + mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } LL_FORCE_INLINE ACCUMULATOR& getAccumulator() @@ -148,12 +154,6 @@ namespace LLTrace return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; } - static PrimaryAccumulatorBuffer& getPrimaryBuffer() - { - static PrimaryAccumulatorBuffer sBuffer; - return sBuffer; - } - private: std::string mName; size_t mAccumulatorIndex; @@ -347,9 +347,13 @@ namespace LLTrace { public: Sampler() {} - Sampler(const Sampler& other); + Sampler(const Sampler& other) + : mF32Stats(other.mF32Stats), + mS32Stats(other.mS32Stats), + mTimers(other.mTimers) + {} - ~Sampler(); + ~Sampler() {} void makePrimary() { @@ -438,7 +442,6 @@ namespace LLTrace protected: Sampler mPrimarySampler; std::list mActiveSamplers; - static LLThreadLocalPtr sCurThreadTrace; }; class MasterThreadTrace : public ThreadTraceData @@ -472,7 +475,7 @@ namespace LLTrace { public: explicit - SlaveThreadTrace(MasterThreadTrace& master_trace) + SlaveThreadTrace(MasterThreadTrace& master_trace = *gMasterThreadTrace) : mMaster(master_trace), ThreadTraceData(master_trace), mSharedData(mPrimarySampler) -- cgit v1.2.3 From 308ff886c3ab2aa561477921bc0d92e1bd7d399a Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 24 Sep 2012 19:01:48 -0700 Subject: fixed build moved LLThread::lockData and unlockData back to header --- indra/llcommon/llthread.cpp | 10 ---------- indra/llcommon/llthread.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 023004eedd..de1f0801a1 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -308,13 +308,3 @@ void LLThread::wakeLocked() mRunCondition->signal(); } } - -void LLThread::lockData() -{ - mRunCondition->lock(); -} - -void LLThread::unlockData() -{ - mRunCondition->unlock(); -} diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index e50fa7653d..fed111b0e4 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -136,6 +136,18 @@ protected: // mRunCondition->unlock(); }; + +void LLThread::lockData() +{ + mRunCondition->lock(); +} + +void LLThread::unlockData() +{ + mRunCondition->unlock(); +} + + //============================================================================ #endif // LL_LLTHREAD_H -- cgit v1.2.3 From 05a3203d8274a0a0999faad128f629614b8d62c5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 26 Sep 2012 17:04:57 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages fixed various issues related to unit tests and LLThreadLocalPtr initialization and teardown --- indra/llcommon/llapr.cpp | 45 +++++++++++++++++++++++++++++-------------- indra/llcommon/llapr.h | 27 ++++++++++++-------------- indra/llcommon/llcommon.cpp | 6 +----- indra/llcommon/llthread.cpp | 5 ++++- indra/llcommon/llthread.h | 2 +- indra/llcommon/lltrace.cpp | 33 ++++++++++++++++++++----------- indra/llcommon/lltrace.h | 47 ++++++++++++++++++++++++++------------------- 7 files changed, 98 insertions(+), 67 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 76749f8a91..e9930c10f7 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -52,7 +52,7 @@ void ll_init_apr() if(!LLAPRFile::sAPRFilePoolp) { - LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ; + LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE); } LLThreadLocalPtrBase::initAllThreadLocalStorage(); @@ -79,6 +79,9 @@ void ll_cleanup_apr() apr_thread_mutex_destroy(gCallStacksLogMutexp); gCallStacksLogMutexp = NULL; } + + LLThreadLocalPtrBase::destroyAllThreadLocalStorage(); + if (gAPRPoolp) { apr_pool_destroy(gAPRPoolp); @@ -86,7 +89,7 @@ void ll_cleanup_apr() } if (LLAPRFile::sAPRFilePoolp) { - delete LLAPRFile::sAPRFilePoolp ; + delete LLAPRFile::sAPRFilePoolp ; LLAPRFile::sAPRFilePoolp = NULL ; } apr_terminate(); @@ -483,9 +486,8 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) // bool LLThreadLocalPtrBase::sInitialized = false; -LLThreadLocalPtrBase::LLThreadLocalPtrBase(void (*cleanup_func)(void*)) -: mCleanupFunc(cleanup_func), - mThreadKey(NULL) +LLThreadLocalPtrBase::LLThreadLocalPtrBase() +: mThreadKey(NULL) { if (sInitialized) { @@ -494,8 +496,7 @@ LLThreadLocalPtrBase::LLThreadLocalPtrBase(void (*cleanup_func)(void*)) } LLThreadLocalPtrBase::LLThreadLocalPtrBase( const LLThreadLocalPtrBase& other) -: mCleanupFunc(other.mCleanupFunc), - mThreadKey(NULL) +: mThreadKey(NULL) { if (sInitialized) { @@ -522,7 +523,7 @@ void LLThreadLocalPtrBase::set( void* value ) void LLThreadLocalPtrBase::initStorage( ) { - apr_status_t result = apr_threadkey_private_create(&mThreadKey, mCleanupFunc, gAPRPoolp); + apr_status_t result = apr_threadkey_private_create(&mThreadKey, NULL, gAPRPoolp); if (result != APR_SUCCESS) { ll_apr_warn_status(result); @@ -532,13 +533,16 @@ void LLThreadLocalPtrBase::initStorage( ) void LLThreadLocalPtrBase::destroyStorage() { - if (mThreadKey) + if (sInitialized) { - apr_status_t result = apr_threadkey_private_delete(mThreadKey); - if (result != APR_SUCCESS) + if (mThreadKey) { - ll_apr_warn_status(result); - llerrs << "Failed to delete thread local data" << llendl; + apr_status_t result = apr_threadkey_private_delete(mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to delete thread local data" << llendl; + } } } } @@ -547,16 +551,29 @@ void LLThreadLocalPtrBase::initAllThreadLocalStorage() { if (!sInitialized) { - sInitialized = true; for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { (*it).initStorage(); } + sInitialized = true; } } +void LLThreadLocalPtrBase::destroyAllThreadLocalStorage() +{ + if (sInitialized) + { + for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + it != end_it; + ++it) + { + (*it).destroyStorage(); + } + sInitialized = false; + } +} // //******************************************************************************************************************************* diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index eb0bf627a0..830e0a33fa 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -259,16 +259,19 @@ public: class LLThreadLocalPtrBase : LLInstanceTracker { public: - LLThreadLocalPtrBase(void (*cleanup_func)(void*) ); + LLThreadLocalPtrBase(); LLThreadLocalPtrBase(const LLThreadLocalPtrBase& other); ~LLThreadLocalPtrBase(); + static void initAllThreadLocalStorage(); + static void destroyAllThreadLocalStorage(); + protected: - friend void LL_COMMON_API ll_init_apr(); void set(void* value); LL_FORCE_INLINE void* get() { + llassert(sInitialized); void* ptr; //apr_status_t result = apr_threadkey_private_get(&ptr, mThreadKey); @@ -294,13 +297,9 @@ protected: } void initStorage(); - void destroyStorage(); - static void initAllThreadLocalStorage(); - -private: - void (*mCleanupFunc)(void*); +protected: apr_threadkey_t* mThreadKey; static bool sInitialized; }; @@ -311,10 +310,10 @@ class LLThreadLocalPtr : public LLThreadLocalPtrBase public: LLThreadLocalPtr() - : LLThreadLocalPtrBase(&cleanup) + : LLThreadLocalPtrBase() {} - LLThreadLocalPtr(T* value) + explicit LLThreadLocalPtr(T* value) : LLThreadLocalPtrBase(&cleanup) { set(value); @@ -327,7 +326,7 @@ public: set(other.get()); } - T* get() + LL_FORCE_INLINE T* get() { return (T*)LLThreadLocalPtrBase::get(); } @@ -363,13 +362,11 @@ public: return *this; } -private: - - static void cleanup(void* ptr) + bool operator ==(T* other) { - delete reinterpret_cast(ptr); + if (!sInitialized) return false; + return get() == other; } - }; /** diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index 512e7da840..c149a1fe5c 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -45,15 +45,12 @@ void LLCommon::initClass() LLTimer::initClass(); LLThreadSafeRefCount::initThreadSafeRefCount(); LLTrace::init(); -// LLWorkerThread::initClass(); -// LLFrameCallbackManager::initClass(); } //static void LLCommon::cleanupClass() { -// LLFrameCallbackManager::cleanupClass(); -// LLWorkerThread::cleanupClass(); + LLTrace::cleanup(); LLThreadSafeRefCount::cleanupThreadSafeRefCount(); LLTimer::cleanupClass(); if (sAprInitialized) @@ -62,5 +59,4 @@ void LLCommon::cleanupClass() sAprInitialized = FALSE; } LLMemory::cleanupClass(); - LLTrace::cleanup(); } diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index de1f0801a1..2e6eb085dc 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -66,7 +66,7 @@ U32 __thread LLThread::sThreadID = 0; #endif U32 LLThread::sIDIter = 0; -LLThreadLocalPtr LLThread::sTraceData; +LLThreadLocalPtr LLThread::sTraceData; LL_COMMON_API void assert_main_thread() @@ -99,6 +99,8 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap // We're done with the run function, this thread is done executing now. threadp->mStatus = STOPPED; + delete sTraceData.get(); + return NULL; } @@ -108,6 +110,7 @@ LLThread::LLThread(const std::string& name, apr_pool_t *poolp) : mAPRThreadp(NULL), mStatus(STOPPED) { + mID = ++sIDIter; // Thread creation probably CAN be paranoid about APR being initialized, if necessary diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index fed111b0e4..6889fab2c1 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -105,7 +105,7 @@ protected: EThreadStatus mStatus; U32 mID; - static LLThreadLocalPtr sTraceData; + static LLThreadLocalPtr sTraceData; //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 501414ebf3..8cedcafd10 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -31,27 +31,37 @@ namespace LLTrace { -BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; - -MasterThreadTrace *gMasterThreadTrace = NULL; -LLThreadLocalPtr gCurThreadTrace; +static MasterThreadTrace* gMasterThreadTrace = NULL; void init() { gMasterThreadTrace = new MasterThreadTrace(); - gCurThreadTrace = gMasterThreadTrace; } void cleanup() { delete gMasterThreadTrace; + gMasterThreadTrace = NULL; } +BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; + + + +MasterThreadTrace& getMasterThreadTrace() +{ + llassert(gMasterThreadTrace != NULL); + return *gMasterThreadTrace; +} + + + /////////////////////////////////////////////////////////////////////// // Sampler /////////////////////////////////////////////////////////////////////// + void Sampler::stop() { getThreadTrace()->deactivate(this); @@ -71,15 +81,15 @@ class ThreadTraceData* Sampler::getThreadTrace() // MasterThreadTrace /////////////////////////////////////////////////////////////////////// -void MasterThreadTrace::pullFromWorkerThreads() +void MasterThreadTrace::pullFromSlaveThreads() { LLMutexLock lock(&mSlaveListMutex); - for (worker_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + for (slave_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); it != end_it; ++it) { - it->mWorkerTrace->mSharedData.copyTo(it->mSamplerStorage); + it->mSlaveTrace->mSharedData.copyTo(it->mSamplerStorage); } } @@ -87,18 +97,18 @@ void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadTraces.push_back(WorkerThreadTraceProxy(child)); + mSlaveThreadTraces.push_back(SlaveThreadTraceProxy(child)); } void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) { LLMutexLock lock(&mSlaveListMutex); - for (worker_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + for (slave_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); it != end_it; ++it) { - if (it->mWorkerTrace == child) + if (it->mSlaveTrace == child) { mSlaveThreadTraces.erase(it); break; @@ -107,3 +117,4 @@ void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) } } + diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 3af05d67f9..e4bec0a644 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -44,8 +44,7 @@ namespace LLTrace void init(); void cleanup(); - extern class MasterThreadTrace *gMasterThreadTrace; - extern LLThreadLocalPtr gCurThreadTrace; + class MasterThreadTrace& getMasterThreadTrace(); // one per thread per type template @@ -59,8 +58,8 @@ namespace LLTrace : mStorageSize(64), mNextStorageSlot(0), mStorage(new ACCUMULATOR[DEFAULT_ACCUMULATOR_BUFFER_SIZE]) - { - } + {} + public: AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) @@ -69,6 +68,15 @@ namespace LLTrace mNextStorageSlot(other.mNextStorageSlot) {} + ~AccumulatorBuffer() + { + if (sPrimaryStorage == mStorage) + { + //TODO pick another primary? + sPrimaryStorage = NULL; + } + } + LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) { return mStorage[index]; @@ -353,7 +361,8 @@ namespace LLTrace mTimers(other.mTimers) {} - ~Sampler() {} + ~Sampler() + {} void makePrimary() { @@ -453,21 +462,21 @@ namespace LLTrace void addSlaveThread(class SlaveThreadTrace* child); void removeSlaveThread(class SlaveThreadTrace* child); - // call this periodically to gather stats data from worker threads - void pullFromWorkerThreads(); + // call this periodically to gather stats data from slave threads + void pullFromSlaveThreads(); private: - struct WorkerThreadTraceProxy + struct SlaveThreadTraceProxy { - WorkerThreadTraceProxy(class SlaveThreadTrace* trace) - : mWorkerTrace(trace) + SlaveThreadTraceProxy(class SlaveThreadTrace* trace) + : mSlaveTrace(trace) {} - class SlaveThreadTrace* mWorkerTrace; + class SlaveThreadTrace* mSlaveTrace; Sampler mSamplerStorage; }; - typedef std::list worker_thread_trace_list_t; + typedef std::list slave_thread_trace_list_t; - worker_thread_trace_list_t mSlaveThreadTraces; + slave_thread_trace_list_t mSlaveThreadTraces; LLMutex mSlaveListMutex; }; @@ -475,17 +484,16 @@ namespace LLTrace { public: explicit - SlaveThreadTrace(MasterThreadTrace& master_trace = *gMasterThreadTrace) - : mMaster(master_trace), - ThreadTraceData(master_trace), + SlaveThreadTrace() + : ThreadTraceData(getMasterThreadTrace()), mSharedData(mPrimarySampler) { - master_trace.addSlaveThread(this); + getMasterThreadTrace().addSlaveThread(this); } ~SlaveThreadTrace() { - mMaster.removeSlaveThread(this); + getMasterThreadTrace().removeSlaveThread(this); } // call this periodically to gather stats data for master thread to consume @@ -494,7 +502,7 @@ namespace LLTrace mSharedData.copyFrom(mPrimarySampler); } - MasterThreadTrace& mMaster; + MasterThreadTrace* mMaster; // this data is accessed by other threads, so give it a 64 byte alignment // to avoid false sharing on most x86 processors @@ -529,7 +537,6 @@ namespace LLTrace SharedData mSharedData; }; - class TimeInterval { public: -- cgit v1.2.3 From 07c4be092b276f0d7c14ba12872efb31c1f16764 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 26 Sep 2012 19:12:40 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages slave threads now pushing data to master thread --- indra/llcommon/llqueuedthread.cpp | 2 ++ indra/llcommon/llthread.cpp | 2 +- indra/llcommon/llthread.h | 5 +-- indra/llcommon/lltrace.cpp | 71 ++++++++++++++++++++++++++++++++++++++- indra/llcommon/lltrace.h | 63 +++++++++------------------------- 5 files changed, 92 insertions(+), 51 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 1738c16dea..a741d342d3 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -111,6 +111,8 @@ void LLQueuedThread::shutdown() // virtual S32 LLQueuedThread::update(F32 max_time_ms) { + LLThread::getTraceData()->pushToMaster(); + if (!mStarted) { if (!mThreaded) diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 2e6eb085dc..2ff524d9ba 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -66,7 +66,7 @@ U32 __thread LLThread::sThreadID = 0; #endif U32 LLThread::sIDIter = 0; -LLThreadLocalPtr LLThread::sTraceData; +LLThreadLocalPtr LLThread::sTraceData; LL_COMMON_API void assert_main_thread() diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 6889fab2c1..5cd287ec39 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -87,7 +87,8 @@ public: U32 getID() const { return mID; } - static LLTrace::ThreadTraceData* getTraceData() { return sTraceData.get(); } + static LLTrace::ThreadTrace* getTraceData() { return sTraceData.get(); } + static void setTraceData(LLTrace::ThreadTrace* data) { sTraceData = data;} private: BOOL mPaused; @@ -105,7 +106,7 @@ protected: EThreadStatus mStatus; U32 mID; - static LLThreadLocalPtr sTraceData; + static LLThreadLocalPtr sTraceData; //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 8cedcafd10..24a2b33a5f 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -72,11 +72,69 @@ void Sampler::resume() getThreadTrace()->activate(this); } -class ThreadTraceData* Sampler::getThreadTrace() +class ThreadTrace* Sampler::getThreadTrace() { return LLThread::getTraceData(); } +/////////////////////////////////////////////////////////////////////// +// MasterThreadTrace +/////////////////////////////////////////////////////////////////////// + +ThreadTrace::ThreadTrace() +{ + mPrimarySampler.makePrimary(); +} + +ThreadTrace::ThreadTrace( const ThreadTrace& other ) : mPrimarySampler(other.mPrimarySampler) +{ + mPrimarySampler.makePrimary(); +} + +void ThreadTrace::activate( Sampler* sampler ) +{ + flushPrimary(); + mActiveSamplers.push_back(sampler); +} + +void ThreadTrace::deactivate( Sampler* sampler ) +{ + sampler->mergeFrom(mPrimarySampler); + + // TODO: replace with intrusive list + std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); + if (found_it != mActiveSamplers.end()) + { + mActiveSamplers.erase(found_it); + } +} + +void ThreadTrace::flushPrimary() +{ + for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); + it != end_it; + ++it) + { + (*it)->mergeFrom(mPrimarySampler); + } + mPrimarySampler.reset(); +} + + + + + + +/////////////////////////////////////////////////////////////////////// +// SlaveThreadTrace +/////////////////////////////////////////////////////////////////////// + +void SlaveThreadTrace::pushToMaster() +{ + mSharedData.copyFrom(mPrimarySampler); +} + + /////////////////////////////////////////////////////////////////////// // MasterThreadTrace /////////////////////////////////////////////////////////////////////// @@ -116,5 +174,16 @@ void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) } } +void MasterThreadTrace::pushToMaster() +{ + +} + +MasterThreadTrace::MasterThreadTrace() +{ + LLThread::setTraceData(this); +} + + } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index e4bec0a644..601b5ed182 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -396,7 +396,7 @@ namespace LLTrace private: // returns data for current thread - class ThreadTraceData* getThreadTrace(); + class ThreadTrace* getThreadTrace(); AccumulatorBuffer > mF32Stats; AccumulatorBuffer > mS32Stats; @@ -404,48 +404,19 @@ namespace LLTrace AccumulatorBuffer mTimers; }; - class ThreadTraceData + class ThreadTrace { public: - ThreadTraceData() - { - mPrimarySampler.makePrimary(); - } - - ThreadTraceData(const ThreadTraceData& other) - : mPrimarySampler(other.mPrimarySampler) - { - mPrimarySampler.makePrimary(); - } + ThreadTrace(); + ThreadTrace(const ThreadTrace& other); - void activate(Sampler* sampler) - { - flushPrimary(); - mActiveSamplers.push_back(sampler); - } + virtual ~ThreadTrace() {} - void deactivate(Sampler* sampler) - { - sampler->mergeFrom(mPrimarySampler); - - // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); - if (found_it != mActiveSamplers.end()) - { - mActiveSamplers.erase(found_it); - } - } + void activate(Sampler* sampler); + void deactivate(Sampler* sampler); + void flushPrimary(); - void flushPrimary() - { - for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); - it != end_it; - ++it) - { - (*it)->mergeFrom(mPrimarySampler); - } - mPrimarySampler.reset(); - } + virtual void pushToMaster() = 0; Sampler* getPrimarySampler() { return &mPrimarySampler; } protected: @@ -453,15 +424,16 @@ namespace LLTrace std::list mActiveSamplers; }; - class MasterThreadTrace : public ThreadTraceData + class MasterThreadTrace : public ThreadTrace { public: - MasterThreadTrace() - {} + MasterThreadTrace(); void addSlaveThread(class SlaveThreadTrace* child); void removeSlaveThread(class SlaveThreadTrace* child); + /*virtual */ void pushToMaster(); + // call this periodically to gather stats data from slave threads void pullFromSlaveThreads(); @@ -480,12 +452,12 @@ namespace LLTrace LLMutex mSlaveListMutex; }; - class SlaveThreadTrace : public ThreadTraceData + class SlaveThreadTrace : public ThreadTrace { public: explicit SlaveThreadTrace() - : ThreadTraceData(getMasterThreadTrace()), + : ThreadTrace(getMasterThreadTrace()), mSharedData(mPrimarySampler) { getMasterThreadTrace().addSlaveThread(this); @@ -497,10 +469,7 @@ namespace LLTrace } // call this periodically to gather stats data for master thread to consume - void pushToParent() - { - mSharedData.copyFrom(mPrimarySampler); - } + /*virtual*/ void pushToMaster(); MasterThreadTrace* mMaster; -- cgit v1.2.3 From 38354e19063478c8cda0408547ad05023b457041 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 28 Sep 2012 10:45:14 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages created separate constructor for static allocation of sampler buffer fixed start/stop/resume semantics of samplers and added sampler time interval tracking --- indra/llcommon/llcommon.cpp | 1 + indra/llcommon/llqueuedthread.cpp | 1 + indra/llcommon/llthread.cpp | 14 ++++- indra/llcommon/llthread.h | 10 +++- indra/llcommon/lltrace.cpp | 117 ++++++++++++++++++++++++++++++++------ indra/llcommon/lltrace.h | 108 +++++++++++++++-------------------- 6 files changed, 167 insertions(+), 84 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index c149a1fe5c..c720df7555 100644 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -29,6 +29,7 @@ #include "llmemory.h" #include "llthread.h" +#include "lltrace.h" //static BOOL LLCommon::sAprInitialized = FALSE; diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index a741d342d3..0a35474b7f 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -28,6 +28,7 @@ #include "llstl.h" #include "lltimer.h" // ms_sleep() +#include "lltrace.h" //============================================================================ diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 2ff524d9ba..7384842627 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -32,6 +32,7 @@ #include "llmutex.h" #include "lltimer.h" +#include "lltrace.h" #if LL_LINUX || LL_SOLARIS #include @@ -85,7 +86,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; - sTraceData = new LLTrace::SlaveThreadTrace(); + setTraceData(new LLTrace::SlaveThreadTrace()); #if !LL_DARWIN sThreadIndex = threadp->mID; @@ -100,6 +101,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap threadp->mStatus = STOPPED; delete sTraceData.get(); + sTraceData = NULL; return NULL; } @@ -311,3 +313,13 @@ void LLThread::wakeLocked() mRunCondition->signal(); } } + +LLTrace::ThreadTrace* LLThread::getTraceData() +{ + return sTraceData.get(); +} + +void LLThread::setTraceData( LLTrace::ThreadTrace* data ) +{ + sTraceData = data; +} diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 5cd287ec39..334ea2f0da 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -30,8 +30,12 @@ #include "llapp.h" #include "llapr.h" #include "apr_thread_cond.h" -#include "lltrace.h" +#include "llmutex.h" +namespace LLTrace +{ + class ThreadTrace; +} class LL_COMMON_API LLThread { private: @@ -87,8 +91,8 @@ public: U32 getID() const { return mID; } - static LLTrace::ThreadTrace* getTraceData() { return sTraceData.get(); } - static void setTraceData(LLTrace::ThreadTrace* data) { sTraceData = data;} + static LLTrace::ThreadTrace* getTraceData(); + static void setTraceData(LLTrace::ThreadTrace* data); private: BOOL mPaused; diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 24a2b33a5f..2da4363b1d 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -55,40 +55,97 @@ MasterThreadTrace& getMasterThreadTrace() return *gMasterThreadTrace; } - - /////////////////////////////////////////////////////////////////////// // Sampler /////////////////////////////////////////////////////////////////////// +Sampler::Sampler(ThreadTrace* thread_trace) +: mElapsedSeconds(0), + mIsStarted(false), + mThreadTrace(thread_trace) +{ +} -void Sampler::stop() +Sampler::~Sampler() { - getThreadTrace()->deactivate(this); +} + +void Sampler::start() +{ + reset(); + resume(); +} + +void Sampler::reset() +{ + mF32Stats.reset(); + mS32Stats.reset(); + mStackTimers.reset(); + + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); } void Sampler::resume() { - getThreadTrace()->activate(this); + if (!mIsStarted) + { + mSamplingTimer.reset(); + getThreadTrace()->activate(this); + mIsStarted = true; + } +} + +void Sampler::stop() +{ + if (mIsStarted) + { + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + getThreadTrace()->deactivate(this); + mIsStarted = false; + } +} + +ThreadTrace* Sampler::getThreadTrace() +{ + return mThreadTrace; +} + +void Sampler::makePrimary() +{ + mF32Stats.makePrimary(); + mS32Stats.makePrimary(); + mStackTimers.makePrimary(); } -class ThreadTrace* Sampler::getThreadTrace() +void Sampler::mergeFrom( const Sampler* other ) { - return LLThread::getTraceData(); + mF32Stats.mergeFrom(other->mF32Stats); + mS32Stats.mergeFrom(other->mS32Stats); + mStackTimers.mergeFrom(other->mStackTimers); } + /////////////////////////////////////////////////////////////////////// // MasterThreadTrace /////////////////////////////////////////////////////////////////////// ThreadTrace::ThreadTrace() { - mPrimarySampler.makePrimary(); + mPrimarySampler = createSampler(); + mPrimarySampler->makePrimary(); + mPrimarySampler->start(); } -ThreadTrace::ThreadTrace( const ThreadTrace& other ) : mPrimarySampler(other.mPrimarySampler) +ThreadTrace::ThreadTrace( const ThreadTrace& other ) +: mPrimarySampler(new Sampler(*(other.mPrimarySampler))) { - mPrimarySampler.makePrimary(); + mPrimarySampler->makePrimary(); +} + +ThreadTrace::~ThreadTrace() +{ + delete mPrimarySampler; } void ThreadTrace::activate( Sampler* sampler ) @@ -117,11 +174,13 @@ void ThreadTrace::flushPrimary() { (*it)->mergeFrom(mPrimarySampler); } - mPrimarySampler.reset(); + mPrimarySampler->reset(); } - - +Sampler* ThreadTrace::createSampler() +{ + return new Sampler(this); +} @@ -129,12 +188,23 @@ void ThreadTrace::flushPrimary() // SlaveThreadTrace /////////////////////////////////////////////////////////////////////// +SlaveThreadTrace::SlaveThreadTrace() +: ThreadTrace(getMasterThreadTrace()), + mSharedData(createSampler()) +{ + getMasterThreadTrace().addSlaveThread(this); +} + +SlaveThreadTrace::~SlaveThreadTrace() +{ + getMasterThreadTrace().removeSlaveThread(this); +} + void SlaveThreadTrace::pushToMaster() { mSharedData.copyFrom(mPrimarySampler); } - /////////////////////////////////////////////////////////////////////// // MasterThreadTrace /////////////////////////////////////////////////////////////////////// @@ -155,7 +225,7 @@ void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadTraces.push_back(SlaveThreadTraceProxy(child)); + mSlaveThreadTraces.push_back(SlaveThreadTraceProxy(child, createSampler())); } void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) @@ -175,15 +245,26 @@ void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) } void MasterThreadTrace::pushToMaster() -{ - -} +{} MasterThreadTrace::MasterThreadTrace() { LLThread::setTraceData(this); } +/////////////////////////////////////////////////////////////////////// +// MasterThreadTrace::SlaveThreadTraceProxy +/////////////////////////////////////////////////////////////////////// + +MasterThreadTrace::SlaveThreadTraceProxy::SlaveThreadTraceProxy( class SlaveThreadTrace* trace, Sampler* storage ) +: mSlaveTrace(trace), + mSamplerStorage(storage) +{} +MasterThreadTrace::SlaveThreadTraceProxy::~SlaveThreadTraceProxy() +{ + delete mSamplerStorage; } + +} diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 601b5ed182..a443735e69 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -32,6 +32,7 @@ #include "llmutex.h" #include "llmemory.h" +#include "lltimer.h" #include @@ -39,6 +40,7 @@ #define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) #define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); + namespace LLTrace { void init(); @@ -135,7 +137,7 @@ namespace LLTrace static AccumulatorBuffer& getDefaultBuffer() { - static AccumulatorBuffer sBuffer; + static AccumulatorBuffer sBuffer(STATIC_ALLOC); return sBuffer; } @@ -354,54 +356,38 @@ namespace LLTrace class Sampler { public: - Sampler() {} - Sampler(const Sampler& other) - : mF32Stats(other.mF32Stats), - mS32Stats(other.mS32Stats), - mTimers(other.mTimers) - {} - - ~Sampler() - {} + ~Sampler(); - void makePrimary() - { - mF32Stats.makePrimary(); - mS32Stats.makePrimary(); - mTimers.makePrimary(); - } - - void start() - { - reset(); - resume(); - } + void makePrimary(); + void start(); void stop(); void resume(); - void mergeFrom(const Sampler& other) - { - mF32Stats.mergeFrom(other.mF32Stats); - mS32Stats.mergeFrom(other.mS32Stats); - mTimers.mergeFrom(other.mTimers); - } + void mergeFrom(const Sampler* other); - void reset() - { - mF32Stats.reset(); - mS32Stats.reset(); - mTimers.reset(); - } + void reset(); + + bool isStarted() { return mIsStarted; } private: + friend class ThreadTrace; + Sampler(class ThreadTrace* thread_trace); + + // no copy + Sampler(const Sampler& other) {} // returns data for current thread class ThreadTrace* getThreadTrace(); AccumulatorBuffer > mF32Stats; AccumulatorBuffer > mS32Stats; - AccumulatorBuffer mTimers; + AccumulatorBuffer mStackTimers; + + bool mIsStarted; + LLTimer mSamplingTimer; + F64 mElapsedSeconds; + ThreadTrace* mThreadTrace; }; class ThreadTrace @@ -410,17 +396,19 @@ namespace LLTrace ThreadTrace(); ThreadTrace(const ThreadTrace& other); - virtual ~ThreadTrace() {} + virtual ~ThreadTrace(); void activate(Sampler* sampler); void deactivate(Sampler* sampler); void flushPrimary(); + Sampler* createSampler(); + virtual void pushToMaster() = 0; - Sampler* getPrimarySampler() { return &mPrimarySampler; } + Sampler* getPrimarySampler() { return mPrimarySampler; } protected: - Sampler mPrimarySampler; + Sampler* mPrimarySampler; std::list mActiveSamplers; }; @@ -440,11 +428,11 @@ namespace LLTrace private: struct SlaveThreadTraceProxy { - SlaveThreadTraceProxy(class SlaveThreadTrace* trace) - : mSlaveTrace(trace) - {} + SlaveThreadTraceProxy(class SlaveThreadTrace* trace, Sampler* storage); + + ~SlaveThreadTraceProxy(); class SlaveThreadTrace* mSlaveTrace; - Sampler mSamplerStorage; + Sampler* mSamplerStorage; }; typedef std::list slave_thread_trace_list_t; @@ -455,18 +443,8 @@ namespace LLTrace class SlaveThreadTrace : public ThreadTrace { public: - explicit - SlaveThreadTrace() - : ThreadTrace(getMasterThreadTrace()), - mSharedData(mPrimarySampler) - { - getMasterThreadTrace().addSlaveThread(this); - } - - ~SlaveThreadTrace() - { - getMasterThreadTrace().removeSlaveThread(this); - } + SlaveThreadTrace(); + ~SlaveThreadTrace(); // call this periodically to gather stats data for master thread to consume /*virtual*/ void pushToMaster(); @@ -479,29 +457,35 @@ namespace LLTrace { public: explicit - SharedData(const Sampler& other_sampler) - : mSampler(other_sampler) - {} + SharedData(Sampler* sampler) + : mSampler(sampler) + { + } + + ~SharedData() + { + delete mSampler; + } - void copyFrom(Sampler& source) + void copyFrom(Sampler* source) { LLMutexLock lock(&mSamplerMutex); { - mSampler.mergeFrom(source); + mSampler->mergeFrom(source); } } - void copyTo(Sampler& sink) + void copyTo(Sampler* sink) { LLMutexLock lock(&mSamplerMutex); { - sink.mergeFrom(mSampler); + sink->mergeFrom(mSampler); } } private: // add a cache line's worth of unused space to avoid any potential of false sharing LLMutex mSamplerMutex; - Sampler mSampler; + Sampler* mSampler; }; SharedData mSharedData; }; -- cgit v1.2.3 From b1baf982b1bd41a150233d0a28d3601226924c65 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 30 Sep 2012 10:41:29 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages factored out lltrace::sampler into separate file added rudimentary lltrace support to llstatgraph made llstatgraph use param blocks more effectively moves initial set of stats over to lltrace removed windows.h #defines for min and max --- indra/llcommon/CMakeLists.txt | 2 + indra/llcommon/llapr.h | 2 + indra/llcommon/lltrace.cpp | 112 +++++++++++---------------------- indra/llcommon/lltrace.h | 127 ++++++++++++-------------------------- indra/llcommon/lltracesampler.cpp | 103 +++++++++++++++++++++++++++++++ indra/llcommon/lltracesampler.h | 91 +++++++++++++++++++++++++++ 6 files changed, 275 insertions(+), 162 deletions(-) create mode 100644 indra/llcommon/lltracesampler.cpp create mode 100644 indra/llcommon/lltracesampler.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index f78751601c..e10dbb3e4d 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -101,6 +101,7 @@ set(llcommon_SOURCE_FILES llthreadsafequeue.cpp lltimer.cpp lltrace.cpp + lltracesampler.cpp lluri.cpp lluuid.cpp llworkerthread.cpp @@ -243,6 +244,7 @@ set(llcommon_HEADER_FILES llthreadsafequeue.h lltimer.h lltrace.h + lltracesampler.h lltreeiterators.h lltypeinfolookup.h lluri.h diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 830e0a33fa..4e704998c2 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -39,6 +39,8 @@ #define WIN32_LEAN_AND_MEAN #include #include + #undef min + #undef max #endif #include diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 2da4363b1d..e487e450a9 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -26,6 +26,7 @@ #include "linden_common.h" #include "lltrace.h" +#include "lltracesampler.h" #include "llthread.h" namespace LLTrace @@ -55,77 +56,6 @@ MasterThreadTrace& getMasterThreadTrace() return *gMasterThreadTrace; } -/////////////////////////////////////////////////////////////////////// -// Sampler -/////////////////////////////////////////////////////////////////////// - -Sampler::Sampler(ThreadTrace* thread_trace) -: mElapsedSeconds(0), - mIsStarted(false), - mThreadTrace(thread_trace) -{ -} - -Sampler::~Sampler() -{ -} - -void Sampler::start() -{ - reset(); - resume(); -} - -void Sampler::reset() -{ - mF32Stats.reset(); - mS32Stats.reset(); - mStackTimers.reset(); - - mElapsedSeconds = 0.0; - mSamplingTimer.reset(); -} - -void Sampler::resume() -{ - if (!mIsStarted) - { - mSamplingTimer.reset(); - getThreadTrace()->activate(this); - mIsStarted = true; - } -} - -void Sampler::stop() -{ - if (mIsStarted) - { - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - getThreadTrace()->deactivate(this); - mIsStarted = false; - } -} - -ThreadTrace* Sampler::getThreadTrace() -{ - return mThreadTrace; -} - -void Sampler::makePrimary() -{ - mF32Stats.makePrimary(); - mS32Stats.makePrimary(); - mStackTimers.makePrimary(); -} - -void Sampler::mergeFrom( const Sampler* other ) -{ - mF32Stats.mergeFrom(other->mF32Stats); - mS32Stats.mergeFrom(other->mS32Stats); - mStackTimers.mergeFrom(other->mStackTimers); -} - - /////////////////////////////////////////////////////////////////////// // MasterThreadTrace /////////////////////////////////////////////////////////////////////// @@ -148,6 +78,11 @@ ThreadTrace::~ThreadTrace() delete mPrimarySampler; } +Sampler* ThreadTrace::getPrimarySampler() +{ + return mPrimarySampler; +} + void ThreadTrace::activate( Sampler* sampler ) { flushPrimary(); @@ -205,6 +140,34 @@ void SlaveThreadTrace::pushToMaster() mSharedData.copyFrom(mPrimarySampler); } +void SlaveThreadTrace::SharedData::copyFrom( Sampler* source ) +{ + LLMutexLock lock(&mSamplerMutex); + { + mSampler->mergeFrom(source); + } +} + +void SlaveThreadTrace::SharedData::copyTo( Sampler* sink ) +{ + LLMutexLock lock(&mSamplerMutex); + { + sink->mergeFrom(mSampler); + } +} + +SlaveThreadTrace::SharedData::~SharedData() +{ + delete mSampler; +} + +SlaveThreadTrace::SharedData::SharedData( Sampler* sampler ) : mSampler(sampler) +{} + + + + + /////////////////////////////////////////////////////////////////////// // MasterThreadTrace /////////////////////////////////////////////////////////////////////// @@ -217,7 +180,7 @@ void MasterThreadTrace::pullFromSlaveThreads() it != end_it; ++it) { - it->mSlaveTrace->mSharedData.copyTo(it->mSamplerStorage); + (*it)->mSlaveTrace->mSharedData.copyTo((*it)->mSamplerStorage); } } @@ -225,7 +188,7 @@ void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadTraces.push_back(SlaveThreadTraceProxy(child, createSampler())); + mSlaveThreadTraces.push_back(new SlaveThreadTraceProxy(child, createSampler())); } void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) @@ -236,7 +199,7 @@ void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) it != end_it; ++it) { - if (it->mSlaveTrace == child) + if ((*it)->mSlaveTrace == child) { mSlaveThreadTraces.erase(it); break; @@ -266,5 +229,4 @@ MasterThreadTrace::SlaveThreadTraceProxy::~SlaveThreadTraceProxy() delete mSamplerStorage; } - } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index a443735e69..c6f920b5e4 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -43,14 +43,16 @@ namespace LLTrace { + class Sampler; + void init(); void cleanup(); - class MasterThreadTrace& getMasterThreadTrace(); + class LL_COMMON_API MasterThreadTrace& getMasterThreadTrace(); // one per thread per type template - class AccumulatorBuffer + class LL_COMMON_API AccumulatorBuffer { static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; private: @@ -64,6 +66,8 @@ namespace LLTrace public: + // copying an accumulator buffer does not copy the actual contents, but simply initializes the buffer size + // to be identical to the other buffer AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) : mStorageSize(other.mStorageSize), mStorage(new ACCUMULATOR[other.mStorageSize]), @@ -150,28 +154,30 @@ namespace LLTrace template LLThreadLocalPtr AccumulatorBuffer::sPrimaryStorage; template - class Trace + class LL_COMMON_API TraceType { public: - Trace(const std::string& name) + TraceType(const std::string& name) : mName(name) { mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } - LL_FORCE_INLINE ACCUMULATOR& getAccumulator() + LL_FORCE_INLINE ACCUMULATOR& getPrimaryAccumulator() { return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; } - private: + ACCUMULATOR& getAccumulator(AccumulatorBuffer& buffer) { return buffer[mAccumulatorIndex]; } + + protected: std::string mName; size_t mAccumulatorIndex; }; template - class StatAccumulator + class LL_COMMON_API StatAccumulator { public: StatAccumulator() @@ -217,6 +223,11 @@ namespace LLTrace mMax = 0; } + T getSum() { return mSum; } + T getMin() { return mMin; } + T getMax() { return mMax; } + T getMean() { return mSum / (T)mNumSamples; } + private: T mSum, mMin, @@ -226,20 +237,23 @@ namespace LLTrace }; template - class Stat : public Trace > + class LL_COMMON_API Stat + : public TraceType >, + public LLInstanceTracker, std::string> { public: Stat(const std::string& name) - : Trace(name) + : TraceType(name), + LLInstanceTracker(name) {} void sample(T value) { - getAccumulator().sample(value); + getPrimaryAccumulator().sample(value); } }; - struct TimerAccumulator + struct LL_COMMON_API TimerAccumulator { U32 mTotalTimeCounter, mChildTimeCounter, @@ -267,11 +281,11 @@ namespace LLTrace }; - class BlockTimer : public Trace + class LL_COMMON_API BlockTimer : public TraceType { public: BlockTimer(const char* name) - : Trace(name) + : TraceType(name) {} struct Recorder @@ -287,7 +301,7 @@ namespace LLTrace : mLastRecorder(sCurRecorder) { mStartTime = getCPUClockCount32(); - TimerAccumulator* accumulator = &block_timer.getAccumulator(); // get per-thread accumulator + TimerAccumulator* accumulator = &block_timer.getPrimaryAccumulator(); // get per-thread accumulator accumulator->mActiveCount++; accumulator->mCalls++; accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); @@ -353,44 +367,7 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; - class Sampler - { - public: - ~Sampler(); - - void makePrimary(); - - void start(); - void stop(); - void resume(); - - void mergeFrom(const Sampler* other); - - void reset(); - - bool isStarted() { return mIsStarted; } - - private: - friend class ThreadTrace; - Sampler(class ThreadTrace* thread_trace); - - // no copy - Sampler(const Sampler& other) {} - // returns data for current thread - class ThreadTrace* getThreadTrace(); - - AccumulatorBuffer > mF32Stats; - AccumulatorBuffer > mS32Stats; - - AccumulatorBuffer mStackTimers; - - bool mIsStarted; - LLTimer mSamplingTimer; - F64 mElapsedSeconds; - ThreadTrace* mThreadTrace; - }; - - class ThreadTrace + class LL_COMMON_API ThreadTrace { public: ThreadTrace(); @@ -406,13 +383,13 @@ namespace LLTrace virtual void pushToMaster() = 0; - Sampler* getPrimarySampler() { return mPrimarySampler; } + Sampler* getPrimarySampler(); protected: Sampler* mPrimarySampler; std::list mActiveSamplers; }; - class MasterThreadTrace : public ThreadTrace + class LL_COMMON_API MasterThreadTrace : public ThreadTrace { public: MasterThreadTrace(); @@ -433,14 +410,17 @@ namespace LLTrace ~SlaveThreadTraceProxy(); class SlaveThreadTrace* mSlaveTrace; Sampler* mSamplerStorage; + private: + //no need to copy these and then have to duplicate the storage + SlaveThreadTraceProxy(const SlaveThreadTraceProxy& other) {} }; - typedef std::list slave_thread_trace_list_t; + typedef std::list slave_thread_trace_list_t; slave_thread_trace_list_t mSlaveThreadTraces; LLMutex mSlaveListMutex; }; - class SlaveThreadTrace : public ThreadTrace + class LL_COMMON_API SlaveThreadTrace : public ThreadTrace { public: SlaveThreadTrace(); @@ -457,31 +437,12 @@ namespace LLTrace { public: explicit - SharedData(Sampler* sampler) - : mSampler(sampler) - { - } + SharedData(Sampler* sampler); - ~SharedData() - { - delete mSampler; - } + ~SharedData(); - void copyFrom(Sampler* source) - { - LLMutexLock lock(&mSamplerMutex); - { - mSampler->mergeFrom(source); - } - } - - void copyTo(Sampler* sink) - { - LLMutexLock lock(&mSamplerMutex); - { - sink->mergeFrom(mSampler); - } - } + void copyFrom(Sampler* source); + void copyTo(Sampler* sink); private: // add a cache line's worth of unused space to avoid any potential of false sharing LLMutex mSamplerMutex; @@ -489,14 +450,6 @@ namespace LLTrace }; SharedData mSharedData; }; - - class TimeInterval - { - public: - void start() {} - void stop() {} - void resume() {} - }; } #endif // LL_LLTRACE_H diff --git a/indra/llcommon/lltracesampler.cpp b/indra/llcommon/lltracesampler.cpp new file mode 100644 index 0000000000..0cf01d7a3a --- /dev/null +++ b/indra/llcommon/lltracesampler.cpp @@ -0,0 +1,103 @@ +/** + * @file lltracesampler.cpp + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltracesampler.h" + +namespace LLTrace +{ + +/////////////////////////////////////////////////////////////////////// +// Sampler +/////////////////////////////////////////////////////////////////////// + +Sampler::Sampler(ThreadTrace* thread_trace) +: mElapsedSeconds(0), + mIsStarted(false), + mThreadTrace(thread_trace) +{ +} + +Sampler::~Sampler() +{ +} + +void Sampler::start() +{ + reset(); + resume(); +} + +void Sampler::reset() +{ + mF32Stats.reset(); + mS32Stats.reset(); + mStackTimers.reset(); + + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); +} + +void Sampler::resume() +{ + if (!mIsStarted) + { + mSamplingTimer.reset(); + getThreadTrace()->activate(this); + mIsStarted = true; + } +} + +void Sampler::stop() +{ + if (mIsStarted) + { + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + getThreadTrace()->deactivate(this); + mIsStarted = false; + } +} + +ThreadTrace* Sampler::getThreadTrace() +{ + return mThreadTrace; +} + +void Sampler::makePrimary() +{ + mF32Stats.makePrimary(); + mS32Stats.makePrimary(); + mStackTimers.makePrimary(); +} + +void Sampler::mergeFrom( const Sampler* other ) +{ + mF32Stats.mergeFrom(other->mF32Stats); + mS32Stats.mergeFrom(other->mS32Stats); + mStackTimers.mergeFrom(other->mStackTimers); +} + +} diff --git a/indra/llcommon/lltracesampler.h b/indra/llcommon/lltracesampler.h new file mode 100644 index 0000000000..d1ca7fc9bb --- /dev/null +++ b/indra/llcommon/lltracesampler.h @@ -0,0 +1,91 @@ +/** + * @file lltracesampler.h + * @brief Sampling object for collecting runtime statistics originating from lltrace. + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTRACESAMPLER_H +#define LL_LLTRACESAMPLER_H + +#include "stdtypes.h" +#include "llpreprocessor.h" + +#include "lltrace.h" + +namespace LLTrace +{ + class LL_COMMON_API Sampler + { + public: + ~Sampler(); + + void makePrimary(); + + void start(); + void stop(); + void resume(); + + void mergeFrom(const Sampler* other); + + void reset(); + + bool isStarted() { return mIsStarted; } + + F32 getSum(Stat& stat) { return stat.getAccumulator(mF32Stats).getSum(); } + F32 getMin(Stat& stat) { return stat.getAccumulator(mF32Stats).getMin(); } + F32 getMax(Stat& stat) { return stat.getAccumulator(mF32Stats).getMax(); } + F32 getMean(Stat& stat) { return stat.getAccumulator(mF32Stats).getMean(); } + + S32 getSum(Stat& stat) { return stat.getAccumulator(mS32Stats).getSum(); } + S32 getMin(Stat& stat) { return stat.getAccumulator(mS32Stats).getMin(); } + S32 getMax(Stat& stat) { return stat.getAccumulator(mS32Stats).getMax(); } + S32 getMean(Stat& stat) { return stat.getAccumulator(mS32Stats).getMean(); } + + F64 getSampleTime() { return mElapsedSeconds; } + + private: + friend class ThreadTrace; + Sampler(class ThreadTrace* thread_trace); + + // no copy + Sampler(const Sampler& other) {} + // returns data for current thread + class ThreadTrace* getThreadTrace(); + + //TODO: take snapshot at sampler start so we can simplify updates + //AccumulatorBuffer > mF32StatsStart; + //AccumulatorBuffer > mS32StatsStart; + //AccumulatorBuffer mStackTimersStart; + + AccumulatorBuffer > mF32Stats; + AccumulatorBuffer > mS32Stats; + AccumulatorBuffer mStackTimers; + + bool mIsStarted; + LLTimer mSamplingTimer; + F64 mElapsedSeconds; + ThreadTrace* mThreadTrace; + }; +} + +#endif // LL_LLTRACESAMPLER_H -- cgit v1.2.3 From 14b1b0b2bb6bac5bc688cc4d14c33f1b680dd3b4 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 1 Oct 2012 19:39:04 -0700 Subject: SH-3275 WIP Run viewer metrics for object update messages cleaned up API samplers are now value types with copy-on-write buffers under the hood removed coupling with LLThread --- indra/llcommon/llapr.cpp | 28 +++--- indra/llcommon/llapr.h | 28 +++--- indra/llcommon/llpointer.h | 83 +++++++++++++----- indra/llcommon/llqueuedthread.cpp | 2 +- indra/llcommon/llthread.cpp | 15 +--- indra/llcommon/llthread.h | 9 -- indra/llcommon/lltrace.cpp | 108 ++++++++++------------- indra/llcommon/lltrace.h | 180 ++++++++++++++++++++++++++++++-------- indra/llcommon/lltracesampler.cpp | 98 +++++++++++++++++---- indra/llcommon/lltracesampler.h | 59 +++++++------ 10 files changed, 398 insertions(+), 212 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index e9930c10f7..d23b70690d 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -55,7 +55,7 @@ void ll_init_apr() LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE); } - LLThreadLocalPtrBase::initAllThreadLocalStorage(); + LLThreadLocalPointerBase::initAllThreadLocalStorage(); } @@ -80,7 +80,7 @@ void ll_cleanup_apr() gCallStacksLogMutexp = NULL; } - LLThreadLocalPtrBase::destroyAllThreadLocalStorage(); + LLThreadLocalPointerBase::destroyAllThreadLocalStorage(); if (gAPRPoolp) { @@ -482,11 +482,11 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) } // -//LLThreadLocalPtrBase +//LLThreadLocalPointerBase // -bool LLThreadLocalPtrBase::sInitialized = false; +bool LLThreadLocalPointerBase::sInitialized = false; -LLThreadLocalPtrBase::LLThreadLocalPtrBase() +LLThreadLocalPointerBase::LLThreadLocalPointerBase() : mThreadKey(NULL) { if (sInitialized) @@ -495,7 +495,7 @@ LLThreadLocalPtrBase::LLThreadLocalPtrBase() } } -LLThreadLocalPtrBase::LLThreadLocalPtrBase( const LLThreadLocalPtrBase& other) +LLThreadLocalPointerBase::LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) : mThreadKey(NULL) { if (sInitialized) @@ -504,12 +504,12 @@ LLThreadLocalPtrBase::LLThreadLocalPtrBase( const LLThreadLocalPtrBase& other) } } -LLThreadLocalPtrBase::~LLThreadLocalPtrBase() +LLThreadLocalPointerBase::~LLThreadLocalPointerBase() { destroyStorage(); } -void LLThreadLocalPtrBase::set( void* value ) +void LLThreadLocalPointerBase::set( void* value ) { llassert(sInitialized && mThreadKey); @@ -521,7 +521,7 @@ void LLThreadLocalPtrBase::set( void* value ) } } -void LLThreadLocalPtrBase::initStorage( ) +void LLThreadLocalPointerBase::initStorage( ) { apr_status_t result = apr_threadkey_private_create(&mThreadKey, NULL, gAPRPoolp); if (result != APR_SUCCESS) @@ -531,7 +531,7 @@ void LLThreadLocalPtrBase::initStorage( ) } } -void LLThreadLocalPtrBase::destroyStorage() +void LLThreadLocalPointerBase::destroyStorage() { if (sInitialized) { @@ -547,11 +547,11 @@ void LLThreadLocalPtrBase::destroyStorage() } } -void LLThreadLocalPtrBase::initAllThreadLocalStorage() +void LLThreadLocalPointerBase::initAllThreadLocalStorage() { if (!sInitialized) { - for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { @@ -561,11 +561,11 @@ void LLThreadLocalPtrBase::initAllThreadLocalStorage() } } -void LLThreadLocalPtrBase::destroyAllThreadLocalStorage() +void LLThreadLocalPointerBase::destroyAllThreadLocalStorage() { if (sInitialized) { - for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 4e704998c2..6efb44a663 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -258,12 +258,12 @@ public: //******************************************************************************************************************************* }; -class LLThreadLocalPtrBase : LLInstanceTracker +class LLThreadLocalPointerBase : LLInstanceTracker { public: - LLThreadLocalPtrBase(); - LLThreadLocalPtrBase(const LLThreadLocalPtrBase& other); - ~LLThreadLocalPtrBase(); + LLThreadLocalPointerBase(); + LLThreadLocalPointerBase(const LLThreadLocalPointerBase& other); + ~LLThreadLocalPointerBase(); static void initAllThreadLocalStorage(); static void destroyAllThreadLocalStorage(); @@ -307,35 +307,35 @@ protected: }; template -class LLThreadLocalPtr : public LLThreadLocalPtrBase +class LLThreadLocalPointer : public LLThreadLocalPointerBase { public: - LLThreadLocalPtr() - : LLThreadLocalPtrBase() + LLThreadLocalPointer() + : LLThreadLocalPointerBase() {} - explicit LLThreadLocalPtr(T* value) - : LLThreadLocalPtrBase(&cleanup) + explicit LLThreadLocalPointer(T* value) + : LLThreadLocalPointerBase(&cleanup) { set(value); } - LLThreadLocalPtr(const LLThreadLocalPtr& other) - : LLThreadLocalPtrBase(other, &cleanup) + LLThreadLocalPointer(const LLThreadLocalPointer& other) + : LLThreadLocalPointerBase(other, &cleanup) { set(other.get()); } LL_FORCE_INLINE T* get() { - return (T*)LLThreadLocalPtrBase::get(); + return (T*)LLThreadLocalPointerBase::get(); } const T* get() const { - return (const T*)LLThreadLocalPtrBase::get(); + return (const T*)LLThreadLocalPointerBase::get(); } T* operator -> () @@ -358,7 +358,7 @@ public: return *(T*)get(); } - LLThreadLocalPtr& operator = (T* value) + LLThreadLocalPointer& operator = (T* value) { set((void*)value); return *this; diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h index 88c09c8dca..0fee4f0990 100644 --- a/indra/llcommon/llpointer.h +++ b/indra/llcommon/llpointer.h @@ -97,24 +97,13 @@ public: LLPointer& operator =(Type* ptr) { - if( mPointer != ptr ) - { - unref(); - mPointer = ptr; - ref(); - } - + assign(ptr); return *this; } LLPointer& operator =(const LLPointer& ptr) { - if( mPointer != ptr.mPointer ) - { - unref(); - mPointer = ptr.mPointer; - ref(); - } + assign(ptr); return *this; } @@ -122,12 +111,7 @@ public: template LLPointer& operator =(const LLPointer& ptr) { - if( mPointer != ptr.get() ) - { - unref(); - mPointer = ptr.get(); - ref(); - } + assign(ptr.get()); return *this; } @@ -144,6 +128,16 @@ protected: void ref(); void unref(); #else + + void assign(const LLPointer& ptr) + { + if( mPointer != ptr.mPointer ) + { + unref(); + mPointer = ptr.mPointer; + ref(); + } + } void ref() { if (mPointer) @@ -156,9 +150,9 @@ protected: { if (mPointer) { - Type *tempp = mPointer; + Type *temp = mPointer; mPointer = NULL; - tempp->unref(); + temp->unref(); if (mPointer != NULL) { llwarns << "Unreference did assignment to non-NULL because of destructor" << llendl; @@ -171,4 +165,51 @@ protected: Type* mPointer; }; +template +class LLCopyOnWritePointer : public LLPointer +{ +public: + typedef LLPointer ref_pointer_t; + typedef LLCopyOnWritePointer self_t; + + LLCopyOnWritePointer() + { + } + + LLCopyOnWritePointer(Type* ptr) + : LLPointer(ptr) + { + } + + Type* write() + { + makeUnique(); + return mPointer; + } + + void makeUnique() + { + if (mPointer && mPointer->getNumRefs() > 1) + { + ref_pointer_t::assign(new Type(*mPointer)); + } + } + + using ref_pointer_t::operator BOOL; + using ref_pointer_t::operator bool; + using ref_pointer_t::operator!; + + using ref_pointer_t::operator !=; + using ref_pointer_t::operator ==; + using LLPointer::operator =; + + using LLPointer::operator <; + using LLPointer::operator >; + + + operator const Type*() const { return mPointer; } + const Type* operator->() const { return mPointer; } + +}; + #endif diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 0a35474b7f..9aa449d037 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -112,7 +112,7 @@ void LLQueuedThread::shutdown() // virtual S32 LLQueuedThread::update(F32 max_time_ms) { - LLThread::getTraceData()->pushToMaster(); + LLTrace::get_thread_trace()->pushToMaster(); if (!mStarted) { diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 7384842627..c705e5103b 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -67,7 +67,6 @@ U32 __thread LLThread::sThreadID = 0; #endif U32 LLThread::sIDIter = 0; -LLThreadLocalPtr LLThread::sTraceData; LL_COMMON_API void assert_main_thread() @@ -86,7 +85,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; - setTraceData(new LLTrace::SlaveThreadTrace()); + LLTrace::ThreadTrace* thread_trace = new LLTrace::SlaveThreadTrace(); #if !LL_DARWIN sThreadIndex = threadp->mID; @@ -100,8 +99,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap // We're done with the run function, this thread is done executing now. threadp->mStatus = STOPPED; - delete sTraceData.get(); - sTraceData = NULL; + delete thread_trace; return NULL; } @@ -314,12 +312,3 @@ void LLThread::wakeLocked() } } -LLTrace::ThreadTrace* LLThread::getTraceData() -{ - return sTraceData.get(); -} - -void LLThread::setTraceData( LLTrace::ThreadTrace* data ) -{ - sTraceData = data; -} diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 334ea2f0da..82ab5f47d2 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -32,10 +32,6 @@ #include "apr_thread_cond.h" #include "llmutex.h" -namespace LLTrace -{ - class ThreadTrace; -} class LL_COMMON_API LLThread { private: @@ -91,9 +87,6 @@ public: U32 getID() const { return mID; } - static LLTrace::ThreadTrace* getTraceData(); - static void setTraceData(LLTrace::ThreadTrace* data); - private: BOOL mPaused; @@ -110,8 +103,6 @@ protected: EThreadStatus mStatus; U32 mID; - static LLThreadLocalPtr sTraceData; - //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. // otherwise it will cause severe memory leaking!!! --bao diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index e487e450a9..04817fd4f4 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -27,7 +27,6 @@ #include "lltrace.h" #include "lltracesampler.h" -#include "llthread.h" namespace LLTrace { @@ -45,6 +44,12 @@ void cleanup() gMasterThreadTrace = NULL; } +LLThreadLocalPointer& get_thread_trace() +{ + static LLThreadLocalPointer s_trace_data; + return s_trace_data; + +} BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; @@ -62,36 +67,52 @@ MasterThreadTrace& getMasterThreadTrace() ThreadTrace::ThreadTrace() { - mPrimarySampler = createSampler(); - mPrimarySampler->makePrimary(); - mPrimarySampler->start(); + get_thread_trace() = this; + mPrimarySampler.makePrimary(); + mTotalSampler.start(); } ThreadTrace::ThreadTrace( const ThreadTrace& other ) -: mPrimarySampler(new Sampler(*(other.mPrimarySampler))) +: mPrimarySampler(other.mPrimarySampler), + mTotalSampler(other.mTotalSampler) { - mPrimarySampler->makePrimary(); + get_thread_trace() = this; + mPrimarySampler.makePrimary(); + mTotalSampler.start(); } ThreadTrace::~ThreadTrace() { - delete mPrimarySampler; + get_thread_trace() = NULL; } +//TODO: remove this and use llviewerstats sampler Sampler* ThreadTrace::getPrimarySampler() { - return mPrimarySampler; + return &mPrimarySampler; } void ThreadTrace::activate( Sampler* sampler ) { - flushPrimary(); - mActiveSamplers.push_back(sampler); + for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); + it != end_it; + ++it) + { + (*it)->mMeasurements.write()->mergeSamples(*mPrimarySampler.mMeasurements); + } + mPrimarySampler.mMeasurements.write()->reset(); + + sampler->initDeltas(mPrimarySampler); + + mActiveSamplers.push_front(sampler); } +//TODO: consider merging results down the list to one past the buffered item. +// this would require 2 buffers per sampler, to separate current total from running total + void ThreadTrace::deactivate( Sampler* sampler ) { - sampler->mergeFrom(mPrimarySampler); + sampler->mergeDeltas(mPrimarySampler); // TODO: replace with intrusive list std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); @@ -101,31 +122,12 @@ void ThreadTrace::deactivate( Sampler* sampler ) } } -void ThreadTrace::flushPrimary() -{ - for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); - it != end_it; - ++it) - { - (*it)->mergeFrom(mPrimarySampler); - } - mPrimarySampler->reset(); -} - -Sampler* ThreadTrace::createSampler() -{ - return new Sampler(this); -} - - - /////////////////////////////////////////////////////////////////////// // SlaveThreadTrace /////////////////////////////////////////////////////////////////////// SlaveThreadTrace::SlaveThreadTrace() -: ThreadTrace(getMasterThreadTrace()), - mSharedData(createSampler()) +: ThreadTrace(getMasterThreadTrace()) { getMasterThreadTrace().addSlaveThread(this); } @@ -137,34 +139,26 @@ SlaveThreadTrace::~SlaveThreadTrace() void SlaveThreadTrace::pushToMaster() { - mSharedData.copyFrom(mPrimarySampler); -} - -void SlaveThreadTrace::SharedData::copyFrom( Sampler* source ) -{ - LLMutexLock lock(&mSamplerMutex); - { - mSampler->mergeFrom(source); + mTotalSampler.stop(); + { + LLMutexLock(getMasterThreadTrace().getSlaveListMutex()); + mSharedData.copyFrom(mTotalSampler); } + mTotalSampler.start(); } -void SlaveThreadTrace::SharedData::copyTo( Sampler* sink ) +void SlaveThreadTrace::SharedData::copyFrom( const Sampler& source ) { LLMutexLock lock(&mSamplerMutex); - { - sink->mergeFrom(mSampler); - } + mSampler.mergeSamples(source); } -SlaveThreadTrace::SharedData::~SharedData() +void SlaveThreadTrace::SharedData::copyTo( Sampler& sink ) { - delete mSampler; + LLMutexLock lock(&mSamplerMutex); + sink.mergeSamples(mSampler); } -SlaveThreadTrace::SharedData::SharedData( Sampler* sampler ) : mSampler(sampler) -{} - - @@ -188,7 +182,7 @@ void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadTraces.push_back(new SlaveThreadTraceProxy(child, createSampler())); + mSlaveThreadTraces.push_back(new SlaveThreadTraceProxy(child)); } void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) @@ -211,22 +205,14 @@ void MasterThreadTrace::pushToMaster() {} MasterThreadTrace::MasterThreadTrace() -{ - LLThread::setTraceData(this); -} +{} /////////////////////////////////////////////////////////////////////// // MasterThreadTrace::SlaveThreadTraceProxy /////////////////////////////////////////////////////////////////////// -MasterThreadTrace::SlaveThreadTraceProxy::SlaveThreadTraceProxy( class SlaveThreadTrace* trace, Sampler* storage ) -: mSlaveTrace(trace), - mSamplerStorage(storage) +MasterThreadTrace::SlaveThreadTraceProxy::SlaveThreadTraceProxy( class SlaveThreadTrace* trace) +: mSlaveTrace(trace) {} -MasterThreadTrace::SlaveThreadTraceProxy::~SlaveThreadTraceProxy() -{ - delete mSamplerStorage; -} - } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index c6f920b5e4..5ec1c821c3 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -33,6 +33,8 @@ #include "llmutex.h" #include "llmemory.h" #include "lltimer.h" +#include "llrefcount.h" +#include "lltracesampler.h" #include @@ -48,11 +50,13 @@ namespace LLTrace void init(); void cleanup(); + LLThreadLocalPointer& get_thread_trace(); + class LL_COMMON_API MasterThreadTrace& getMasterThreadTrace(); // one per thread per type template - class LL_COMMON_API AccumulatorBuffer + class LL_COMMON_API AccumulatorBuffer : public LLRefCount { static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; private: @@ -88,13 +92,23 @@ namespace LLTrace return mStorage[index]; } - void mergeFrom(const AccumulatorBuffer& other) + void mergeSamples(const AccumulatorBuffer& other) { llassert(mNextStorageSlot == other.mNextStorageSlot); for (size_t i = 0; i < mNextStorageSlot; i++) { - mStorage[i].mergeFrom(other.mStorage[i]); + mStorage[i].mergeSamples(other.mStorage[i]); + } + } + + void mergeDeltas(const AccumulatorBuffer& start, const AccumulatorBuffer& finish) + { + llassert(mNextStorageSlot == start.mNextStorageSlot && mNextStorageSlot == finish.mNextStorageSlot); + + for (size_t i = 0; i < mNextStorageSlot; i++) + { + mStorage[i].mergeDeltas(start.mStorage[i], finish.mStorage[i]); } } @@ -119,6 +133,11 @@ namespace LLTrace sPrimaryStorage = mStorage; } + bool isPrimary() const + { + return sPrimaryStorage == mStorage; + } + LL_FORCE_INLINE static ACCUMULATOR* getPrimaryStorage() { return sPrimaryStorage.get(); @@ -149,9 +168,9 @@ namespace LLTrace ACCUMULATOR* mStorage; size_t mStorageSize; size_t mNextStorageSlot; - static LLThreadLocalPtr sPrimaryStorage; + static LLThreadLocalPointer sPrimaryStorage; }; - template LLThreadLocalPtr AccumulatorBuffer::sPrimaryStorage; + template LLThreadLocalPointer AccumulatorBuffer::sPrimaryStorage; template class LL_COMMON_API TraceType @@ -168,7 +187,7 @@ namespace LLTrace return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; } - ACCUMULATOR& getAccumulator(AccumulatorBuffer& buffer) { return buffer[mAccumulatorIndex]; } + ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) { return (*buffer)[mAccumulatorIndex]; } protected: std::string mName; @@ -177,10 +196,10 @@ namespace LLTrace template - class LL_COMMON_API StatAccumulator + class LL_COMMON_API MeasurementAccumulator { public: - StatAccumulator() + MeasurementAccumulator() : mSum(0), mMin(0), mMax(0), @@ -199,9 +218,12 @@ namespace LLTrace { mMax = value; } + F32 old_mean = mMean; + mMean += ((F32)value - old_mean) / (F32)mNumSamples; + mStandardDeviation += ((F32)value - old_mean) * ((F32)value - mMean); } - void mergeFrom(const StatAccumulator& other) + void mergeSamples(const MeasurementAccumulator& other) { mSum += other.mSum; if (other.mMin < mMin) @@ -213,6 +235,28 @@ namespace LLTrace mMax = other.mMax; } mNumSamples += other.mNumSamples; + F32 weight = (F32)mNumSamples / (F32)(mNumSamples + other.mNumSamples); + mMean = mMean * weight + other.mMean * (1.f - weight); + + F32 n_1 = (F32)mNumSamples, + n_2 = (F32)other.mNumSamples; + F32 m_1 = mMean, + m_2 = other.mMean; + F32 sd_1 = mStandardDeviation, + sd_2 = other.mStandardDeviation; + // combine variance (and hence standard deviation) of 2 different sized sample groups using + // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm + F32 variance = ((((n_1 - 1.f) * sd_1 * sd_1) + + ((n_2 - 1.f) * sd_2 * sd_2) + + (((n_1 * n_2) / (n_1 + n_2)) + * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) + / (n_1 + n_2 - 1.f)); + mStandardDeviation = sqrtf(variance); + } + + void mergeDeltas(const MeasurementAccumulator& start, const MeasurementAccumulator& finish) + { + llerrs << "Delta merge invalid for measurement accumulators" << llendl; } void reset() @@ -226,23 +270,68 @@ namespace LLTrace T getSum() { return mSum; } T getMin() { return mMin; } T getMax() { return mMax; } - T getMean() { return mSum / (T)mNumSamples; } + F32 getMean() { return mMean; } + F32 getStandardDeviation() { return mStandardDeviation; } private: T mSum, mMin, mMax; + F32 mMean, + mStandardDeviation; + + U32 mNumSamples; + }; + + template + class LL_COMMON_API RateAccumulator + { + public: + RateAccumulator() + : mSum(0), + mNumSamples(0) + {} + + LL_FORCE_INLINE void add(T value) + { + mNumSamples++; + mSum += value; + } + + void mergeSamples(const RateAccumulator& other) + { + mSum += other.mSum; + mNumSamples += other.mNumSamples; + } + + void mergeDeltas(const RateAccumulator& start, const RateAccumulator& finish) + { + mSum += finish.mSum - start.mSum; + mNumSamples += finish.mNumSamples - start.mNumSamples; + } + + void reset() + { + mNumSamples = 0; + mSum = 0; + } + + T getSum() { return mSum; } + + private: + T mSum; + U32 mNumSamples; }; template - class LL_COMMON_API Stat - : public TraceType >, - public LLInstanceTracker, std::string> + class LL_COMMON_API Measurement + : public TraceType >, + public LLInstanceTracker, std::string> { public: - Stat(const std::string& name) + Measurement(const std::string& name) : TraceType(name), LLInstanceTracker(name) {} @@ -253,11 +342,30 @@ namespace LLTrace } }; - struct LL_COMMON_API TimerAccumulator + template + class LL_COMMON_API Rate + : public TraceType >, + public LLInstanceTracker, std::string> { + public: + Rate(const std::string& name) + : TraceType(name), + LLInstanceTracker(name) + {} + + void add(T value) + { + getPrimaryAccumulator().add(value); + } + }; + + class LL_COMMON_API TimerAccumulator + { + public: U32 mTotalTimeCounter, mChildTimeCounter, mCalls; + TimerAccumulator* mParent; // info for caller timer TimerAccumulator* mLastCaller; // used to bootstrap tree construction const class BlockTimer* mTimer; // points to block timer associated with this storage @@ -265,13 +373,20 @@ namespace LLTrace bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame std::vector mChildren; // currently assumed child timers - void mergeFrom(const TimerAccumulator& other) + void mergeSamples(const TimerAccumulator& other) { mTotalTimeCounter += other.mTotalTimeCounter; mChildTimeCounter += other.mChildTimeCounter; mCalls += other.mCalls; } + void mergeDeltas(const TimerAccumulator& start, const TimerAccumulator& finish) + { + mTotalTimeCounter += finish.mTotalTimeCounter - start.mTotalTimeCounter; + mChildTimeCounter += finish.mChildTimeCounter - start.mChildTimeCounter; + mCalls += finish.mCalls - start.mCalls; + } + void reset() { mTotalTimeCounter = 0; @@ -377,15 +492,13 @@ namespace LLTrace void activate(Sampler* sampler); void deactivate(Sampler* sampler); - void flushPrimary(); - - Sampler* createSampler(); virtual void pushToMaster() = 0; Sampler* getPrimarySampler(); protected: - Sampler* mPrimarySampler; + Sampler mPrimarySampler; + Sampler mTotalSampler; std::list mActiveSamplers; }; @@ -402,14 +515,15 @@ namespace LLTrace // call this periodically to gather stats data from slave threads void pullFromSlaveThreads(); + LLMutex* getSlaveListMutex() { return &mSlaveListMutex; } + private: struct SlaveThreadTraceProxy { - SlaveThreadTraceProxy(class SlaveThreadTrace* trace, Sampler* storage); + SlaveThreadTraceProxy(class SlaveThreadTrace* trace); - ~SlaveThreadTraceProxy(); class SlaveThreadTrace* mSlaveTrace; - Sampler* mSamplerStorage; + Sampler mSamplerStorage; private: //no need to copy these and then have to duplicate the storage SlaveThreadTraceProxy(const SlaveThreadTraceProxy& other) {} @@ -431,24 +545,16 @@ namespace LLTrace MasterThreadTrace* mMaster; - // this data is accessed by other threads, so give it a 64 byte alignment - // to avoid false sharing on most x86 processors - LL_ALIGNED(64) class SharedData + class SharedData { public: - explicit - SharedData(Sampler* sampler); - - ~SharedData(); - - void copyFrom(Sampler* source); - void copyTo(Sampler* sink); + void copyFrom(const Sampler& source); + void copyTo(Sampler& sink); private: - // add a cache line's worth of unused space to avoid any potential of false sharing - LLMutex mSamplerMutex; - Sampler* mSampler; + LLMutex mSamplerMutex; + Sampler mSampler; }; - SharedData mSharedData; + SharedData mSharedData; }; } diff --git a/indra/llcommon/lltracesampler.cpp b/indra/llcommon/lltracesampler.cpp index 0cf01d7a3a..17e58b96e2 100644 --- a/indra/llcommon/lltracesampler.cpp +++ b/indra/llcommon/lltracesampler.cpp @@ -26,6 +26,8 @@ #include "linden_common.h" #include "lltracesampler.h" +#include "lltrace.h" +#include "llthread.h" namespace LLTrace { @@ -34,10 +36,14 @@ namespace LLTrace // Sampler /////////////////////////////////////////////////////////////////////// -Sampler::Sampler(ThreadTrace* thread_trace) +Sampler::Sampler() : mElapsedSeconds(0), mIsStarted(false), - mThreadTrace(thread_trace) + mRatesStart(new AccumulatorBuffer >()), + mRates(new AccumulatorBuffer >()), + mMeasurements(new AccumulatorBuffer >()), + mStackTimers(new AccumulatorBuffer()), + mStackTimersStart(new AccumulatorBuffer()) { } @@ -53,9 +59,9 @@ void Sampler::start() void Sampler::reset() { - mF32Stats.reset(); - mS32Stats.reset(); - mStackTimers.reset(); + mRates.write()->reset(); + mMeasurements.write()->reset(); + mStackTimers.write()->reset(); mElapsedSeconds = 0.0; mSamplingTimer.reset(); @@ -66,7 +72,7 @@ void Sampler::resume() if (!mIsStarted) { mSamplingTimer.reset(); - getThreadTrace()->activate(this); + LLTrace::get_thread_trace()->activate(this); mIsStarted = true; } } @@ -76,28 +82,86 @@ void Sampler::stop() if (mIsStarted) { mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - getThreadTrace()->deactivate(this); + LLTrace::get_thread_trace()->deactivate(this); mIsStarted = false; } } -ThreadTrace* Sampler::getThreadTrace() + +void Sampler::makePrimary() { - return mThreadTrace; + mRates.write()->makePrimary(); + mMeasurements.write()->makePrimary(); + mStackTimers.write()->makePrimary(); } -void Sampler::makePrimary() +bool Sampler::isPrimary() +{ + return mRates->isPrimary(); +} + +void Sampler::mergeSamples( const Sampler& other ) +{ + mRates.write()->mergeSamples(*other.mRates); + mMeasurements.write()->mergeSamples(*other.mMeasurements); + mStackTimers.write()->mergeSamples(*other.mStackTimers); +} + +void Sampler::initDeltas( const Sampler& other ) +{ + mRatesStart.write()->copyFrom(*other.mRates); + mStackTimersStart.write()->copyFrom(*other.mStackTimers); +} + + +void Sampler::mergeDeltas( const Sampler& other ) +{ + mRates.write()->mergeDeltas(*mRatesStart, *other.mRates); + mStackTimers.write()->mergeDeltas(*mStackTimersStart, *other.mStackTimers); + mMeasurements.write()->mergeSamples(*other.mMeasurements); +} + + +F32 Sampler::getSum( Rate& stat ) { - mF32Stats.makePrimary(); - mS32Stats.makePrimary(); - mStackTimers.makePrimary(); + return stat.getAccumulator(mRates).getSum(); } -void Sampler::mergeFrom( const Sampler* other ) +F32 Sampler::getSum( Measurement& stat ) { - mF32Stats.mergeFrom(other->mF32Stats); - mS32Stats.mergeFrom(other->mS32Stats); - mStackTimers.mergeFrom(other->mStackTimers); + return stat.getAccumulator(mMeasurements).getSum(); } + +F32 Sampler::getPerSec( Rate& stat ) +{ + return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; +} + +F32 Sampler::getMin( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMin(); +} + +F32 Sampler::getMax( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMax(); +} + +F32 Sampler::getMean( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMean(); +} + +F32 Sampler::getStandardDeviation( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getStandardDeviation(); +} + + + + + + + } diff --git a/indra/llcommon/lltracesampler.h b/indra/llcommon/lltracesampler.h index d1ca7fc9bb..e3498fb39f 100644 --- a/indra/llcommon/lltracesampler.h +++ b/indra/llcommon/lltracesampler.h @@ -30,61 +30,70 @@ #include "stdtypes.h" #include "llpreprocessor.h" -#include "lltrace.h" +#include "llpointer.h" +#include "lltimer.h" namespace LLTrace { + template class Rate; + template class Measurement; + template class AccumulatorBuffer; + template class RateAccumulator; + template class MeasurementAccumulator; + class TimerAccumulator; + class LL_COMMON_API Sampler { public: + Sampler(); + ~Sampler(); void makePrimary(); + bool isPrimary(); void start(); void stop(); void resume(); - void mergeFrom(const Sampler* other); + void mergeSamples(const Sampler& other); + void initDeltas(const Sampler& other); + void mergeDeltas(const Sampler& other); void reset(); bool isStarted() { return mIsStarted; } - F32 getSum(Stat& stat) { return stat.getAccumulator(mF32Stats).getSum(); } - F32 getMin(Stat& stat) { return stat.getAccumulator(mF32Stats).getMin(); } - F32 getMax(Stat& stat) { return stat.getAccumulator(mF32Stats).getMax(); } - F32 getMean(Stat& stat) { return stat.getAccumulator(mF32Stats).getMean(); } + F32 getSum(Rate& stat); + F32 getPerSec(Rate& stat); - S32 getSum(Stat& stat) { return stat.getAccumulator(mS32Stats).getSum(); } - S32 getMin(Stat& stat) { return stat.getAccumulator(mS32Stats).getMin(); } - S32 getMax(Stat& stat) { return stat.getAccumulator(mS32Stats).getMax(); } - S32 getMean(Stat& stat) { return stat.getAccumulator(mS32Stats).getMean(); } + F32 getSum(Measurement& stat); + F32 getMin(Measurement& stat); + F32 getMax(Measurement& stat); + F32 getMean(Measurement& stat); + F32 getStandardDeviation(Measurement& stat); F64 getSampleTime() { return mElapsedSeconds; } private: friend class ThreadTrace; - Sampler(class ThreadTrace* thread_trace); - - // no copy - Sampler(const Sampler& other) {} // returns data for current thread class ThreadTrace* getThreadTrace(); - //TODO: take snapshot at sampler start so we can simplify updates - //AccumulatorBuffer > mF32StatsStart; - //AccumulatorBuffer > mS32StatsStart; - //AccumulatorBuffer mStackTimersStart; + LLCopyOnWritePointer > > mRatesStart; + LLCopyOnWritePointer > > mRates; + LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > mStackTimersStart; + LLCopyOnWritePointer > mStackTimers; - AccumulatorBuffer > mF32Stats; - AccumulatorBuffer > mS32Stats; - AccumulatorBuffer mStackTimers; + bool mIsStarted; + LLTimer mSamplingTimer; + F64 mElapsedSeconds; + }; + + class LL_COMMON_API PeriodicSampler + { - bool mIsStarted; - LLTimer mSamplingTimer; - F64 mElapsedSeconds; - ThreadTrace* mThreadTrace; }; } -- cgit v1.2.3 From dbe9742703cf14db85ec3d16c540efc68dce95a6 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 2 Oct 2012 15:37:16 -0700 Subject: SH-3404 create sampler class renamed LLTrace::ThreadTrace to LLTrace::ThreadRecorder renamed LLTrace::Sampler to LLTrace::Recording --- indra/llcommon/CMakeLists.txt | 4 +- indra/llcommon/llapr.cpp | 23 ----- indra/llcommon/llapr.h | 26 +++++- indra/llcommon/llqueuedthread.cpp | 2 +- indra/llcommon/llthread.cpp | 4 +- indra/llcommon/lltrace.cpp | 143 +++++++++++++++--------------- indra/llcommon/lltrace.h | 66 +++++++------- indra/llcommon/lltracerecording.cpp | 167 ++++++++++++++++++++++++++++++++++++ indra/llcommon/lltracerecording.h | 100 +++++++++++++++++++++ indra/llcommon/lltracesampler.cpp | 167 ------------------------------------ indra/llcommon/lltracesampler.h | 100 --------------------- 11 files changed, 397 insertions(+), 405 deletions(-) create mode 100644 indra/llcommon/lltracerecording.cpp create mode 100644 indra/llcommon/lltracerecording.h delete mode 100644 indra/llcommon/lltracesampler.cpp delete mode 100644 indra/llcommon/lltracesampler.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index e10dbb3e4d..1ccee23e1e 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -101,7 +101,7 @@ set(llcommon_SOURCE_FILES llthreadsafequeue.cpp lltimer.cpp lltrace.cpp - lltracesampler.cpp + lltracerecording.cpp lluri.cpp lluuid.cpp llworkerthread.cpp @@ -244,7 +244,7 @@ set(llcommon_HEADER_FILES llthreadsafequeue.h lltimer.h lltrace.h - lltracesampler.h + lltracerecording.h lltreeiterators.h lltypeinfolookup.h lluri.h diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index d23b70690d..1db3aa9e89 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -486,29 +486,6 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) // bool LLThreadLocalPointerBase::sInitialized = false; -LLThreadLocalPointerBase::LLThreadLocalPointerBase() -: mThreadKey(NULL) -{ - if (sInitialized) - { - initStorage(); - } -} - -LLThreadLocalPointerBase::LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) -: mThreadKey(NULL) -{ - if (sInitialized) - { - initStorage(); - } -} - -LLThreadLocalPointerBase::~LLThreadLocalPointerBase() -{ - destroyStorage(); -} - void LLThreadLocalPointerBase::set( void* value ) { llassert(sInitialized && mThreadKey); diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 6efb44a663..821274aeb3 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -261,9 +261,28 @@ public: class LLThreadLocalPointerBase : LLInstanceTracker { public: - LLThreadLocalPointerBase(); - LLThreadLocalPointerBase(const LLThreadLocalPointerBase& other); - ~LLThreadLocalPointerBase(); + LLThreadLocalPointerBase() + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + ~LLThreadLocalPointerBase() + { + destroyStorage(); + } static void initAllThreadLocalStorage(); static void destroyAllThreadLocalStorage(); @@ -312,7 +331,6 @@ class LLThreadLocalPointer : public LLThreadLocalPointerBase public: LLThreadLocalPointer() - : LLThreadLocalPointerBase() {} explicit LLThreadLocalPointer(T* value) diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 9aa449d037..6e2a2b140f 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -112,7 +112,7 @@ void LLQueuedThread::shutdown() // virtual S32 LLQueuedThread::update(F32 max_time_ms) { - LLTrace::get_thread_trace()->pushToMaster(); + LLTrace::get_thread_recorder()->pushToMaster(); if (!mStarted) { diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index c705e5103b..6723e427f5 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -85,7 +85,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; - LLTrace::ThreadTrace* thread_trace = new LLTrace::SlaveThreadTrace(); + LLTrace::ThreadRecorder* thread_recorder = new LLTrace::SlaveThreadRecorder(); #if !LL_DARWIN sThreadIndex = threadp->mID; @@ -99,7 +99,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap // We're done with the run function, this thread is done executing now. threadp->mStatus = STOPPED; - delete thread_trace; + delete thread_recorder; return NULL; } diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 04817fd4f4..6b4c3aeb06 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -26,28 +26,28 @@ #include "linden_common.h" #include "lltrace.h" -#include "lltracesampler.h" +#include "lltracerecording.h" namespace LLTrace { -static MasterThreadTrace* gMasterThreadTrace = NULL; +static MasterThreadRecorder* gMasterThreadRecorder = NULL; void init() { - gMasterThreadTrace = new MasterThreadTrace(); + gMasterThreadRecorder = new MasterThreadRecorder(); } void cleanup() { - delete gMasterThreadTrace; - gMasterThreadTrace = NULL; + delete gMasterThreadRecorder; + gMasterThreadRecorder = NULL; } -LLThreadLocalPointer& get_thread_trace() +LLThreadLocalPointer& get_thread_recorder() { - static LLThreadLocalPointer s_trace_data; - return s_trace_data; + static LLThreadLocalPointer s_thread_recorder; + return s_thread_recorder; } @@ -55,164 +55,161 @@ BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; -MasterThreadTrace& getMasterThreadTrace() +MasterThreadRecorder& getMasterThreadRecorder() { - llassert(gMasterThreadTrace != NULL); - return *gMasterThreadTrace; + llassert(gMasterThreadRecorder != NULL); + return *gMasterThreadRecorder; } /////////////////////////////////////////////////////////////////////// -// MasterThreadTrace +// ThreadRecorder /////////////////////////////////////////////////////////////////////// -ThreadTrace::ThreadTrace() +ThreadRecorder::ThreadRecorder() { - get_thread_trace() = this; - mPrimarySampler.makePrimary(); - mTotalSampler.start(); + get_thread_recorder() = this; + mPrimaryRecording.makePrimary(); + mFullRecording.start(); } -ThreadTrace::ThreadTrace( const ThreadTrace& other ) -: mPrimarySampler(other.mPrimarySampler), - mTotalSampler(other.mTotalSampler) +ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) +: mPrimaryRecording(other.mPrimaryRecording), + mFullRecording(other.mFullRecording) { - get_thread_trace() = this; - mPrimarySampler.makePrimary(); - mTotalSampler.start(); + get_thread_recorder() = this; + mPrimaryRecording.makePrimary(); + mFullRecording.start(); } -ThreadTrace::~ThreadTrace() +ThreadRecorder::~ThreadRecorder() { - get_thread_trace() = NULL; + get_thread_recorder() = NULL; } -//TODO: remove this and use llviewerstats sampler -Sampler* ThreadTrace::getPrimarySampler() +//TODO: remove this and use llviewerstats recording +Recording* ThreadRecorder::getPrimaryRecording() { - return &mPrimarySampler; + return &mPrimaryRecording; } -void ThreadTrace::activate( Sampler* sampler ) +void ThreadRecorder::activate( Recording* recorder ) { - for (std::list::iterator it = mActiveSamplers.begin(), end_it = mActiveSamplers.end(); + for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); it != end_it; ++it) { - (*it)->mMeasurements.write()->mergeSamples(*mPrimarySampler.mMeasurements); + (*it)->mMeasurements.write()->mergeSamples(*mPrimaryRecording.mMeasurements); } - mPrimarySampler.mMeasurements.write()->reset(); + mPrimaryRecording.mMeasurements.write()->reset(); - sampler->initDeltas(mPrimarySampler); + recorder->initDeltas(mPrimaryRecording); - mActiveSamplers.push_front(sampler); + mActiveRecordings.push_front(recorder); } //TODO: consider merging results down the list to one past the buffered item. // this would require 2 buffers per sampler, to separate current total from running total -void ThreadTrace::deactivate( Sampler* sampler ) +void ThreadRecorder::deactivate( Recording* recorder ) { - sampler->mergeDeltas(mPrimarySampler); + recorder->mergeDeltas(mPrimaryRecording); // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mActiveSamplers.begin(), mActiveSamplers.end(), sampler); - if (found_it != mActiveSamplers.end()) + std::list::iterator found_it = std::find(mActiveRecordings.begin(), mActiveRecordings.end(), recorder); + if (found_it != mActiveRecordings.end()) { - mActiveSamplers.erase(found_it); + mActiveRecordings.erase(found_it); } } /////////////////////////////////////////////////////////////////////// -// SlaveThreadTrace +// SlaveThreadRecorder /////////////////////////////////////////////////////////////////////// -SlaveThreadTrace::SlaveThreadTrace() -: ThreadTrace(getMasterThreadTrace()) +SlaveThreadRecorder::SlaveThreadRecorder() +: ThreadRecorder(getMasterThreadRecorder()) { - getMasterThreadTrace().addSlaveThread(this); + getMasterThreadRecorder().addSlaveThread(this); } -SlaveThreadTrace::~SlaveThreadTrace() +SlaveThreadRecorder::~SlaveThreadRecorder() { - getMasterThreadTrace().removeSlaveThread(this); + getMasterThreadRecorder().removeSlaveThread(this); } -void SlaveThreadTrace::pushToMaster() +void SlaveThreadRecorder::pushToMaster() { - mTotalSampler.stop(); + mFullRecording.stop(); { - LLMutexLock(getMasterThreadTrace().getSlaveListMutex()); - mSharedData.copyFrom(mTotalSampler); + LLMutexLock(getMasterThreadRecorder().getSlaveListMutex()); + mSharedData.copyFrom(mFullRecording); } - mTotalSampler.start(); + mFullRecording.start(); } -void SlaveThreadTrace::SharedData::copyFrom( const Sampler& source ) +void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) { - LLMutexLock lock(&mSamplerMutex); - mSampler.mergeSamples(source); + LLMutexLock lock(&mRecorderMutex); + mRecorder.mergeSamples(source); } -void SlaveThreadTrace::SharedData::copyTo( Sampler& sink ) +void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) { - LLMutexLock lock(&mSamplerMutex); - sink.mergeSamples(mSampler); + LLMutexLock lock(&mRecorderMutex); + sink.mergeSamples(mRecorder); } - - - /////////////////////////////////////////////////////////////////////// -// MasterThreadTrace +// MasterThreadRecorder /////////////////////////////////////////////////////////////////////// -void MasterThreadTrace::pullFromSlaveThreads() +void MasterThreadRecorder::pullFromSlaveThreads() { LLMutexLock lock(&mSlaveListMutex); - for (slave_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) { - (*it)->mSlaveTrace->mSharedData.copyTo((*it)->mSamplerStorage); + (*it)->mRecorder->mSharedData.copyTo((*it)->mSlaveRecording); } } -void MasterThreadTrace::addSlaveThread( class SlaveThreadTrace* child ) +void MasterThreadRecorder::addSlaveThread( class SlaveThreadRecorder* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadTraces.push_back(new SlaveThreadTraceProxy(child)); + mSlaveThreadRecorders.push_back(new SlaveThreadRecorderProxy(child)); } -void MasterThreadTrace::removeSlaveThread( class SlaveThreadTrace* child ) +void MasterThreadRecorder::removeSlaveThread( class SlaveThreadRecorder* child ) { LLMutexLock lock(&mSlaveListMutex); - for (slave_thread_trace_list_t::iterator it = mSlaveThreadTraces.begin(), end_it = mSlaveThreadTraces.end(); + for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) { - if ((*it)->mSlaveTrace == child) + if ((*it)->mRecorder == child) { - mSlaveThreadTraces.erase(it); + mSlaveThreadRecorders.erase(it); break; } } } -void MasterThreadTrace::pushToMaster() +void MasterThreadRecorder::pushToMaster() {} -MasterThreadTrace::MasterThreadTrace() +MasterThreadRecorder::MasterThreadRecorder() {} /////////////////////////////////////////////////////////////////////// -// MasterThreadTrace::SlaveThreadTraceProxy +// MasterThreadRecorder::SlaveThreadTraceProxy /////////////////////////////////////////////////////////////////////// -MasterThreadTrace::SlaveThreadTraceProxy::SlaveThreadTraceProxy( class SlaveThreadTrace* trace) -: mSlaveTrace(trace) +MasterThreadRecorder::SlaveThreadRecorderProxy::SlaveThreadRecorderProxy( class SlaveThreadRecorder* recorder) +: mRecorder(recorder) {} } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 5ec1c821c3..c5356777ae 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -34,7 +34,7 @@ #include "llmemory.h" #include "lltimer.h" #include "llrefcount.h" -#include "lltracesampler.h" +#include "lltracerecording.h" #include @@ -45,14 +45,14 @@ namespace LLTrace { - class Sampler; + class Recording; void init(); void cleanup(); - LLThreadLocalPointer& get_thread_trace(); + LLThreadLocalPointer& get_thread_recorder(); - class LL_COMMON_API MasterThreadTrace& getMasterThreadTrace(); + class LL_COMMON_API MasterThreadRecorder& getMasterThreadRecorder(); // one per thread per type template @@ -482,33 +482,33 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; - class LL_COMMON_API ThreadTrace + class LL_COMMON_API ThreadRecorder { public: - ThreadTrace(); - ThreadTrace(const ThreadTrace& other); + ThreadRecorder(); + ThreadRecorder(const ThreadRecorder& other); - virtual ~ThreadTrace(); + virtual ~ThreadRecorder(); - void activate(Sampler* sampler); - void deactivate(Sampler* sampler); + void activate(Recording* recording); + void deactivate(Recording* recording); virtual void pushToMaster() = 0; - Sampler* getPrimarySampler(); + Recording* getPrimaryRecording(); protected: - Sampler mPrimarySampler; - Sampler mTotalSampler; - std::list mActiveSamplers; + Recording mPrimaryRecording; + Recording mFullRecording; + std::list mActiveRecordings; }; - class LL_COMMON_API MasterThreadTrace : public ThreadTrace + class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder { public: - MasterThreadTrace(); + MasterThreadRecorder(); - void addSlaveThread(class SlaveThreadTrace* child); - void removeSlaveThread(class SlaveThreadTrace* child); + void addSlaveThread(class SlaveThreadRecorder* child); + void removeSlaveThread(class SlaveThreadRecorder* child); /*virtual */ void pushToMaster(); @@ -518,41 +518,41 @@ namespace LLTrace LLMutex* getSlaveListMutex() { return &mSlaveListMutex; } private: - struct SlaveThreadTraceProxy + struct SlaveThreadRecorderProxy { - SlaveThreadTraceProxy(class SlaveThreadTrace* trace); + SlaveThreadRecorderProxy(class SlaveThreadRecorder* recorder); - class SlaveThreadTrace* mSlaveTrace; - Sampler mSamplerStorage; + class SlaveThreadRecorder* mRecorder; + Recording mSlaveRecording; private: //no need to copy these and then have to duplicate the storage - SlaveThreadTraceProxy(const SlaveThreadTraceProxy& other) {} + SlaveThreadRecorderProxy(const SlaveThreadRecorderProxy& other) {} }; - typedef std::list slave_thread_trace_list_t; + typedef std::list slave_thread_recorder_list_t; - slave_thread_trace_list_t mSlaveThreadTraces; + slave_thread_recorder_list_t mSlaveThreadRecorders; LLMutex mSlaveListMutex; }; - class LL_COMMON_API SlaveThreadTrace : public ThreadTrace + class LL_COMMON_API SlaveThreadRecorder : public ThreadRecorder { public: - SlaveThreadTrace(); - ~SlaveThreadTrace(); + SlaveThreadRecorder(); + ~SlaveThreadRecorder(); // call this periodically to gather stats data for master thread to consume /*virtual*/ void pushToMaster(); - MasterThreadTrace* mMaster; + MasterThreadRecorder* mMaster; class SharedData { public: - void copyFrom(const Sampler& source); - void copyTo(Sampler& sink); + void copyFrom(const Recording& source); + void copyTo(Recording& sink); private: - LLMutex mSamplerMutex; - Sampler mSampler; + LLMutex mRecorderMutex; + Recording mRecorder; }; SharedData mSharedData; }; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp new file mode 100644 index 0000000000..a792d40f9d --- /dev/null +++ b/indra/llcommon/lltracerecording.cpp @@ -0,0 +1,167 @@ +/** + * @file lltracesampler.cpp + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltracerecording.h" +#include "lltrace.h" +#include "llthread.h" + +namespace LLTrace +{ + +/////////////////////////////////////////////////////////////////////// +// Recording +/////////////////////////////////////////////////////////////////////// + +Recording::Recording() +: mElapsedSeconds(0), + mIsStarted(false), + mRatesStart(new AccumulatorBuffer >()), + mRates(new AccumulatorBuffer >()), + mMeasurements(new AccumulatorBuffer >()), + mStackTimers(new AccumulatorBuffer()), + mStackTimersStart(new AccumulatorBuffer()) +{ +} + +Recording::~Recording() +{ +} + +void Recording::start() +{ + reset(); + resume(); +} + +void Recording::reset() +{ + mRates.write()->reset(); + mMeasurements.write()->reset(); + mStackTimers.write()->reset(); + + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); +} + +void Recording::resume() +{ + if (!mIsStarted) + { + mSamplingTimer.reset(); + LLTrace::get_thread_recorder()->activate(this); + mIsStarted = true; + } +} + +void Recording::stop() +{ + if (mIsStarted) + { + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::get_thread_recorder()->deactivate(this); + mIsStarted = false; + } +} + + +void Recording::makePrimary() +{ + mRates.write()->makePrimary(); + mMeasurements.write()->makePrimary(); + mStackTimers.write()->makePrimary(); +} + +bool Recording::isPrimary() +{ + return mRates->isPrimary(); +} + +void Recording::mergeSamples( const Recording& other ) +{ + mRates.write()->mergeSamples(*other.mRates); + mMeasurements.write()->mergeSamples(*other.mMeasurements); + mStackTimers.write()->mergeSamples(*other.mStackTimers); +} + +void Recording::initDeltas( const Recording& other ) +{ + mRatesStart.write()->copyFrom(*other.mRates); + mStackTimersStart.write()->copyFrom(*other.mStackTimers); +} + + +void Recording::mergeDeltas( const Recording& other ) +{ + mRates.write()->mergeDeltas(*mRatesStart, *other.mRates); + mStackTimers.write()->mergeDeltas(*mStackTimersStart, *other.mStackTimers); + mMeasurements.write()->mergeSamples(*other.mMeasurements); +} + + +F32 Recording::getSum( Rate& stat ) +{ + return stat.getAccumulator(mRates).getSum(); +} + +F32 Recording::getSum( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getSum(); +} + + +F32 Recording::getPerSec( Rate& stat ) +{ + return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; +} + +F32 Recording::getMin( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMin(); +} + +F32 Recording::getMax( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMax(); +} + +F32 Recording::getMean( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getMean(); +} + +F32 Recording::getStandardDeviation( Measurement& stat ) +{ + return stat.getAccumulator(mMeasurements).getStandardDeviation(); +} + + + + + + + +} diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h new file mode 100644 index 0000000000..83dc503ea6 --- /dev/null +++ b/indra/llcommon/lltracerecording.h @@ -0,0 +1,100 @@ +/** + * @file lltracerecording.h + * @brief Sampling object for collecting runtime statistics originating from lltrace. + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTRACERECORDING_H +#define LL_LLTRACERECORDING_H + +#include "stdtypes.h" +#include "llpreprocessor.h" + +#include "llpointer.h" +#include "lltimer.h" + +namespace LLTrace +{ + template class Rate; + template class Measurement; + template class AccumulatorBuffer; + template class RateAccumulator; + template class MeasurementAccumulator; + class TimerAccumulator; + + class LL_COMMON_API Recording + { + public: + Recording(); + + ~Recording(); + + void makePrimary(); + bool isPrimary(); + + void start(); + void stop(); + void resume(); + + void mergeSamples(const Recording& other); + void initDeltas(const Recording& other); + void mergeDeltas(const Recording& other); + + void reset(); + + bool isStarted() { return mIsStarted; } + + F32 getSum(Rate& stat); + F32 getPerSec(Rate& stat); + + F32 getSum(Measurement& stat); + F32 getMin(Measurement& stat); + F32 getMax(Measurement& stat); + F32 getMean(Measurement& stat); + F32 getStandardDeviation(Measurement& stat); + + F64 getSampleTime() { return mElapsedSeconds; } + + private: + friend class ThreadRecorder; + // returns data for current thread + class ThreadRecorder* getThreadRecorder(); + + LLCopyOnWritePointer > > mRatesStart; + LLCopyOnWritePointer > > mRates; + LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > mStackTimersStart; + LLCopyOnWritePointer > mStackTimers; + + bool mIsStarted; + LLTimer mSamplingTimer; + F64 mElapsedSeconds; + }; + + class LL_COMMON_API PeriodicRecording + { + + }; +} + +#endif // LL_LLTRACERECORDING_H diff --git a/indra/llcommon/lltracesampler.cpp b/indra/llcommon/lltracesampler.cpp deleted file mode 100644 index 17e58b96e2..0000000000 --- a/indra/llcommon/lltracesampler.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/** - * @file lltracesampler.cpp - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "lltracesampler.h" -#include "lltrace.h" -#include "llthread.h" - -namespace LLTrace -{ - -/////////////////////////////////////////////////////////////////////// -// Sampler -/////////////////////////////////////////////////////////////////////// - -Sampler::Sampler() -: mElapsedSeconds(0), - mIsStarted(false), - mRatesStart(new AccumulatorBuffer >()), - mRates(new AccumulatorBuffer >()), - mMeasurements(new AccumulatorBuffer >()), - mStackTimers(new AccumulatorBuffer()), - mStackTimersStart(new AccumulatorBuffer()) -{ -} - -Sampler::~Sampler() -{ -} - -void Sampler::start() -{ - reset(); - resume(); -} - -void Sampler::reset() -{ - mRates.write()->reset(); - mMeasurements.write()->reset(); - mStackTimers.write()->reset(); - - mElapsedSeconds = 0.0; - mSamplingTimer.reset(); -} - -void Sampler::resume() -{ - if (!mIsStarted) - { - mSamplingTimer.reset(); - LLTrace::get_thread_trace()->activate(this); - mIsStarted = true; - } -} - -void Sampler::stop() -{ - if (mIsStarted) - { - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - LLTrace::get_thread_trace()->deactivate(this); - mIsStarted = false; - } -} - - -void Sampler::makePrimary() -{ - mRates.write()->makePrimary(); - mMeasurements.write()->makePrimary(); - mStackTimers.write()->makePrimary(); -} - -bool Sampler::isPrimary() -{ - return mRates->isPrimary(); -} - -void Sampler::mergeSamples( const Sampler& other ) -{ - mRates.write()->mergeSamples(*other.mRates); - mMeasurements.write()->mergeSamples(*other.mMeasurements); - mStackTimers.write()->mergeSamples(*other.mStackTimers); -} - -void Sampler::initDeltas( const Sampler& other ) -{ - mRatesStart.write()->copyFrom(*other.mRates); - mStackTimersStart.write()->copyFrom(*other.mStackTimers); -} - - -void Sampler::mergeDeltas( const Sampler& other ) -{ - mRates.write()->mergeDeltas(*mRatesStart, *other.mRates); - mStackTimers.write()->mergeDeltas(*mStackTimersStart, *other.mStackTimers); - mMeasurements.write()->mergeSamples(*other.mMeasurements); -} - - -F32 Sampler::getSum( Rate& stat ) -{ - return stat.getAccumulator(mRates).getSum(); -} - -F32 Sampler::getSum( Measurement& stat ) -{ - return stat.getAccumulator(mMeasurements).getSum(); -} - - -F32 Sampler::getPerSec( Rate& stat ) -{ - return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; -} - -F32 Sampler::getMin( Measurement& stat ) -{ - return stat.getAccumulator(mMeasurements).getMin(); -} - -F32 Sampler::getMax( Measurement& stat ) -{ - return stat.getAccumulator(mMeasurements).getMax(); -} - -F32 Sampler::getMean( Measurement& stat ) -{ - return stat.getAccumulator(mMeasurements).getMean(); -} - -F32 Sampler::getStandardDeviation( Measurement& stat ) -{ - return stat.getAccumulator(mMeasurements).getStandardDeviation(); -} - - - - - - - -} diff --git a/indra/llcommon/lltracesampler.h b/indra/llcommon/lltracesampler.h deleted file mode 100644 index e3498fb39f..0000000000 --- a/indra/llcommon/lltracesampler.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file lltracesampler.h - * @brief Sampling object for collecting runtime statistics originating from lltrace. - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2012, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLTRACESAMPLER_H -#define LL_LLTRACESAMPLER_H - -#include "stdtypes.h" -#include "llpreprocessor.h" - -#include "llpointer.h" -#include "lltimer.h" - -namespace LLTrace -{ - template class Rate; - template class Measurement; - template class AccumulatorBuffer; - template class RateAccumulator; - template class MeasurementAccumulator; - class TimerAccumulator; - - class LL_COMMON_API Sampler - { - public: - Sampler(); - - ~Sampler(); - - void makePrimary(); - bool isPrimary(); - - void start(); - void stop(); - void resume(); - - void mergeSamples(const Sampler& other); - void initDeltas(const Sampler& other); - void mergeDeltas(const Sampler& other); - - void reset(); - - bool isStarted() { return mIsStarted; } - - F32 getSum(Rate& stat); - F32 getPerSec(Rate& stat); - - F32 getSum(Measurement& stat); - F32 getMin(Measurement& stat); - F32 getMax(Measurement& stat); - F32 getMean(Measurement& stat); - F32 getStandardDeviation(Measurement& stat); - - F64 getSampleTime() { return mElapsedSeconds; } - - private: - friend class ThreadTrace; - // returns data for current thread - class ThreadTrace* getThreadTrace(); - - LLCopyOnWritePointer > > mRatesStart; - LLCopyOnWritePointer > > mRates; - LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimersStart; - LLCopyOnWritePointer > mStackTimers; - - bool mIsStarted; - LLTimer mSamplingTimer; - F64 mElapsedSeconds; - }; - - class LL_COMMON_API PeriodicSampler - { - - }; -} - -#endif // LL_LLTRACESAMPLER_H -- cgit v1.2.3 From 7196619b4a0823a332e10b7f98464a1649e0dfd2 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 2 Oct 2012 17:14:12 -0700 Subject: SH-3275 WIP Update viewer metrics system to be more flexible implemented minimal merging logic made recordings ligher weight by moving live tracking data into threadrecorder --- indra/llcommon/lltrace.cpp | 78 ++++++++++++++++++++++++++----------- indra/llcommon/lltrace.h | 14 ++++++- indra/llcommon/lltracerecording.cpp | 24 +++--------- indra/llcommon/lltracerecording.h | 5 +-- 4 files changed, 75 insertions(+), 46 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 6b4c3aeb06..6d928721de 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -66,18 +66,17 @@ MasterThreadRecorder& getMasterThreadRecorder() /////////////////////////////////////////////////////////////////////// ThreadRecorder::ThreadRecorder() +: mPrimaryRecording(NULL) { get_thread_recorder() = this; - mPrimaryRecording.makePrimary(); mFullRecording.start(); } ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) -: mPrimaryRecording(other.mPrimaryRecording), - mFullRecording(other.mFullRecording) +: mFullRecording(other.mFullRecording), + mPrimaryRecording(NULL) { get_thread_recorder() = this; - mPrimaryRecording.makePrimary(); mFullRecording.start(); } @@ -89,39 +88,74 @@ ThreadRecorder::~ThreadRecorder() //TODO: remove this and use llviewerstats recording Recording* ThreadRecorder::getPrimaryRecording() { - return &mPrimaryRecording; + return mPrimaryRecording; } -void ThreadRecorder::activate( Recording* recorder ) +void ThreadRecorder::activate( Recording* recording ) { - for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); + mActiveRecordings.push_front(ActiveRecording(mPrimaryRecording, recording)); + mActiveRecordings.front().mBaseline.makePrimary(); + mPrimaryRecording = &mActiveRecordings.front().mBaseline; +} + +//TODO: consider merging results down the list to one past the buffered item. +// this would require 2 buffers per sampler, to separate current total from running total + +void ThreadRecorder::deactivate( Recording* recording ) +{ + for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); it != end_it; ++it) { - (*it)->mMeasurements.write()->mergeSamples(*mPrimaryRecording.mMeasurements); - } - mPrimaryRecording.mMeasurements.write()->reset(); + std::list::iterator next_it = it; + if (++next_it != mActiveRecordings.end()) + { + next_it->mergeMeasurements((*it)); + } - recorder->initDeltas(mPrimaryRecording); + it->flushAccumulators(mPrimaryRecording); - mActiveRecordings.push_front(recorder); + if (it->mTargetRecording == recording) + { + if (next_it != mActiveRecordings.end()) + { + next_it->mBaseline.makePrimary(); + mPrimaryRecording = &next_it->mBaseline; + } + mActiveRecordings.erase(it); + break; + } + } } -//TODO: consider merging results down the list to one past the buffered item. -// this would require 2 buffers per sampler, to separate current total from running total - -void ThreadRecorder::deactivate( Recording* recorder ) +ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* target ) +: mTargetRecording(target) { - recorder->mergeDeltas(mPrimaryRecording); - - // TODO: replace with intrusive list - std::list::iterator found_it = std::find(mActiveRecordings.begin(), mActiveRecordings.end(), recorder); - if (found_it != mActiveRecordings.end()) + // take snapshots of current values rates and timers + if (source) { - mActiveRecordings.erase(found_it); + mBaseline.mRates.write()->copyFrom(*source->mRates); + mBaseline.mStackTimers.write()->copyFrom(*source->mStackTimers); } } +void ThreadRecorder::ActiveRecording::mergeMeasurements(ThreadRecorder::ActiveRecording& other) +{ + mBaseline.mMeasurements.write()->mergeSamples(*other.mBaseline.mMeasurements); +} + +void ThreadRecorder::ActiveRecording::flushAccumulators(Recording* current) +{ + // accumulate statistics-like measurements + mTargetRecording->mMeasurements.write()->mergeSamples(*mBaseline.mMeasurements); + // for rate-like measurements, merge total change since baseline + mTargetRecording->mRates.write()->mergeDeltas(*mBaseline.mRates, *current->mRates); + mTargetRecording->mStackTimers.write()->mergeDeltas(*mBaseline.mStackTimers, *current->mStackTimers); + // reset baselines + mBaseline.mRates.write()->copyFrom(*current->mRates); + mBaseline.mStackTimers.write()->copyFrom(*current->mStackTimers); +} + /////////////////////////////////////////////////////////////////////// // SlaveThreadRecorder /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index c5356777ae..39de79e4c1 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -497,9 +497,19 @@ namespace LLTrace Recording* getPrimaryRecording(); protected: - Recording mPrimaryRecording; + struct ActiveRecording + { + ActiveRecording(Recording* source, Recording* target); + + Recording* mTargetRecording; + Recording mBaseline; + + void mergeMeasurements(ActiveRecording& other); + void flushAccumulators(Recording* current); + }; + Recording* mPrimaryRecording; Recording mFullRecording; - std::list mActiveRecordings; + std::list mActiveRecordings; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index a792d40f9d..95cdb44e4b 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -39,17 +39,13 @@ namespace LLTrace Recording::Recording() : mElapsedSeconds(0), mIsStarted(false), - mRatesStart(new AccumulatorBuffer >()), mRates(new AccumulatorBuffer >()), mMeasurements(new AccumulatorBuffer >()), - mStackTimers(new AccumulatorBuffer()), - mStackTimersStart(new AccumulatorBuffer()) -{ -} + mStackTimers(new AccumulatorBuffer()) +{} Recording::~Recording() -{ -} +{} void Recording::start() { @@ -107,18 +103,10 @@ void Recording::mergeSamples( const Recording& other ) mStackTimers.write()->mergeSamples(*other.mStackTimers); } -void Recording::initDeltas( const Recording& other ) +void Recording::mergeDeltas(const Recording& baseline, const Recording& target) { - mRatesStart.write()->copyFrom(*other.mRates); - mStackTimersStart.write()->copyFrom(*other.mStackTimers); -} - - -void Recording::mergeDeltas( const Recording& other ) -{ - mRates.write()->mergeDeltas(*mRatesStart, *other.mRates); - mStackTimers.write()->mergeDeltas(*mStackTimersStart, *other.mStackTimers); - mMeasurements.write()->mergeSamples(*other.mMeasurements); + mRates.write()->mergeDeltas(*baseline.mRates, *target.mRates); + mStackTimers.write()->mergeDeltas(*baseline.mStackTimers, *target.mStackTimers); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 83dc503ea6..0a54e4cedf 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -57,8 +57,7 @@ namespace LLTrace void resume(); void mergeSamples(const Recording& other); - void initDeltas(const Recording& other); - void mergeDeltas(const Recording& other); + void mergeDeltas(const Recording& baseline, const Recording& target); void reset(); @@ -80,10 +79,8 @@ namespace LLTrace // returns data for current thread class ThreadRecorder* getThreadRecorder(); - LLCopyOnWritePointer > > mRatesStart; LLCopyOnWritePointer > > mRates; LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimersStart; LLCopyOnWritePointer > mStackTimers; bool mIsStarted; -- cgit v1.2.3 From 8f5e83789254d19a1a31737b0d7515cd7e967b26 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 3 Oct 2012 19:32:59 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system SH-3403 FIX implement unit conversion LLUnit implements unit tracking and conversion added support for LLUnit to LLTrace duplicated most llstats into LLTrace equivalents --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/lltrace.h | 62 +++++++++-- indra/llcommon/lltracerecording.h | 18 +-- indra/llcommon/llunit.h | 226 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 291 insertions(+), 16 deletions(-) create mode 100644 indra/llcommon/llunit.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 1ccee23e1e..471558ea01 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -247,6 +247,7 @@ set(llcommon_HEADER_FILES lltracerecording.h lltreeiterators.h lltypeinfolookup.h + llunit.h lluri.h lluuid.h lluuidhashmap.h diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 39de79e4c1..6a889f74df 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -35,6 +35,7 @@ #include "lltimer.h" #include "llrefcount.h" #include "lltracerecording.h" +#include "llunit.h" #include @@ -42,11 +43,8 @@ #define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) #define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); - namespace LLTrace { - class Recording; - void init(); void cleanup(); @@ -325,10 +323,10 @@ namespace LLTrace U32 mNumSamples; }; - template + template class LL_COMMON_API Measurement : public TraceType >, - public LLInstanceTracker, std::string> + public LLInstanceTracker, std::string> { public: Measurement(const std::string& name) @@ -343,13 +341,37 @@ namespace LLTrace }; template + class LL_COMMON_API Measurement + : public Measurement + { + public: + typedef Measurement base_measurement_t; + Measurement(const std::string& name) + : Measurement(name) + {} + + template + void sample(UNIT_T value) + { + base_measurement_t::sample(value.get()); + } + + template + typename T::value_t get() + { + UNIT_T value(*this); + return value.get(); + } + }; + + template class LL_COMMON_API Rate - : public TraceType >, + : public TraceType >, public LLInstanceTracker, std::string> { public: Rate(const std::string& name) - : TraceType(name), + : TraceType(name), LLInstanceTracker(name) {} @@ -359,6 +381,30 @@ namespace LLTrace } }; + template + class LL_COMMON_API Rate + : public Rate + { + public: + Rate(const std::string& name) + : Rate(name) + {} + + template + void add(UNIT_T value) + { + getPrimaryAccumulator().add(value.get()); + } + + template + typename T::value_t get() + { + UNIT_T value(*this); + return value.get(); + } + + }; + class LL_COMMON_API TimerAccumulator { public: @@ -482,6 +528,8 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; + class Recording; + class LL_COMMON_API ThreadRecorder { public: diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 0a54e4cedf..4d5793014f 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -35,8 +35,8 @@ namespace LLTrace { - template class Rate; - template class Measurement; + template class Rate; + template class Measurement; template class AccumulatorBuffer; template class RateAccumulator; template class MeasurementAccumulator; @@ -63,14 +63,14 @@ namespace LLTrace bool isStarted() { return mIsStarted; } - F32 getSum(Rate& stat); - F32 getPerSec(Rate& stat); + F32 getSum(Rate& stat); + F32 getPerSec(Rate& stat); - F32 getSum(Measurement& stat); - F32 getMin(Measurement& stat); - F32 getMax(Measurement& stat); - F32 getMean(Measurement& stat); - F32 getStandardDeviation(Measurement& stat); + F32 getSum(Measurement& stat); + F32 getMin(Measurement& stat); + F32 getMax(Measurement& stat); + F32 getMean(Measurement& stat); + F32 getStandardDeviation(Measurement& stat); F64 getSampleTime() { return mElapsedSeconds; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h new file mode 100644 index 0000000000..9d78df7cae --- /dev/null +++ b/indra/llcommon/llunit.h @@ -0,0 +1,226 @@ +/** + * @file llunit.h + * @brief Unit conversion classes + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLUNIT_H +#define LL_LLUNIT_H + +#include "stdtypes.h" +#include "llpreprocessor.h" + +template +struct LLUnit : public BASE_UNIT +{ + typedef LLUnit unit_t; + typedef typename BASE_UNIT::value_t value_t; + typedef void is_unit_t; + + LLUnit() + {} + + explicit LLUnit(value_t value) + : BASE_UNIT(convertToBase(value)) + {} + + operator value_t() { return get(); } + + value_t get() const + { + return convertToDerived(mValue); + } + + static value_t convertToBase(value_t derived_value) + { + return (value_t)((F32)derived_value * DERIVED_UNIT::conversionToBaseFactor()); + } + + static value_t convertToDerived(value_t base_value) + { + return (value_t)((F32)base_value / DERIVED_UNIT::conversionToBaseFactor()); + } + +}; + +template +struct LLUnit +{ + typedef LLUnit unit_t; + typedef T value_t; + typedef void is_unit_t; + + LLUnit() + : mValue() + {} + + explicit LLUnit(T value) + : mValue(value) + {} + + unit_t& operator=(T value) + { + setBaseValue(value); + return *this; + } + + value_t get() { return mValue; } + + static value_t convertToBase(value_t derived_value) + { + return (value_t)1; + } + + static value_t convertToDerived(value_t base_value) + { + return (value_t)1; + } + + unit_t operator + (const unit_t other) const + { + return unit_t(mValue + other.mValue); + } + + void operator += (const unit_t other) + { + mValue += other.mValue; + } + + unit_t operator - (const unit_t other) const + { + return unit_t(mValue - other.mValue); + } + + void operator -= (const unit_t other) + { + mValue -= other.mValue; + } + + unit_t operator * (value_t multiplicand) const + { + return unit_t(mValue * multiplicand); + } + + void operator *= (value_t multiplicand) + { + mValue *= multiplicand; + } + + unit_t operator / (value_t divisor) const + { + return unit_t(mValue / divisor); + } + + void operator /= (value_t divisor) + { + mValue /= divisor; + } + +protected: + void setBaseValue(T value) + { + mValue = value; + } + + T mValue; +}; + +#define LL_DECLARE_BASE_UNIT(unit_name) \ + template \ + struct unit_name : public LLUnit \ + { \ + unit_name(STORAGE_TYPE value) \ + : LLUnit(value) \ + {} \ + \ + unit_name() \ + {} \ + \ + template \ + unit_name(const LLUnit& other) \ + { \ + setBaseValue(other.unit_name::get()); \ + } \ + \ + using LLUnit::operator +; \ + using LLUnit::operator +=; \ + using LLUnit::operator -; \ + using LLUnit::operator -=; \ + using LLUnit::operator *; \ + using LLUnit::operator *=; \ + using LLUnit::operator /; \ + using LLUnit::operator /=; \ + }; + +#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ + template \ + struct derived_unit : public LLUnit, derived_unit > \ + { \ + derived_unit(value_t value) \ + : LLUnit(value) \ + {} \ + \ + derived_unit() \ + {} \ + \ + template \ + derived_unit(const LLUnit, T>& other) \ + { \ + setBaseValue(other.base_unit::get()); \ + } \ + \ + static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ + \ + using LLUnit::operator +; \ + using LLUnit::operator +=; \ + using LLUnit::operator -; \ + using LLUnit::operator -=; \ + using LLUnit::operator *; \ + using LLUnit::operator *=; \ + using LLUnit::operator /; \ + using LLUnit::operator /=; \ + }; + +namespace LLUnits +{ + LL_DECLARE_BASE_UNIT(Bytes); + LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); + LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.f / 8.f)); + LL_DECLARE_DERIVED_UNIT(Bytes, Kilobit, (1024 / 8)); + LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); + LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); + + LL_DECLARE_BASE_UNIT(Seconds); + LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); + LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); + LL_DECLARE_DERIVED_UNIT(Seconds, Days, 60 * 60 * 24); + LL_DECLARE_DERIVED_UNIT(Seconds, Weeks, 60 * 60 * 24 * 7); + LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.f / 1000.f)); + LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.f / (1000000.f))); + LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.f / (1000000000.f))); + +} + +#endif // LL_LLUNIT_H -- cgit v1.2.3 From 3960fdf9e01619ddfd7903bcdd8d894f432752d0 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 4 Oct 2012 23:11:57 -0700 Subject: SH-3275 WIP Update viewer metrics system to be more flexible moved threadrecorder classes into separate file added Count trace type, which tracks value increases and decreases and can report churn as well as overall growth rate --- indra/llcommon/CMakeLists.txt | 2 + indra/llcommon/lltrace.cpp | 195 +-------------------------- indra/llcommon/lltrace.h | 143 +++++--------------- indra/llcommon/lltracerecording.cpp | 54 ++++++-- indra/llcommon/lltracerecording.h | 30 +++-- indra/llcommon/lltracethreadrecorder.cpp | 219 +++++++++++++++++++++++++++++++ indra/llcommon/lltracethreadrecorder.h | 124 +++++++++++++++++ 7 files changed, 450 insertions(+), 317 deletions(-) create mode 100644 indra/llcommon/lltracethreadrecorder.cpp create mode 100644 indra/llcommon/lltracethreadrecorder.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 471558ea01..c0e9266aa9 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -102,6 +102,7 @@ set(llcommon_SOURCE_FILES lltimer.cpp lltrace.cpp lltracerecording.cpp + lltracethreadrecorder.cpp lluri.cpp lluuid.cpp llworkerthread.cpp @@ -245,6 +246,7 @@ set(llcommon_HEADER_FILES lltimer.h lltrace.h lltracerecording.h + lltracethreadrecorder.h lltreeiterators.h lltypeinfolookup.h llunit.h diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 6d928721de..2b1c8d8ce8 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -44,206 +44,19 @@ void cleanup() gMasterThreadRecorder = NULL; } -LLThreadLocalPointer& get_thread_recorder() -{ - static LLThreadLocalPointer s_thread_recorder; - return s_thread_recorder; - -} - -BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; - - - MasterThreadRecorder& getMasterThreadRecorder() { llassert(gMasterThreadRecorder != NULL); return *gMasterThreadRecorder; } -/////////////////////////////////////////////////////////////////////// -// ThreadRecorder -/////////////////////////////////////////////////////////////////////// - -ThreadRecorder::ThreadRecorder() -: mPrimaryRecording(NULL) -{ - get_thread_recorder() = this; - mFullRecording.start(); -} - -ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) -: mFullRecording(other.mFullRecording), - mPrimaryRecording(NULL) -{ - get_thread_recorder() = this; - mFullRecording.start(); -} - -ThreadRecorder::~ThreadRecorder() -{ - get_thread_recorder() = NULL; -} - -//TODO: remove this and use llviewerstats recording -Recording* ThreadRecorder::getPrimaryRecording() -{ - return mPrimaryRecording; -} - -void ThreadRecorder::activate( Recording* recording ) -{ - mActiveRecordings.push_front(ActiveRecording(mPrimaryRecording, recording)); - mActiveRecordings.front().mBaseline.makePrimary(); - mPrimaryRecording = &mActiveRecordings.front().mBaseline; -} - -//TODO: consider merging results down the list to one past the buffered item. -// this would require 2 buffers per sampler, to separate current total from running total - -void ThreadRecorder::deactivate( Recording* recording ) -{ - for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); - it != end_it; - ++it) - { - std::list::iterator next_it = it; - if (++next_it != mActiveRecordings.end()) - { - next_it->mergeMeasurements((*it)); - } - - it->flushAccumulators(mPrimaryRecording); - - if (it->mTargetRecording == recording) - { - if (next_it != mActiveRecordings.end()) - { - next_it->mBaseline.makePrimary(); - mPrimaryRecording = &next_it->mBaseline; - } - mActiveRecordings.erase(it); - break; - } - } -} - -ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* target ) -: mTargetRecording(target) -{ - // take snapshots of current values rates and timers - if (source) - { - mBaseline.mRates.write()->copyFrom(*source->mRates); - mBaseline.mStackTimers.write()->copyFrom(*source->mStackTimers); - } -} - -void ThreadRecorder::ActiveRecording::mergeMeasurements(ThreadRecorder::ActiveRecording& other) -{ - mBaseline.mMeasurements.write()->mergeSamples(*other.mBaseline.mMeasurements); -} - -void ThreadRecorder::ActiveRecording::flushAccumulators(Recording* current) -{ - // accumulate statistics-like measurements - mTargetRecording->mMeasurements.write()->mergeSamples(*mBaseline.mMeasurements); - // for rate-like measurements, merge total change since baseline - mTargetRecording->mRates.write()->mergeDeltas(*mBaseline.mRates, *current->mRates); - mTargetRecording->mStackTimers.write()->mergeDeltas(*mBaseline.mStackTimers, *current->mStackTimers); - // reset baselines - mBaseline.mRates.write()->copyFrom(*current->mRates); - mBaseline.mStackTimers.write()->copyFrom(*current->mStackTimers); -} - -/////////////////////////////////////////////////////////////////////// -// SlaveThreadRecorder -/////////////////////////////////////////////////////////////////////// - -SlaveThreadRecorder::SlaveThreadRecorder() -: ThreadRecorder(getMasterThreadRecorder()) -{ - getMasterThreadRecorder().addSlaveThread(this); -} - -SlaveThreadRecorder::~SlaveThreadRecorder() -{ - getMasterThreadRecorder().removeSlaveThread(this); -} - -void SlaveThreadRecorder::pushToMaster() -{ - mFullRecording.stop(); - { - LLMutexLock(getMasterThreadRecorder().getSlaveListMutex()); - mSharedData.copyFrom(mFullRecording); - } - mFullRecording.start(); -} - -void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) -{ - LLMutexLock lock(&mRecorderMutex); - mRecorder.mergeSamples(source); -} - -void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) -{ - LLMutexLock lock(&mRecorderMutex); - sink.mergeSamples(mRecorder); -} - -/////////////////////////////////////////////////////////////////////// -// MasterThreadRecorder -/////////////////////////////////////////////////////////////////////// - -void MasterThreadRecorder::pullFromSlaveThreads() -{ - LLMutexLock lock(&mSlaveListMutex); - - for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); - it != end_it; - ++it) - { - (*it)->mRecorder->mSharedData.copyTo((*it)->mSlaveRecording); - } -} - -void MasterThreadRecorder::addSlaveThread( class SlaveThreadRecorder* child ) -{ - LLMutexLock lock(&mSlaveListMutex); - - mSlaveThreadRecorders.push_back(new SlaveThreadRecorderProxy(child)); -} - -void MasterThreadRecorder::removeSlaveThread( class SlaveThreadRecorder* child ) +LLThreadLocalPointer& get_thread_recorder() { - LLMutexLock lock(&mSlaveListMutex); + static LLThreadLocalPointer s_thread_recorder; + return s_thread_recorder; - for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); - it != end_it; - ++it) - { - if ((*it)->mRecorder == child) - { - mSlaveThreadRecorders.erase(it); - break; - } - } } -void MasterThreadRecorder::pushToMaster() -{} - -MasterThreadRecorder::MasterThreadRecorder() -{} - -/////////////////////////////////////////////////////////////////////// -// MasterThreadRecorder::SlaveThreadTraceProxy -/////////////////////////////////////////////////////////////////////// - -MasterThreadRecorder::SlaveThreadRecorderProxy::SlaveThreadRecorderProxy( class SlaveThreadRecorder* recorder) -: mRecorder(recorder) -{} +BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6a889f74df..d83ea77363 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -30,11 +30,10 @@ #include "stdtypes.h" #include "llpreprocessor.h" -#include "llmutex.h" #include "llmemory.h" -#include "lltimer.h" #include "llrefcount.h" #include "lltracerecording.h" +#include "lltracethreadrecorder.h" #include "llunit.h" #include @@ -171,7 +170,7 @@ namespace LLTrace template LLThreadLocalPointer AccumulatorBuffer::sPrimaryStorage; template - class LL_COMMON_API TraceType + class LL_COMMON_API TraceType { public: TraceType(const std::string& name) @@ -186,6 +185,7 @@ namespace LLTrace } ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) { return (*buffer)[mAccumulatorIndex]; } + const ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) const { return (*buffer)[mAccumulatorIndex]; } protected: std::string mName; @@ -265,11 +265,11 @@ namespace LLTrace mMax = 0; } - T getSum() { return mSum; } - T getMin() { return mMin; } - T getMax() { return mMax; } - F32 getMean() { return mMean; } - F32 getStandardDeviation() { return mStandardDeviation; } + T getSum() const { return mSum; } + T getMin() const { return mMin; } + T getMax() const { return mMax; } + F32 getMean() const { return mMean; } + F32 getStandardDeviation() const { return mStandardDeviation; } private: T mSum, @@ -315,7 +315,7 @@ namespace LLTrace mSum = 0; } - T getSum() { return mSum; } + T getSum() const { return mSum; } private: T mSum; @@ -355,13 +355,6 @@ namespace LLTrace { base_measurement_t::sample(value.get()); } - - template - typename T::value_t get() - { - UNIT_T value(*this); - return value.get(); - } }; template @@ -395,14 +388,35 @@ namespace LLTrace { getPrimaryAccumulator().add(value.get()); } + }; - template - typename T::value_t get() + template + class LL_COMMON_API Count + { + public: + Count(const std::string& name) + : mIncrease(name + "_increase"), + mDecrease(name + "_decrease"), + mTotal(name) + {} + + void count(T value) { - UNIT_T value(*this); - return value.get(); + if (value < 0) + { + mDecrease.add(value * -1); + } + else + { + mIncrease.add(value); + } + mTotal.add(value); } - + private: + friend class LLTrace::Recording; + Rate mIncrease; + Rate mDecrease; + Rate mTotal; }; class LL_COMMON_API TimerAccumulator @@ -527,93 +541,6 @@ namespace LLTrace static Recorder::StackEntry sCurRecorder; }; - - class Recording; - - class LL_COMMON_API ThreadRecorder - { - public: - ThreadRecorder(); - ThreadRecorder(const ThreadRecorder& other); - - virtual ~ThreadRecorder(); - - void activate(Recording* recording); - void deactivate(Recording* recording); - - virtual void pushToMaster() = 0; - - Recording* getPrimaryRecording(); - protected: - struct ActiveRecording - { - ActiveRecording(Recording* source, Recording* target); - - Recording* mTargetRecording; - Recording mBaseline; - - void mergeMeasurements(ActiveRecording& other); - void flushAccumulators(Recording* current); - }; - Recording* mPrimaryRecording; - Recording mFullRecording; - std::list mActiveRecordings; - }; - - class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder - { - public: - MasterThreadRecorder(); - - void addSlaveThread(class SlaveThreadRecorder* child); - void removeSlaveThread(class SlaveThreadRecorder* child); - - /*virtual */ void pushToMaster(); - - // call this periodically to gather stats data from slave threads - void pullFromSlaveThreads(); - - LLMutex* getSlaveListMutex() { return &mSlaveListMutex; } - - private: - struct SlaveThreadRecorderProxy - { - SlaveThreadRecorderProxy(class SlaveThreadRecorder* recorder); - - class SlaveThreadRecorder* mRecorder; - Recording mSlaveRecording; - private: - //no need to copy these and then have to duplicate the storage - SlaveThreadRecorderProxy(const SlaveThreadRecorderProxy& other) {} - }; - typedef std::list slave_thread_recorder_list_t; - - slave_thread_recorder_list_t mSlaveThreadRecorders; - LLMutex mSlaveListMutex; - }; - - class LL_COMMON_API SlaveThreadRecorder : public ThreadRecorder - { - public: - SlaveThreadRecorder(); - ~SlaveThreadRecorder(); - - // call this periodically to gather stats data for master thread to consume - /*virtual*/ void pushToMaster(); - - MasterThreadRecorder* mMaster; - - class SharedData - { - public: - void copyFrom(const Recording& source); - void copyTo(Recording& sink); - private: - LLMutex mRecorderMutex; - Recording mRecorder; - }; - SharedData mSharedData; - }; } #endif // LL_LLTRACE_H diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 95cdb44e4b..e4cff551f9 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -110,46 +110,80 @@ void Recording::mergeDeltas(const Recording& baseline, const Recording& target) } -F32 Recording::getSum( Rate& stat ) +F32 Recording::getSum(const Rate& stat) { return stat.getAccumulator(mRates).getSum(); } -F32 Recording::getSum( Measurement& stat ) +F32 Recording::getPerSec(const Rate& stat) { - return stat.getAccumulator(mMeasurements).getSum(); + return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; } - -F32 Recording::getPerSec( Rate& stat ) +F32 Recording::getSum(const Measurement& stat) { - return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; + return stat.getAccumulator(mMeasurements).getSum(); } -F32 Recording::getMin( Measurement& stat ) +F32 Recording::getMin(const Measurement& stat) { return stat.getAccumulator(mMeasurements).getMin(); } -F32 Recording::getMax( Measurement& stat ) +F32 Recording::getMax(const Measurement& stat) { return stat.getAccumulator(mMeasurements).getMax(); } -F32 Recording::getMean( Measurement& stat ) +F32 Recording::getMean(const Measurement& stat) { return stat.getAccumulator(mMeasurements).getMean(); } -F32 Recording::getStandardDeviation( Measurement& stat ) +F32 Recording::getStandardDeviation(const Measurement& stat) { return stat.getAccumulator(mMeasurements).getStandardDeviation(); } +F32 Recording::getSum(const Count& stat) +{ + return getSum(stat.mTotal); +} + +F32 Recording::getPerSec(const Count& stat) +{ + return getPerSec(stat.mTotal); +} + +F32 Recording::getIncrease(const Count& stat) +{ + return getSum(stat.mIncrease); +} + +F32 Recording::getIncreasePerSec(const Count& stat) +{ + return getPerSec(stat.mIncrease); +} +F32 Recording::getDecrease(const Count& stat) +{ + return getSum(stat.mDecrease); +} +F32 Recording::getDecreasePerSec(const Count& stat) +{ + return getPerSec(stat.mDecrease); +} +F32 Recording::getChurn(const Count& stat) +{ + return getIncrease(stat) + getDecrease(stat); +} +F32 Recording::getChurnPerSec(const Count& stat) +{ + return getIncreasePerSec(stat) + getDecreasePerSec(stat); +} } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 4d5793014f..f9bc6b61b2 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -37,6 +37,7 @@ namespace LLTrace { template class Rate; template class Measurement; + template class Count; template class AccumulatorBuffer; template class RateAccumulator; template class MeasurementAccumulator; @@ -63,14 +64,27 @@ namespace LLTrace bool isStarted() { return mIsStarted; } - F32 getSum(Rate& stat); - F32 getPerSec(Rate& stat); - - F32 getSum(Measurement& stat); - F32 getMin(Measurement& stat); - F32 getMax(Measurement& stat); - F32 getMean(Measurement& stat); - F32 getStandardDeviation(Measurement& stat); + // Rate accessors + F32 getSum(const Rate& stat); + F32 getPerSec(const Rate& stat); + + // Measurement accessors + F32 getSum(const Measurement& stat); + F32 getPerSec(const Measurement& stat); + F32 getMin(const Measurement& stat); + F32 getMax(const Measurement& stat); + F32 getMean(const Measurement& stat); + F32 getStandardDeviation(const Measurement& stat); + + // Count accessors + F32 getSum(const Count& stat); + F32 getPerSec(const Count& stat); + F32 getIncrease(const Count& stat); + F32 getIncreasePerSec(const Count& stat); + F32 getDecrease(const Count& stat); + F32 getDecreasePerSec(const Count& stat); + F32 getChurn(const Count& stat); + F32 getChurnPerSec(const Count& stat); F64 getSampleTime() { return mElapsedSeconds; } diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp new file mode 100644 index 0000000000..9115a52fd1 --- /dev/null +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -0,0 +1,219 @@ +/** + * @file lltracethreadrecorder.cpp + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltrace.h" + +namespace LLTrace +{ + + +/////////////////////////////////////////////////////////////////////// +// ThreadRecorder +/////////////////////////////////////////////////////////////////////// + +ThreadRecorder::ThreadRecorder() +: mPrimaryRecording(NULL) +{ + get_thread_recorder() = this; + mFullRecording.start(); +} + +ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) +: mFullRecording(other.mFullRecording), + mPrimaryRecording(NULL) +{ + get_thread_recorder() = this; + mFullRecording.start(); +} + +ThreadRecorder::~ThreadRecorder() +{ + get_thread_recorder() = NULL; +} + +//TODO: remove this and use llviewerstats recording +Recording* ThreadRecorder::getPrimaryRecording() +{ + return mPrimaryRecording; +} + +void ThreadRecorder::activate( Recording* recording ) +{ + mActiveRecordings.push_front(ActiveRecording(mPrimaryRecording, recording)); + mActiveRecordings.front().mBaseline.makePrimary(); + mPrimaryRecording = &mActiveRecordings.front().mBaseline; +} + +//TODO: consider merging results down the list to one past the buffered item. +// this would require 2 buffers per sampler, to separate current total from running total + +void ThreadRecorder::deactivate( Recording* recording ) +{ + for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); + it != end_it; + ++it) + { + std::list::iterator next_it = it; + if (++next_it != mActiveRecordings.end()) + { + next_it->mergeMeasurements((*it)); + } + + it->flushAccumulators(mPrimaryRecording); + + if (it->mTargetRecording == recording) + { + if (next_it != mActiveRecordings.end()) + { + next_it->mBaseline.makePrimary(); + mPrimaryRecording = &next_it->mBaseline; + } + mActiveRecordings.erase(it); + break; + } + } +} + +ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* target ) +: mTargetRecording(target) +{ + // take snapshots of current values rates and timers + if (source) + { + mBaseline.mRates.write()->copyFrom(*source->mRates); + mBaseline.mStackTimers.write()->copyFrom(*source->mStackTimers); + } +} + +void ThreadRecorder::ActiveRecording::mergeMeasurements(ThreadRecorder::ActiveRecording& other) +{ + mBaseline.mMeasurements.write()->mergeSamples(*other.mBaseline.mMeasurements); +} + +void ThreadRecorder::ActiveRecording::flushAccumulators(Recording* current) +{ + // accumulate statistics-like measurements + mTargetRecording->mMeasurements.write()->mergeSamples(*mBaseline.mMeasurements); + // for rate-like measurements, merge total change since baseline + mTargetRecording->mRates.write()->mergeDeltas(*mBaseline.mRates, *current->mRates); + mTargetRecording->mStackTimers.write()->mergeDeltas(*mBaseline.mStackTimers, *current->mStackTimers); + // reset baselines + mBaseline.mRates.write()->copyFrom(*current->mRates); + mBaseline.mStackTimers.write()->copyFrom(*current->mStackTimers); +} + +/////////////////////////////////////////////////////////////////////// +// SlaveThreadRecorder +/////////////////////////////////////////////////////////////////////// + +SlaveThreadRecorder::SlaveThreadRecorder() +: ThreadRecorder(getMasterThreadRecorder()) +{ + getMasterThreadRecorder().addSlaveThread(this); +} + +SlaveThreadRecorder::~SlaveThreadRecorder() +{ + getMasterThreadRecorder().removeSlaveThread(this); +} + +void SlaveThreadRecorder::pushToMaster() +{ + mFullRecording.stop(); + { + LLMutexLock(getMasterThreadRecorder().getSlaveListMutex()); + mSharedData.copyFrom(mFullRecording); + } + mFullRecording.start(); +} + +void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) +{ + LLMutexLock lock(&mRecorderMutex); + mRecorder.mergeSamples(source); +} + +void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) +{ + LLMutexLock lock(&mRecorderMutex); + sink.mergeSamples(mRecorder); +} + +/////////////////////////////////////////////////////////////////////// +// MasterThreadRecorder +/////////////////////////////////////////////////////////////////////// + +void MasterThreadRecorder::pullFromSlaveThreads() +{ + LLMutexLock lock(&mSlaveListMutex); + + for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); + it != end_it; + ++it) + { + (*it)->mRecorder->mSharedData.copyTo((*it)->mSlaveRecording); + } +} + +void MasterThreadRecorder::addSlaveThread( class SlaveThreadRecorder* child ) +{ + LLMutexLock lock(&mSlaveListMutex); + + mSlaveThreadRecorders.push_back(new SlaveThreadRecorderProxy(child)); +} + +void MasterThreadRecorder::removeSlaveThread( class SlaveThreadRecorder* child ) +{ + LLMutexLock lock(&mSlaveListMutex); + + for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); + it != end_it; + ++it) + { + if ((*it)->mRecorder == child) + { + mSlaveThreadRecorders.erase(it); + break; + } + } +} + +void MasterThreadRecorder::pushToMaster() +{} + +MasterThreadRecorder::MasterThreadRecorder() +{} + +/////////////////////////////////////////////////////////////////////// +// MasterThreadRecorder::SlaveThreadTraceProxy +/////////////////////////////////////////////////////////////////////// + +MasterThreadRecorder::SlaveThreadRecorderProxy::SlaveThreadRecorderProxy( class SlaveThreadRecorder* recorder) +: mRecorder(recorder) +{} + +} diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h new file mode 100644 index 0000000000..40441d0447 --- /dev/null +++ b/indra/llcommon/lltracethreadrecorder.h @@ -0,0 +1,124 @@ +/** + * @file lltrace.h + * @brief Runtime statistics accumulation. + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTRACETHREADRECORDER_H +#define LL_LLTRACETHREADRECORDER_H + +#include "stdtypes.h" +#include "llpreprocessor.h" + +#include "llmutex.h" +#include "lltracerecording.h" + +namespace LLTrace +{ + class LL_COMMON_API ThreadRecorder + { + public: + ThreadRecorder(); + ThreadRecorder(const ThreadRecorder& other); + + virtual ~ThreadRecorder(); + + void activate(Recording* recording); + void deactivate(Recording* recording); + + virtual void pushToMaster() = 0; + + Recording* getPrimaryRecording(); + protected: + struct ActiveRecording + { + ActiveRecording(Recording* source, Recording* target); + + Recording* mTargetRecording; + Recording mBaseline; + + void mergeMeasurements(ActiveRecording& other); + void flushAccumulators(Recording* current); + }; + Recording* mPrimaryRecording; + Recording mFullRecording; + std::list mActiveRecordings; + }; + + class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder + { + public: + MasterThreadRecorder(); + + void addSlaveThread(class SlaveThreadRecorder* child); + void removeSlaveThread(class SlaveThreadRecorder* child); + + /*virtual */ void pushToMaster(); + + // call this periodically to gather stats data from slave threads + void pullFromSlaveThreads(); + + LLMutex* getSlaveListMutex() { return &mSlaveListMutex; } + + private: + struct SlaveThreadRecorderProxy + { + SlaveThreadRecorderProxy(class SlaveThreadRecorder* recorder); + + class SlaveThreadRecorder* mRecorder; + Recording mSlaveRecording; + private: + //no need to copy these and then have to duplicate the storage + SlaveThreadRecorderProxy(const SlaveThreadRecorderProxy& other) {} + }; + typedef std::list slave_thread_recorder_list_t; + + slave_thread_recorder_list_t mSlaveThreadRecorders; + LLMutex mSlaveListMutex; + }; + + class LL_COMMON_API SlaveThreadRecorder : public ThreadRecorder + { + public: + SlaveThreadRecorder(); + ~SlaveThreadRecorder(); + + // call this periodically to gather stats data for master thread to consume + /*virtual*/ void pushToMaster(); + + MasterThreadRecorder* mMaster; + + class SharedData + { + public: + void copyFrom(const Recording& source); + void copyTo(Recording& sink); + private: + LLMutex mRecorderMutex; + Recording mRecorder; + }; + SharedData mSharedData; + }; +} + +#endif // LL_LLTRACETHREADRECORDER_H -- cgit v1.2.3 From 4dce574a8d604a501ec3c12eef3f5d03ee188473 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 5 Oct 2012 10:51:38 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system added update() method to trace recorders to allow mid-collection snapshots --- indra/llcommon/lltracerecording.cpp | 6 ++++++ indra/llcommon/lltracerecording.h | 1 + indra/llcommon/lltracethreadrecorder.cpp | 19 +++++++++++++------ indra/llcommon/lltracethreadrecorder.h | 3 +++ 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index e4cff551f9..c44cc8a8a7 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -63,6 +63,12 @@ void Recording::reset() mSamplingTimer.reset(); } +void Recording::update() +{ + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); +} + void Recording::resume() { if (!mIsStarted) diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f9bc6b61b2..4d53cd9600 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -61,6 +61,7 @@ namespace LLTrace void mergeDeltas(const Recording& baseline, const Recording& target); void reset(); + void update(); bool isStarted() { return mIsStarted; } diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 9115a52fd1..b2c6fe3b80 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -68,10 +68,7 @@ void ThreadRecorder::activate( Recording* recording ) mPrimaryRecording = &mActiveRecordings.front().mBaseline; } -//TODO: consider merging results down the list to one past the buffered item. -// this would require 2 buffers per sampler, to separate current total from running total - -void ThreadRecorder::deactivate( Recording* recording ) +std::list::iterator ThreadRecorder::update( Recording* recording ) { for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); it != end_it; @@ -92,10 +89,20 @@ void ThreadRecorder::deactivate( Recording* recording ) next_it->mBaseline.makePrimary(); mPrimaryRecording = &next_it->mBaseline; } - mActiveRecordings.erase(it); - break; + return it; } } + + return mActiveRecordings.end(); +} + +void ThreadRecorder::deactivate( Recording* recording ) +{ + std::list::iterator it = update(recording); + if (it != mActiveRecordings.end()) + { + mActiveRecordings.erase(it); + } } ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* target ) diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 40441d0447..42230087c0 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -37,6 +37,8 @@ namespace LLTrace { class LL_COMMON_API ThreadRecorder { + protected: + struct ActiveRecording; public: ThreadRecorder(); ThreadRecorder(const ThreadRecorder& other); @@ -44,6 +46,7 @@ namespace LLTrace virtual ~ThreadRecorder(); void activate(Recording* recording); + std::list::iterator update(Recording* recording); void deactivate(Recording* recording); virtual void pushToMaster() = 0; -- cgit v1.2.3 From 960f8764ad2407add941bc8650b295f1e77beb19 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 5 Oct 2012 11:44:36 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system added update() method to trace recorders to allow mid-collection snapshots --- indra/llcommon/lltracerecording.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index c44cc8a8a7..f0b17ef100 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -65,8 +65,12 @@ void Recording::reset() void Recording::update() { - mElapsedSeconds = 0.0; - mSamplingTimer.reset(); + if (mIsStarted) + { + LLTrace::get_thread_recorder()->update(this); + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); + } } void Recording::resume() -- cgit v1.2.3 From aff9654c1115b4a74fc3ee8f9ca2c2ffa07f8d73 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 9 Oct 2012 18:02:47 -0700 Subject: SH-3275 WIP Update viewer metrics system to be more flexible added PeriodicRecorder class for frame by frame stats accumulation --- indra/llcommon/lltrace.h | 4 +- indra/llcommon/lltracerecording.cpp | 35 ++--- indra/llcommon/lltracerecording.h | 247 ++++++++++++++++++++++++++++++++++-- indra/llcommon/llunit.h | 12 +- 4 files changed, 261 insertions(+), 37 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index d83ea77363..e655a3582e 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -353,7 +353,7 @@ namespace LLTrace template void sample(UNIT_T value) { - base_measurement_t::sample(value.get()); + base_measurement_t::sample(value.value()); } }; @@ -386,7 +386,7 @@ namespace LLTrace template void add(UNIT_T value) { - getPrimaryAccumulator().add(value.get()); + getPrimaryAccumulator().add(value.value()); } }; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index e4cff551f9..7cd6280f03 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -38,7 +38,6 @@ namespace LLTrace Recording::Recording() : mElapsedSeconds(0), - mIsStarted(false), mRates(new AccumulatorBuffer >()), mMeasurements(new AccumulatorBuffer >()), mStackTimers(new AccumulatorBuffer()) @@ -47,13 +46,7 @@ Recording::Recording() Recording::~Recording() {} -void Recording::start() -{ - reset(); - resume(); -} - -void Recording::reset() +void Recording::handleReset() { mRates.write()->reset(); mMeasurements.write()->reset(); @@ -63,24 +56,22 @@ void Recording::reset() mSamplingTimer.reset(); } -void Recording::resume() +void Recording::handleStart() +{ + mSamplingTimer.reset(); + LLTrace::get_thread_recorder()->activate(this); +} + +void Recording::handleStop() { - if (!mIsStarted) - { - mSamplingTimer.reset(); - LLTrace::get_thread_recorder()->activate(this); - mIsStarted = true; - } + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::get_thread_recorder()->deactivate(this); } -void Recording::stop() +void Recording::handleSplitTo(Recording& other) { - if (mIsStarted) - { - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - LLTrace::get_thread_recorder()->deactivate(this); - mIsStarted = false; - } + stop(); + other.restart(); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f9bc6b61b2..080007ba00 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -33,6 +33,147 @@ #include "llpointer.h" #include "lltimer.h" +template +class LL_COMMON_API LLVCRControlsMixinInterface +{ +public: + virtual ~LLVCRControlsMixinInterface() {} + // trigger data accumulation (without reset) + virtual void handleStart() = 0; + // stop data accumulation, should put object in queryable state + virtual void handleStop() = 0; + // clear accumulated values, can be called while started + virtual void handleReset() = 0; + // atomically stop this object while starting the other + // no data can be missed in between stop and start + virtual void handleSplitTo(DERIVED& other) = 0; +}; + +template +class LL_COMMON_API LLVCRControlsMixin +: private LLVCRControlsMixinInterface +{ +public: + enum EPlayState + { + STOPPED, + PAUSED, + STARTED + }; + + void start() + { + switch (mPlayState) + { + case STOPPED: + handleReset(); + handleStart(); + break; + case PAUSED: + handleStart(); + break; + case STARTED: + handleReset(); + break; + } + mPlayState = STARTED; + } + + void stop() + { + switch (mPlayState) + { + case STOPPED: + break; + case PAUSED: + handleStop(); + break; + case STARTED: + break; + } + mPlayState = STOPPED; + } + + void pause() + { + switch (mPlayState) + { + case STOPPED: + break; + case PAUSED: + break; + case STARTED: + handleStop(); + break; + } + mPlayState = PAUSED; + } + + void resume() + { + switch (mPlayState) + { + case STOPPED: + handleStart(); + break; + case PAUSED: + handleStart(); + break; + case STARTED: + break; + } + mPlayState = STARTED; + } + + void restart() + { + switch (mPlayState) + { + case STOPPED: + handleReset(); + handleStart(); + break; + case PAUSED: + handleReset(); + handleStart(); + break; + case STARTED: + handleReset(); + break; + } + mPlayState = STARTED; + } + + void reset() + { + handleReset(); + } + + void splitTo(DERIVED& other) + { + onSplitTo(other); + } + + void splitFrom(DERIVED& other) + { + other.onSplitTo(*this); + } + + bool isStarted() { return mPlayState == STARTED; } + bool isPaused() { return mPlayState == PAUSED; } + bool isStopped() { return mPlayState == STOPPED; } + EPlayState getPlayState() { return mPlayState; } + +protected: + + LLVCRControlsMixin() + : mPlayState(STOPPED) + {} + +private: + EPlayState mPlayState; +}; + namespace LLTrace { template class Rate; @@ -43,7 +184,7 @@ namespace LLTrace template class MeasurementAccumulator; class TimerAccumulator; - class LL_COMMON_API Recording + class LL_COMMON_API Recording : public LLVCRControlsMixin { public: Recording(); @@ -53,16 +194,9 @@ namespace LLTrace void makePrimary(); bool isPrimary(); - void start(); - void stop(); - void resume(); - void mergeSamples(const Recording& other); void mergeDeltas(const Recording& baseline, const Recording& target); - void reset(); - - bool isStarted() { return mIsStarted; } // Rate accessors F32 getSum(const Rate& stat); @@ -89,6 +223,14 @@ namespace LLTrace F64 getSampleTime() { return mElapsedSeconds; } private: + friend class PeriodicRecording; + // implementation for LLVCRControlsMixin + /*virtual*/ void handleStart(); + /*virtual*/ void handleStop(); + /*virtual*/ void handleReset(); + /*virtual*/ void handleSplitTo(Recording& other); + + friend class ThreadRecorder; // returns data for current thread class ThreadRecorder* getThreadRecorder(); @@ -97,14 +239,99 @@ namespace LLTrace LLCopyOnWritePointer > > mMeasurements; LLCopyOnWritePointer > mStackTimers; - bool mIsStarted; LLTimer mSamplingTimer; F64 mElapsedSeconds; }; - class LL_COMMON_API PeriodicRecording + class LL_COMMON_API PeriodicRecording + : public LLVCRControlsMixin { + public: + PeriodicRecording(S32 num_periods) + : mNumPeriods(num_periods), + mCurPeriod(0), + mTotalValid(false), + mRecordingPeriods(new Recording[num_periods]) + { + llassert(mNumPeriods > 0); + } + + ~PeriodicRecording() + { + delete[] mRecordingPeriods; + } + + void nextPeriod() + { + EPlayState play_state = getPlayState(); + getCurRecordingPeriod().stop(); + mCurPeriod = (mCurPeriod + 1) % mNumPeriods; + switch(play_state) + { + case STOPPED: + break; + case PAUSED: + getCurRecordingPeriod().pause(); + break; + case STARTED: + getCurRecordingPeriod().start(); + break; + } + // new period, need to recalculate total + mTotalValid = false; + } + + Recording& getCurRecordingPeriod() + { + return mRecordingPeriods[mCurPeriod]; + } + + const Recording& getCurRecordingPeriod() const + { + return mRecordingPeriods[mCurPeriod]; + } + + Recording& getTotalRecording() + { + if (!mTotalValid) + { + mTotalRecording.reset(); + for (S32 i = (mCurPeriod + 1) % mNumPeriods; i < mCurPeriod; i++) + { + mTotalRecording.mergeSamples(mRecordingPeriods[i]); + } + } + mTotalValid = true; + return mTotalRecording; + } + + private: + // implementation for LLVCRControlsMixin + /*virtual*/ void handleStart() + { + getCurRecordingPeriod().handleStart(); + } + + /*virtual*/ void handleStop() + { + getCurRecordingPeriod().handleStop(); + } + + /*virtual*/ void handleReset() + { + getCurRecordingPeriod().handleReset(); + } + + /*virtual*/ void handleSplitTo(PeriodicRecording& other) + { + getCurRecordingPeriod().handleSplitTo(other.getCurRecordingPeriod()); + } + Recording* mRecordingPeriods; + Recording mTotalRecording; + bool mTotalValid; + S32 mNumPeriods, + mCurPeriod; }; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 9d78df7cae..52b837fdc3 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -44,13 +44,19 @@ struct LLUnit : public BASE_UNIT : BASE_UNIT(convertToBase(value)) {} - operator value_t() { return get(); } + operator value_t() { return value(); } - value_t get() const + value_t value() const { return convertToDerived(mValue); } + template + value_t value() const + { + return CONVERTED_TYPE(*this).value(); + } + static value_t convertToBase(value_t derived_value) { return (value_t)((F32)derived_value * DERIVED_UNIT::conversionToBaseFactor()); @@ -84,7 +90,7 @@ struct LLUnit return *this; } - value_t get() { return mValue; } + value_t value() { return mValue; } static value_t convertToBase(value_t derived_value) { -- cgit v1.2.3 From 8bb0a6ef737cb40c8f64f37fe64ecc7f6a87ae18 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 9 Oct 2012 18:07:31 -0700 Subject: post merge cleanup --- indra/llcommon/lltracerecording.cpp | 32 ++++++++++++++++---------------- indra/llcommon/lltracerecording.h | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 93d2136e7f..d931c4ed29 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -46,6 +46,16 @@ Recording::Recording() Recording::~Recording() {} +void Recording::update() +{ + if (isStarted()) + { + LLTrace::get_thread_recorder()->update(this); + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); + } +} + void Recording::handleReset() { mRates.write()->reset(); @@ -56,27 +66,17 @@ void Recording::handleReset() mSamplingTimer.reset(); } -void Recording::update() -{ - if (mIsStarted) - { - LLTrace::get_thread_recorder()->update(this); - mElapsedSeconds = 0.0; - mSamplingTimer.reset(); - } -} - void Recording::handleStart() { - mSamplingTimer.reset(); - LLTrace::get_thread_recorder()->activate(this); + mSamplingTimer.reset(); + LLTrace::get_thread_recorder()->activate(this); } void Recording::handleStop() - { - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - LLTrace::get_thread_recorder()->deactivate(this); - } +{ + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::get_thread_recorder()->deactivate(this); +} void Recording::handleSplitTo(Recording& other) { diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 6e5f118cf6..092dc7ff2c 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -254,7 +254,7 @@ namespace LLTrace mCurPeriod(0), mTotalValid(false), mRecordingPeriods(new Recording[num_periods]) - { + { llassert(mNumPeriods > 0); } -- cgit v1.2.3 From 05510799e5a69eafcc919e72d25cf5b89c9274cf Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 9 Oct 2012 22:18:07 -0700 Subject: SH-3275 WIP Update viewer metrics system to be more flexible renamed mergeSamples to mergeRecording --- indra/llcommon/lltracerecording.cpp | 2 +- indra/llcommon/lltracerecording.h | 4 ++-- indra/llcommon/lltracethreadrecorder.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index d931c4ed29..9a08770bd7 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -97,7 +97,7 @@ bool Recording::isPrimary() return mRates->isPrimary(); } -void Recording::mergeSamples( const Recording& other ) +void Recording::mergeRecording( const Recording& other ) { mRates.write()->mergeSamples(*other.mRates); mMeasurements.write()->mergeSamples(*other.mMeasurements); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 092dc7ff2c..4399a65cfb 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -194,7 +194,7 @@ namespace LLTrace void makePrimary(); bool isPrimary(); - void mergeSamples(const Recording& other); + void mergeRecording(const Recording& other); void mergeDeltas(const Recording& baseline, const Recording& target); void reset(); @@ -300,7 +300,7 @@ namespace LLTrace mTotalRecording.reset(); for (S32 i = (mCurPeriod + 1) % mNumPeriods; i < mCurPeriod; i++) { - mTotalRecording.mergeSamples(mRecordingPeriods[i]); + mTotalRecording.mergeRecording(mRecordingPeriods[i]); } } mTotalValid = true; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index b2c6fe3b80..4d020f5650 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -161,13 +161,13 @@ void SlaveThreadRecorder::pushToMaster() void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) { LLMutexLock lock(&mRecorderMutex); - mRecorder.mergeSamples(source); + mRecorder.mergeRecording(source); } void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) { LLMutexLock lock(&mRecorderMutex); - sink.mergeSamples(mRecorder); + sink.mergeRecording(mRecorder); } /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 74ac0182ec8f7a0f6d0ea89f5814f0998ab90b62 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 10 Oct 2012 19:25:56 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed units conversion so that trace getters return convertable units removed circular dependencies from lltrace* converted more stats to lltrace --- indra/llcommon/llqueuedthread.cpp | 2 +- indra/llcommon/llthread.cpp | 1 + indra/llcommon/lltrace.cpp | 1 + indra/llcommon/lltrace.h | 88 ++++++++++------ indra/llcommon/lltracerecording.cpp | 96 ++--------------- indra/llcommon/lltracerecording.h | 145 +++++++++++++++++++------ indra/llcommon/lltracethreadrecorder.cpp | 14 +-- indra/llcommon/llunit.h | 176 ++++++++++++++++++------------- 8 files changed, 295 insertions(+), 228 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 6e2a2b140f..218f6dbcd0 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -28,7 +28,7 @@ #include "llstl.h" #include "lltimer.h" // ms_sleep() -#include "lltrace.h" +#include "lltracethreadrecorder.h" //============================================================================ diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 6723e427f5..cc661bab59 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -33,6 +33,7 @@ #include "lltimer.h" #include "lltrace.h" +#include "lltracethreadrecorder.h" #if LL_LINUX || LL_SOLARIS #include diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 2b1c8d8ce8..d5911ece25 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -27,6 +27,7 @@ #include "lltrace.h" #include "lltracerecording.h" +#include "lltracethreadrecorder.h" namespace LLTrace { diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index d83ea77363..539a37ce31 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -32,9 +32,9 @@ #include "llmemory.h" #include "llrefcount.h" -#include "lltracerecording.h" -#include "lltracethreadrecorder.h" +//#include "lltracethreadrecorder.h" #include "llunit.h" +#include "llapr.h" #include @@ -44,6 +44,8 @@ namespace LLTrace { + class Recording; + void init(); void cleanup(); @@ -89,23 +91,23 @@ namespace LLTrace return mStorage[index]; } - void mergeSamples(const AccumulatorBuffer& other) + void addSamples(const AccumulatorBuffer& other) { llassert(mNextStorageSlot == other.mNextStorageSlot); for (size_t i = 0; i < mNextStorageSlot; i++) { - mStorage[i].mergeSamples(other.mStorage[i]); + mStorage[i].addSamples(other.mStorage[i]); } } - void mergeDeltas(const AccumulatorBuffer& start, const AccumulatorBuffer& finish) + void addDeltas(const AccumulatorBuffer& start, const AccumulatorBuffer& finish) { llassert(mNextStorageSlot == start.mNextStorageSlot && mNextStorageSlot == finish.mNextStorageSlot); for (size_t i = 0; i < mNextStorageSlot; i++) { - mStorage[i].mergeDeltas(start.mStorage[i], finish.mStorage[i]); + mStorage[i].addDeltas(start.mStorage[i], finish.mStorage[i]); } } @@ -173,8 +175,9 @@ namespace LLTrace class LL_COMMON_API TraceType { public: - TraceType(const std::string& name) - : mName(name) + TraceType(const char* name, const char* description = NULL) + : mName(name), + mDescription(description ? description : "") { mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } @@ -189,6 +192,7 @@ namespace LLTrace protected: std::string mName; + std::string mDescription; size_t mAccumulatorIndex; }; @@ -201,6 +205,8 @@ namespace LLTrace : mSum(0), mMin(0), mMax(0), + mMean(0), + mVarianceSum(0), mNumSamples(0) {} @@ -218,10 +224,11 @@ namespace LLTrace } F32 old_mean = mMean; mMean += ((F32)value - old_mean) / (F32)mNumSamples; - mStandardDeviation += ((F32)value - old_mean) * ((F32)value - mMean); + mVarianceSum += ((F32)value - old_mean) * ((F32)value - mMean); + mLastValue = value; } - void mergeSamples(const MeasurementAccumulator& other) + void addSamples(const MeasurementAccumulator& other) { mSum += other.mSum; if (other.mMin < mMin) @@ -240,19 +247,20 @@ namespace LLTrace n_2 = (F32)other.mNumSamples; F32 m_1 = mMean, m_2 = other.mMean; - F32 sd_1 = mStandardDeviation, - sd_2 = other.mStandardDeviation; + F32 sd_1 = getStandardDeviation(), + sd_2 = other.getStandardDeviation(); // combine variance (and hence standard deviation) of 2 different sized sample groups using // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm - F32 variance = ((((n_1 - 1.f) * sd_1 * sd_1) - + ((n_2 - 1.f) * sd_2 * sd_2) - + (((n_1 * n_2) / (n_1 + n_2)) - * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) - / (n_1 + n_2 - 1.f)); - mStandardDeviation = sqrtf(variance); + mVarianceSum = (F32)mNumSamples + * ((((n_1 - 1.f) * sd_1 * sd_1) + + ((n_2 - 1.f) * sd_2 * sd_2) + + (((n_1 * n_2) / (n_1 + n_2)) + * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) + / (n_1 + n_2 - 1.f)); + mLastValue = other.mLastValue; } - void mergeDeltas(const MeasurementAccumulator& start, const MeasurementAccumulator& finish) + void addDeltas(const MeasurementAccumulator& start, const MeasurementAccumulator& finish) { llerrs << "Delta merge invalid for measurement accumulators" << llendl; } @@ -268,16 +276,18 @@ namespace LLTrace T getSum() const { return mSum; } T getMin() const { return mMin; } T getMax() const { return mMax; } + T getLastValue() const { return mLastValue; } F32 getMean() const { return mMean; } - F32 getStandardDeviation() const { return mStandardDeviation; } + F32 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } private: T mSum, mMin, - mMax; + mMax, + mLastValue; F32 mMean, - mStandardDeviation; + mVarianceSum; U32 mNumSamples; }; @@ -297,13 +307,13 @@ namespace LLTrace mSum += value; } - void mergeSamples(const RateAccumulator& other) + void addSamples(const RateAccumulator& other) { mSum += other.mSum; mNumSamples += other.mNumSamples; } - void mergeDeltas(const RateAccumulator& start, const RateAccumulator& finish) + void addDeltas(const RateAccumulator& start, const RateAccumulator& finish) { mSum += finish.mSum - start.mSum; mNumSamples += finish.mNumSamples - start.mNumSamples; @@ -329,7 +339,10 @@ namespace LLTrace public LLInstanceTracker, std::string> { public: - Measurement(const std::string& name) + typedef T storage_t; + typedef T base_unit_t; + + Measurement(const char* name, const char* description = NULL) : TraceType(name), LLInstanceTracker(name) {} @@ -345,8 +358,11 @@ namespace LLTrace : public Measurement { public: + typedef typename T::storage_t storage_t; + typedef typename T::base_unit_t base_unit_t; + typedef Measurement base_measurement_t; - Measurement(const std::string& name) + Measurement(const char* name, const char* description = NULL) : Measurement(name) {} @@ -363,7 +379,10 @@ namespace LLTrace public LLInstanceTracker, std::string> { public: - Rate(const std::string& name) + typedef T storage_t; + typedef T base_unit_t; + + Rate(const char* name, const char* description = NULL) : TraceType(name), LLInstanceTracker(name) {} @@ -379,7 +398,10 @@ namespace LLTrace : public Rate { public: - Rate(const std::string& name) + typedef typename T::storage_t storage_t; + typedef typename T::base_unit_t base_unit_t; + + Rate(const char* name, const char* description = NULL) : Rate(name) {} @@ -394,7 +416,9 @@ namespace LLTrace class LL_COMMON_API Count { public: - Count(const std::string& name) + typedef typename Rate::base_unit_t base_unit_t; + + Count(const char* name) : mIncrease(name + "_increase"), mDecrease(name + "_decrease"), mTotal(name) @@ -413,7 +437,7 @@ namespace LLTrace mTotal.add(value); } private: - friend class LLTrace::Recording; + friend LLTrace::Recording; Rate mIncrease; Rate mDecrease; Rate mTotal; @@ -433,14 +457,14 @@ namespace LLTrace bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame std::vector mChildren; // currently assumed child timers - void mergeSamples(const TimerAccumulator& other) + void addSamples(const TimerAccumulator& other) { mTotalTimeCounter += other.mTotalTimeCounter; mChildTimeCounter += other.mChildTimeCounter; mCalls += other.mCalls; } - void mergeDeltas(const TimerAccumulator& start, const TimerAccumulator& finish) + void addDeltas(const TimerAccumulator& start, const TimerAccumulator& finish) { mTotalTimeCounter += finish.mTotalTimeCounter - start.mTotalTimeCounter; mChildTimeCounter += finish.mChildTimeCounter - start.mChildTimeCounter; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index f0b17ef100..e20bf797e7 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -25,8 +25,9 @@ #include "linden_common.h" -#include "lltracerecording.h" #include "lltrace.h" +#include "lltracerecording.h" +#include "lltracethreadrecorder.h" #include "llthread.h" namespace LLTrace @@ -101,99 +102,22 @@ void Recording::makePrimary() mStackTimers.write()->makePrimary(); } -bool Recording::isPrimary() +bool Recording::isPrimary() const { return mRates->isPrimary(); } -void Recording::mergeSamples( const Recording& other ) +void Recording::addSamples( const Recording& other ) { - mRates.write()->mergeSamples(*other.mRates); - mMeasurements.write()->mergeSamples(*other.mMeasurements); - mStackTimers.write()->mergeSamples(*other.mStackTimers); + mRates.write()->addSamples(*other.mRates); + mMeasurements.write()->addSamples(*other.mMeasurements); + mStackTimers.write()->addSamples(*other.mStackTimers); } -void Recording::mergeDeltas(const Recording& baseline, const Recording& target) +void Recording::addDeltas(const Recording& baseline, const Recording& target) { - mRates.write()->mergeDeltas(*baseline.mRates, *target.mRates); - mStackTimers.write()->mergeDeltas(*baseline.mStackTimers, *target.mStackTimers); + mRates.write()->addDeltas(*baseline.mRates, *target.mRates); + mStackTimers.write()->addDeltas(*baseline.mStackTimers, *target.mStackTimers); } - -F32 Recording::getSum(const Rate& stat) -{ - return stat.getAccumulator(mRates).getSum(); -} - -F32 Recording::getPerSec(const Rate& stat) -{ - return stat.getAccumulator(mRates).getSum() / mElapsedSeconds; -} - -F32 Recording::getSum(const Measurement& stat) -{ - return stat.getAccumulator(mMeasurements).getSum(); -} - -F32 Recording::getMin(const Measurement& stat) -{ - return stat.getAccumulator(mMeasurements).getMin(); -} - -F32 Recording::getMax(const Measurement& stat) -{ - return stat.getAccumulator(mMeasurements).getMax(); -} - -F32 Recording::getMean(const Measurement& stat) -{ - return stat.getAccumulator(mMeasurements).getMean(); -} - -F32 Recording::getStandardDeviation(const Measurement& stat) -{ - return stat.getAccumulator(mMeasurements).getStandardDeviation(); -} - -F32 Recording::getSum(const Count& stat) -{ - return getSum(stat.mTotal); -} - -F32 Recording::getPerSec(const Count& stat) -{ - return getPerSec(stat.mTotal); -} - -F32 Recording::getIncrease(const Count& stat) -{ - return getSum(stat.mIncrease); -} - -F32 Recording::getIncreasePerSec(const Count& stat) -{ - return getPerSec(stat.mIncrease); -} - -F32 Recording::getDecrease(const Count& stat) -{ - return getSum(stat.mDecrease); -} - -F32 Recording::getDecreasePerSec(const Count& stat) -{ - return getPerSec(stat.mDecrease); -} - -F32 Recording::getChurn(const Count& stat) -{ - return getIncrease(stat) + getDecrease(stat); -} - -F32 Recording::getChurnPerSec(const Count& stat) -{ - return getIncreasePerSec(stat) + getDecreasePerSec(stat); -} - - } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 4d53cd9600..d0c2e754f5 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -32,16 +32,17 @@ #include "llpointer.h" #include "lltimer.h" +#include "lltrace.h" namespace LLTrace { - template class Rate; - template class Measurement; - template class Count; - template class AccumulatorBuffer; - template class RateAccumulator; - template class MeasurementAccumulator; - class TimerAccumulator; + //template class Rate; + //template class Measurement; + //template class Count; + //template class AccumulatorBuffer; + //template class RateAccumulator; + //template class MeasurementAccumulator; + //class TimerAccumulator; class LL_COMMON_API Recording { @@ -51,43 +52,125 @@ namespace LLTrace ~Recording(); void makePrimary(); - bool isPrimary(); + bool isPrimary() const; void start(); void stop(); void resume(); - - void mergeSamples(const Recording& other); - void mergeDeltas(const Recording& baseline, const Recording& target); - void reset(); void update(); + bool isStarted() const { return mIsStarted; } - bool isStarted() { return mIsStarted; } + void addSamples(const Recording& other); + void addDeltas(const Recording& baseline, const Recording& target); // Rate accessors - F32 getSum(const Rate& stat); - F32 getPerSec(const Rate& stat); + template + typename Rate::base_unit_t getSum(const Rate& stat) const + { + return (typename Rate::base_unit_t)stat.getAccumulator(mRates).getSum(); + } + + template + typename Rate::base_unit_t getPerSec(const Rate& stat) const + { + return (typename Rate::base_unit_t)stat.getAccumulator(mRates).getSum() / mElapsedSeconds; + } // Measurement accessors - F32 getSum(const Measurement& stat); - F32 getPerSec(const Measurement& stat); - F32 getMin(const Measurement& stat); - F32 getMax(const Measurement& stat); - F32 getMean(const Measurement& stat); - F32 getStandardDeviation(const Measurement& stat); + template + typename Measurement::base_unit_t getSum(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getSum(); + + } + + template + typename Measurement::base_unit_t getPerSec(const Measurement& stat) const + { + return (typename Rate::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; + } + + template + typename Measurement::base_unit_t getMin(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMin(); + } + + template + typename Measurement::base_unit_t getMax(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMax(); + } + + template + typename Measurement::base_unit_t getMean(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMean(); + } + + template + typename Measurement::base_unit_t getStandardDeviation(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getStandardDeviation(); + } + + template + typename Measurement::base_unit_t getLastValue(const Measurement& stat) const + { + return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getLastValue(); + } // Count accessors - F32 getSum(const Count& stat); - F32 getPerSec(const Count& stat); - F32 getIncrease(const Count& stat); - F32 getIncreasePerSec(const Count& stat); - F32 getDecrease(const Count& stat); - F32 getDecreasePerSec(const Count& stat); - F32 getChurn(const Count& stat); - F32 getChurnPerSec(const Count& stat); - - F64 getSampleTime() { return mElapsedSeconds; } + template + typename Count::base_unit_t getSum(const Count& stat) const + { + return getSum(stat.mTotal); + } + + template + typename Count::base_unit_t getPerSec(const Count& stat) const + { + return getPerSec(stat.mTotal); + } + + template + typename Count::base_unit_t getIncrease(const Count& stat) const + { + return getPerSec(stat.mTotal); + } + + template + typename Count::base_unit_t getIncreasePerSec(const Count& stat) const + { + return getPerSec(stat.mIncrease); + } + + template + typename Count::base_unit_t getDecrease(const Count& stat) const + { + return getPerSec(stat.mDecrease); + } + + template + typename Count::base_unit_t getDecreasePerSec(const Count& stat) const + { + return getPerSec(stat.mDecrease); + } + + template + typename Count::base_unit_t getChurn(const Count& stat) const + { + return getIncrease(stat) + getDecrease(stat); + } + + template + typename Count::base_unit_t getChurnPerSec(const Count& stat) const + { + return getIncreasePerSec(stat) + getDecreasePerSec(stat); + } + + F64 getSampleTime() const { return mElapsedSeconds; } private: friend class ThreadRecorder; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index b2c6fe3b80..78833835c2 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -25,7 +25,7 @@ #include "linden_common.h" -#include "lltrace.h" +#include "lltracethreadrecorder.h" namespace LLTrace { @@ -118,16 +118,16 @@ ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* void ThreadRecorder::ActiveRecording::mergeMeasurements(ThreadRecorder::ActiveRecording& other) { - mBaseline.mMeasurements.write()->mergeSamples(*other.mBaseline.mMeasurements); + mBaseline.mMeasurements.write()->addSamples(*other.mBaseline.mMeasurements); } void ThreadRecorder::ActiveRecording::flushAccumulators(Recording* current) { // accumulate statistics-like measurements - mTargetRecording->mMeasurements.write()->mergeSamples(*mBaseline.mMeasurements); + mTargetRecording->mMeasurements.write()->addSamples(*mBaseline.mMeasurements); // for rate-like measurements, merge total change since baseline - mTargetRecording->mRates.write()->mergeDeltas(*mBaseline.mRates, *current->mRates); - mTargetRecording->mStackTimers.write()->mergeDeltas(*mBaseline.mStackTimers, *current->mStackTimers); + mTargetRecording->mRates.write()->addDeltas(*mBaseline.mRates, *current->mRates); + mTargetRecording->mStackTimers.write()->addDeltas(*mBaseline.mStackTimers, *current->mStackTimers); // reset baselines mBaseline.mRates.write()->copyFrom(*current->mRates); mBaseline.mStackTimers.write()->copyFrom(*current->mStackTimers); @@ -161,13 +161,13 @@ void SlaveThreadRecorder::pushToMaster() void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) { LLMutexLock lock(&mRecorderMutex); - mRecorder.mergeSamples(source); + mRecorder.addSamples(source); } void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) { LLMutexLock lock(&mRecorderMutex); - sink.mergeSamples(mRecorder); + sink.addSamples(mRecorder); } /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 9d78df7cae..4663070c42 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -30,21 +30,24 @@ #include "stdtypes.h" #include "llpreprocessor.h" -template -struct LLUnit : public BASE_UNIT +template +struct LLUnitType : public BASE_UNIT { - typedef LLUnit unit_t; + typedef DERIVED_UNIT unit_t; typedef typename BASE_UNIT::value_t value_t; typedef void is_unit_t; - LLUnit() + LLUnitType() {} - explicit LLUnit(value_t value) + explicit LLUnitType(value_t value) : BASE_UNIT(convertToBase(value)) {} - operator value_t() { return get(); } + operator unit_t& () + { + return static_cast(*this); + } value_t get() const { @@ -53,47 +56,72 @@ struct LLUnit : public BASE_UNIT static value_t convertToBase(value_t derived_value) { - return (value_t)((F32)derived_value * DERIVED_UNIT::conversionToBaseFactor()); + return (value_t)((F32)derived_value * unit_t::conversionToBaseFactor()); } static value_t convertToDerived(value_t base_value) { - return (value_t)((F32)base_value / DERIVED_UNIT::conversionToBaseFactor()); + return (value_t)((F32)base_value / unit_t::conversionToBaseFactor()); + } + + unit_t operator + (const unit_t other) const + { + return unit_t(mValue + other.mValue); + } + + unit_t operator - (const unit_t other) const + { + return unit_t(mValue - other.mValue); + } + + unit_t operator * (value_t multiplicand) const + { + return unit_t(mValue * multiplicand); + } + + unit_t operator / (value_t divisor) const + { + return unit_t(mValue / divisor); } }; -template -struct LLUnit +template +struct LLUnitType { - typedef LLUnit unit_t; - typedef T value_t; + typedef T unit_t; + typedef typename STORAGE_TYPE value_t; typedef void is_unit_t; - LLUnit() + LLUnitType() : mValue() {} - explicit LLUnit(T value) + explicit LLUnitType(value_t value) : mValue(value) {} - unit_t& operator=(T value) + unit_t& operator=(value_t value) { setBaseValue(value); return *this; } + operator unit_t& () + { + return static_cast(*this); + } + value_t get() { return mValue; } static value_t convertToBase(value_t derived_value) { - return (value_t)1; + return (value_t)derived_value; } static value_t convertToDerived(value_t base_value) { - return (value_t)1; + return (value_t)base_value; } unit_t operator + (const unit_t other) const @@ -137,68 +165,74 @@ struct LLUnit } protected: - void setBaseValue(T value) + void setBaseValue(value_t value) { mValue = value; } - T mValue; + value_t mValue; }; -#define LL_DECLARE_BASE_UNIT(unit_name) \ - template \ - struct unit_name : public LLUnit \ - { \ - unit_name(STORAGE_TYPE value) \ - : LLUnit(value) \ - {} \ - \ - unit_name() \ - {} \ - \ - template \ - unit_name(const LLUnit& other) \ - { \ - setBaseValue(other.unit_name::get()); \ - } \ - \ - using LLUnit::operator +; \ - using LLUnit::operator +=; \ - using LLUnit::operator -; \ - using LLUnit::operator -=; \ - using LLUnit::operator *; \ - using LLUnit::operator *=; \ - using LLUnit::operator /; \ - using LLUnit::operator /=; \ +#define LL_DECLARE_BASE_UNIT(unit_name) \ + template \ + struct unit_name : public LLUnitType > \ + { \ + typedef unit_name base_unit_t; \ + typedef STORAGE_TYPE storage_t; \ + \ + unit_name(STORAGE_TYPE value) \ + : LLUnitType(value) \ + {} \ + \ + unit_name() \ + {} \ + \ + template \ + unit_name(const LLUnitType& source) \ + { \ + setBaseValue(source.unit_t::get()); \ + } \ + \ + 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 LLUnit, derived_unit > \ - { \ - derived_unit(value_t value) \ - : LLUnit(value) \ - {} \ - \ - derived_unit() \ - {} \ - \ - template \ - derived_unit(const LLUnit, T>& other) \ - { \ - setBaseValue(other.base_unit::get()); \ - } \ - \ - static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ - \ - using LLUnit::operator +; \ - using LLUnit::operator +=; \ - using LLUnit::operator -; \ - using LLUnit::operator -=; \ - using LLUnit::operator *; \ - using LLUnit::operator *=; \ - using LLUnit::operator /; \ - using LLUnit::operator /=; \ +#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ + template \ + struct derived_unit : public LLUnitType, derived_unit > \ + { \ + typedef base_unit base_unit_t; \ + typedef STORAGE_TYPE storage_t; \ + \ + derived_unit(value_t value) \ + : LLUnitType(value) \ + {} \ + \ + derived_unit() \ + {} \ + \ + template \ + derived_unit(const LLUnitType, SOURCE_TYPE>& source) \ + { \ + setBaseValue(source.base_unit_t::get()); \ + } \ + \ + 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 /=; \ }; namespace LLUnits -- cgit v1.2.3 From 0f58ca02cdec62711eadb82ba28fcff08faef2ee Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 12 Oct 2012 00:20:19 -0700 Subject: SH-3275 WIP Update viewer metrics system to be more flexible cleaned up accumulator merging logic introduced frame recording to LLTrace directly instead of going through LLViewerStats moved consumer code over to frame recording instead of whatever the current active recording was --- indra/llcommon/lltrace.h | 49 +++--- indra/llcommon/lltracerecording.cpp | 214 ++++++++++++++++++++++++-- indra/llcommon/lltracerecording.h | 251 +++++++++---------------------- indra/llcommon/lltracethreadrecorder.cpp | 73 ++++----- indra/llcommon/lltracethreadrecorder.h | 7 +- 5 files changed, 321 insertions(+), 273 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index a6334e176b..0c618a2f4b 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -101,16 +101,6 @@ namespace LLTrace } } - void addDeltas(const AccumulatorBuffer& start, const AccumulatorBuffer& finish) - { - llassert(mNextStorageSlot == start.mNextStorageSlot && mNextStorageSlot == finish.mNextStorageSlot); - - for (size_t i = 0; i < mNextStorageSlot; i++) - { - mStorage[i].addDeltas(start.mStorage[i], finish.mStorage[i]); - } - } - void copyFrom(const AccumulatorBuffer& other) { for (size_t i = 0; i < mNextStorageSlot; i++) @@ -203,11 +193,12 @@ namespace LLTrace public: MeasurementAccumulator() : mSum(0), - mMin(0), - mMax(0), + mMin(std::numeric_limits::max()), + mMax(std::numeric_limits::min()), mMean(0), mVarianceSum(0), - mNumSamples(0) + mNumSamples(0), + mLastValue(0) {} LL_FORCE_INLINE void sample(T value) @@ -251,20 +242,27 @@ namespace LLTrace sd_2 = other.getStandardDeviation(); // combine variance (and hence standard deviation) of 2 different sized sample groups using // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm - mVarianceSum = (F32)mNumSamples + if (n_1 == 0) + { + mVarianceSum = other.mVarianceSum; + } + else if (n_2 == 0) + { + // don't touch variance + // mVarianceSum = mVarianceSum; + } + else + { + mVarianceSum = (F32)mNumSamples * ((((n_1 - 1.f) * sd_1 * sd_1) + ((n_2 - 1.f) * sd_2 * sd_2) + (((n_1 * n_2) / (n_1 + n_2)) * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) / (n_1 + n_2 - 1.f)); + } mLastValue = other.mLastValue; } - void addDeltas(const MeasurementAccumulator& start, const MeasurementAccumulator& finish) - { - llerrs << "Delta merge invalid for measurement accumulators" << llendl; - } - void reset() { mNumSamples = 0; @@ -313,12 +311,6 @@ namespace LLTrace mNumSamples += other.mNumSamples; } - void addDeltas(const RateAccumulator& start, const RateAccumulator& finish) - { - mSum += finish.mSum - start.mSum; - mNumSamples += finish.mNumSamples - start.mNumSamples; - } - void reset() { mNumSamples = 0; @@ -464,13 +456,6 @@ namespace LLTrace mCalls += other.mCalls; } - void addDeltas(const TimerAccumulator& start, const TimerAccumulator& finish) - { - mTotalTimeCounter += finish.mTotalTimeCounter - start.mTotalTimeCounter; - mChildTimeCounter += finish.mChildTimeCounter - start.mChildTimeCounter; - mCalls += finish.mCalls - start.mCalls; - } - void reset() { mTotalTimeCounter = 0; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 0883930319..5d7b231b7d 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -68,16 +68,16 @@ void Recording::handleReset() } void Recording::handleStart() - { - mSamplingTimer.reset(); - LLTrace::get_thread_recorder()->activate(this); +{ + mSamplingTimer.reset(); + LLTrace::get_thread_recorder()->activate(this); } void Recording::handleStop() - { - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - LLTrace::get_thread_recorder()->deactivate(this); - } +{ + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::get_thread_recorder()->deactivate(this); +} void Recording::handleSplitTo(Recording& other) { @@ -105,10 +105,204 @@ void Recording::mergeRecording( const Recording& other ) mStackTimers.write()->addSamples(*other.mStackTimers); } -void Recording::mergeRecordingDelta(const Recording& baseline, const Recording& target) +/////////////////////////////////////////////////////////////////////// +// Recording +/////////////////////////////////////////////////////////////////////// + +PeriodicRecording::PeriodicRecording( S32 num_periods ) +: mNumPeriods(num_periods), + mCurPeriod(0), + mTotalValid(false), + mRecordingPeriods( new Recording[num_periods]) +{ + llassert(mNumPeriods > 0); +} + +PeriodicRecording::~PeriodicRecording() +{ + delete[] mRecordingPeriods; +} + + +void PeriodicRecording::nextPeriod() +{ + EPlayState play_state = getPlayState(); + getCurRecordingPeriod().stop(); + mCurPeriod = (mCurPeriod + 1) % mNumPeriods; + switch(play_state) + { + case STOPPED: + break; + case PAUSED: + getCurRecordingPeriod().pause(); + break; + case STARTED: + getCurRecordingPeriod().start(); + break; + } + // new period, need to recalculate total + mTotalValid = false; +} + +Recording& PeriodicRecording::getTotalRecording() +{ + if (!mTotalValid) + { + mTotalRecording.reset(); + for (S32 i = (mCurPeriod + 1) % mNumPeriods; i < mCurPeriod; i++) + { + mTotalRecording.mergeRecording(mRecordingPeriods[i]); + } + } + mTotalValid = true; + return mTotalRecording; +} + +void PeriodicRecording::handleStart() +{ + getCurRecordingPeriod().handleStart(); +} + +void PeriodicRecording::handleStop() +{ + getCurRecordingPeriod().handleStop(); +} + +void PeriodicRecording::handleReset() +{ + getCurRecordingPeriod().handleReset(); +} + +void PeriodicRecording::handleSplitTo( PeriodicRecording& other ) +{ + getCurRecordingPeriod().handleSplitTo(other.getCurRecordingPeriod()); +} + +/////////////////////////////////////////////////////////////////////// +// ExtendableRecording +/////////////////////////////////////////////////////////////////////// + +void ExtendableRecording::extend() { - mRates.write()->addDeltas(*baseline.mRates, *target.mRates); - mStackTimers.write()->addDeltas(*baseline.mStackTimers, *target.mStackTimers); + mAcceptedRecording.mergeRecording(mPotentialRecording); + mPotentialRecording.reset(); } +void ExtendableRecording::handleStart() +{ + mPotentialRecording.handleStart(); +} + +void ExtendableRecording::handleStop() +{ + mPotentialRecording.handleStop(); +} + +void ExtendableRecording::handleReset() +{ + mAcceptedRecording.handleReset(); + mPotentialRecording.handleReset(); +} + +void ExtendableRecording::handleSplitTo( ExtendableRecording& other ) +{ + mPotentialRecording.handleSplitTo(other.mPotentialRecording); +} + +PeriodicRecording& get_frame_recording() +{ + static PeriodicRecording sRecording(64); + sRecording.start(); + return sRecording; +} + +} + +void LLVCRControlsMixinCommon::start() +{ + switch (mPlayState) + { + case STOPPED: + handleReset(); + handleStart(); + break; + case PAUSED: + handleStart(); + break; + case STARTED: + handleReset(); + break; + } + mPlayState = STARTED; +} + +void LLVCRControlsMixinCommon::stop() +{ + switch (mPlayState) + { + case STOPPED: + break; + case PAUSED: + handleStop(); + break; + case STARTED: + handleStop(); + break; + } + mPlayState = STOPPED; +} + +void LLVCRControlsMixinCommon::pause() +{ + switch (mPlayState) + { + case STOPPED: + break; + case PAUSED: + break; + case STARTED: + handleStop(); + break; + } + mPlayState = PAUSED; +} + +void LLVCRControlsMixinCommon::resume() +{ + switch (mPlayState) + { + case STOPPED: + handleStart(); + break; + case PAUSED: + handleStart(); + break; + case STARTED: + break; + } + mPlayState = STARTED; +} + +void LLVCRControlsMixinCommon::restart() +{ + switch (mPlayState) + { + case STOPPED: + handleReset(); + handleStart(); + break; + case PAUSED: + handleReset(); + handleStart(); + break; + case STARTED: + handleReset(); + break; + } + mPlayState = STARTED; +} + +void LLVCRControlsMixinCommon::reset() +{ + handleReset(); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 0a1a02fa02..924a7bffd5 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -34,27 +34,11 @@ #include "lltimer.h" #include "lltrace.h" -template -class LL_COMMON_API LLVCRControlsMixinInterface +class LL_COMMON_API LLVCRControlsMixinCommon { public: - virtual ~LLVCRControlsMixinInterface() {} - // trigger data accumulation (without reset) - virtual void handleStart() = 0; - // stop data accumulation, should put object in queryable state - virtual void handleStop() = 0; - // clear accumulated values, can be called while started - virtual void handleReset() = 0; - // atomically stop this object while starting the other - // no data can be missed in between stop and start - virtual void handleSplitTo(DERIVED& other) = 0; -}; + virtual ~LLVCRControlsMixinCommon() {} -template -class LL_COMMON_API LLVCRControlsMixin -: private LLVCRControlsMixinInterface -{ -public: enum EPlayState { STOPPED, @@ -62,94 +46,39 @@ public: STARTED }; - void start() - { - switch (mPlayState) - { - case STOPPED: - handleReset(); - handleStart(); - break; - case PAUSED: - handleStart(); - break; - case STARTED: - handleReset(); - break; - } - mPlayState = STARTED; - } + void start(); + void stop(); + void pause(); + void resume(); + void restart(); + void reset(); - void stop() - { - switch (mPlayState) - { - case STOPPED: - break; - case PAUSED: - handleStop(); - break; - case STARTED: - break; - } - mPlayState = STOPPED; - } - - void pause() - { - switch (mPlayState) - { - case STOPPED: - break; - case PAUSED: - break; - case STARTED: - handleStop(); - break; - } - mPlayState = PAUSED; - } + bool isStarted() { return mPlayState == STARTED; } + bool isPaused() { return mPlayState == PAUSED; } + bool isStopped() { return mPlayState == STOPPED; } + EPlayState getPlayState() { return mPlayState; } - void resume() - { - switch (mPlayState) - { - case STOPPED: - handleStart(); - break; - case PAUSED: - handleStart(); - break; - case STARTED: - break; - } - mPlayState = STARTED; - } +protected: + LLVCRControlsMixinCommon() + : mPlayState(STOPPED) + {} - void restart() - { - switch (mPlayState) - { - case STOPPED: - handleReset(); - handleStart(); - break; - case PAUSED: - handleReset(); - handleStart(); - break; - case STARTED: - handleReset(); - break; - } - mPlayState = STARTED; - } +private: + // trigger data accumulation (without reset) + virtual void handleStart() = 0; + // stop data accumulation, should put object in queryable state + virtual void handleStop() = 0; + // clear accumulated values, can be called while started + virtual void handleReset() = 0; - void reset() - { - handleReset(); - } + EPlayState mPlayState; +}; +template +class LLVCRControlsMixin +: public LLVCRControlsMixinCommon +{ +public: void splitTo(DERIVED& other) { onSplitTo(other); @@ -159,32 +88,15 @@ public: { other.onSplitTo(*this); } - - bool isStarted() { return mPlayState == STARTED; } - bool isPaused() { return mPlayState == PAUSED; } - bool isStopped() { return mPlayState == STOPPED; } - EPlayState getPlayState() { return mPlayState; } - -protected: - - LLVCRControlsMixin() - : mPlayState(STOPPED) - {} - private: - EPlayState mPlayState; + // atomically stop this object while starting the other + // no data can be missed in between stop and start + virtual void handleSplitTo(DERIVED& other) = 0; + }; namespace LLTrace { - //template class Rate; - //template class Measurement; - //template class Count; - //template class AccumulatorBuffer; - //template class RateAccumulator; - //template class MeasurementAccumulator; - //class TimerAccumulator; - class LL_COMMON_API Recording : public LLVCRControlsMixin { public: @@ -196,7 +108,6 @@ namespace LLTrace bool isPrimary() const; void mergeRecording(const Recording& other); - void mergeRecordingDelta(const Recording& baseline, const Recording& target); void update(); @@ -308,15 +219,13 @@ namespace LLTrace F64 getSampleTime() const { return mElapsedSeconds; } - private: - friend class PeriodicRecording; // implementation for LLVCRControlsMixin /*virtual*/ void handleStart(); /*virtual*/ void handleStop(); /*virtual*/ void handleReset(); /*virtual*/ void handleSplitTo(Recording& other); - + private: friend class ThreadRecorder; // returns data for current thread class ThreadRecorder* getThreadRecorder(); @@ -333,38 +242,19 @@ namespace LLTrace : public LLVCRControlsMixin { public: - PeriodicRecording(S32 num_periods) - : mNumPeriods(num_periods), - mCurPeriod(0), - mTotalValid(false), - mRecordingPeriods(new Recording[num_periods]) - { - llassert(mNumPeriods > 0); - } + PeriodicRecording(S32 num_periods); + ~PeriodicRecording(); + + void nextPeriod(); - ~PeriodicRecording() + Recording& getLastRecordingPeriod() { - delete[] mRecordingPeriods; + return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; } - void nextPeriod() + const Recording& getLastRecordingPeriod() const { - EPlayState play_state = getPlayState(); - getCurRecordingPeriod().stop(); - mCurPeriod = (mCurPeriod + 1) % mNumPeriods; - switch(play_state) - { - case STOPPED: - break; - case PAUSED: - getCurRecordingPeriod().pause(); - break; - case STARTED: - getCurRecordingPeriod().start(); - break; - } - // new period, need to recalculate total - mTotalValid = false; + return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; } Recording& getCurRecordingPeriod() @@ -377,41 +267,16 @@ namespace LLTrace return mRecordingPeriods[mCurPeriod]; } - Recording& getTotalRecording() - { - if (!mTotalValid) - { - mTotalRecording.reset(); - for (S32 i = (mCurPeriod + 1) % mNumPeriods; i < mCurPeriod; i++) - { - mTotalRecording.mergeRecording(mRecordingPeriods[i]); - } - } - mTotalValid = true; - return mTotalRecording; - } + Recording& getTotalRecording(); private: - // implementation for LLVCRControlsMixin - /*virtual*/ void handleStart() - { - getCurRecordingPeriod().handleStart(); - } - - /*virtual*/ void handleStop() - { - getCurRecordingPeriod().handleStop(); - } - /*virtual*/ void handleReset() - { - getCurRecordingPeriod().handleReset(); - } + // implementation for LLVCRControlsMixin + /*virtual*/ void handleStart(); + /*virtual*/ void handleStop(); + /*virtual*/ void handleReset(); - /*virtual*/ void handleSplitTo(PeriodicRecording& other) - { - getCurRecordingPeriod().handleSplitTo(other.getCurRecordingPeriod()); - } + /*virtual*/ void handleSplitTo(PeriodicRecording& other); Recording* mRecordingPeriods; Recording mTotalRecording; @@ -419,6 +284,24 @@ namespace LLTrace S32 mNumPeriods, mCurPeriod; }; + + PeriodicRecording& get_frame_recording(); + + class ExtendableRecording + : public LLVCRControlsMixin + { + void extend(); + + private: + // implementation for LLVCRControlsMixin + /*virtual*/ void handleStart(); + /*virtual*/ void handleStop(); + /*virtual*/ void handleReset(); + /*virtual*/ void handleSplitTo(ExtendableRecording& other); + + Recording mAcceptedRecording; + Recording mPotentialRecording; + }; } #endif // LL_LLTRACERECORDING_H diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 3acd06d553..48aa1a42f2 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -36,15 +36,13 @@ namespace LLTrace /////////////////////////////////////////////////////////////////////// ThreadRecorder::ThreadRecorder() -: mPrimaryRecording(NULL) { get_thread_recorder() = this; mFullRecording.start(); } ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) -: mFullRecording(other.mFullRecording), - mPrimaryRecording(NULL) +: mFullRecording(other.mFullRecording) { get_thread_recorder() = this; mFullRecording.start(); @@ -55,45 +53,40 @@ ThreadRecorder::~ThreadRecorder() get_thread_recorder() = NULL; } -//TODO: remove this and use llviewerstats recording -Recording* ThreadRecorder::getPrimaryRecording() -{ - return mPrimaryRecording; -} - void ThreadRecorder::activate( Recording* recording ) { - mActiveRecordings.push_front(ActiveRecording(mPrimaryRecording, recording)); + mActiveRecordings.push_front(ActiveRecording(recording)); mActiveRecordings.front().mBaseline.makePrimary(); - mPrimaryRecording = &mActiveRecordings.front().mBaseline; } std::list::iterator ThreadRecorder::update( Recording* recording ) { - for (std::list::iterator it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); + std::list::iterator it, end_it; + for (it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); it != end_it; ++it) { std::list::iterator next_it = it; - if (++next_it != mActiveRecordings.end()) + ++next_it; + + // if we have another recording further down in the stack... + if (next_it != mActiveRecordings.end()) { - next_it->mergeMeasurements((*it)); + // ...push our gathered data down to it + next_it->mBaseline.mergeRecording(it->mBaseline); } - it->flushAccumulators(mPrimaryRecording); + // copy accumulated measurements into result buffer and clear accumulator (mBaseline) + it->moveBaselineToTarget(); if (it->mTargetRecording == recording) { - if (next_it != mActiveRecordings.end()) - { - next_it->mBaseline.makePrimary(); - mPrimaryRecording = &next_it->mBaseline; - } - return it; + // found the recording, so return it + break; } } - return mActiveRecordings.end(); + return it; } void ThreadRecorder::deactivate( Recording* recording ) @@ -101,38 +94,34 @@ void ThreadRecorder::deactivate( Recording* recording ) std::list::iterator it = update(recording); if (it != mActiveRecordings.end()) { + // and if we've found the recording we wanted to update + std::list::iterator next_it = it; + ++next_it; + if (next_it != mActiveRecordings.end()) + { + next_it->mTargetRecording->makePrimary(); + } + mActiveRecordings.erase(it); } } -ThreadRecorder::ActiveRecording::ActiveRecording( Recording* source, Recording* target ) +ThreadRecorder::ActiveRecording::ActiveRecording( Recording* target ) : mTargetRecording(target) { - // take snapshots of current values rates and timers - if (source) - { - mBaseline.mRates.write()->copyFrom(*source->mRates); - mBaseline.mStackTimers.write()->copyFrom(*source->mStackTimers); - } } -void ThreadRecorder::ActiveRecording::mergeMeasurements(ThreadRecorder::ActiveRecording& other) +void ThreadRecorder::ActiveRecording::moveBaselineToTarget() { - mBaseline.mMeasurements.write()->addSamples(*other.mBaseline.mMeasurements); -} - -void ThreadRecorder::ActiveRecording::flushAccumulators(Recording* current) -{ - // accumulate statistics-like measurements mTargetRecording->mMeasurements.write()->addSamples(*mBaseline.mMeasurements); - // for rate-like measurements, merge total change since baseline - mTargetRecording->mRates.write()->addDeltas(*mBaseline.mRates, *current->mRates); - mTargetRecording->mStackTimers.write()->addDeltas(*mBaseline.mStackTimers, *current->mStackTimers); - // reset baselines - mBaseline.mRates.write()->copyFrom(*current->mRates); - mBaseline.mStackTimers.write()->copyFrom(*current->mStackTimers); + mTargetRecording->mRates.write()->addSamples(*mBaseline.mRates); + mTargetRecording->mStackTimers.write()->addSamples(*mBaseline.mStackTimers); + mBaseline.mMeasurements.write()->reset(); + mBaseline.mRates.write()->reset(); + mBaseline.mStackTimers.write()->reset(); } + /////////////////////////////////////////////////////////////////////// // SlaveThreadRecorder /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 42230087c0..678b1a89f0 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -51,19 +51,16 @@ namespace LLTrace virtual void pushToMaster() = 0; - Recording* getPrimaryRecording(); protected: struct ActiveRecording { - ActiveRecording(Recording* source, Recording* target); + ActiveRecording(Recording* target); Recording* mTargetRecording; Recording mBaseline; - void mergeMeasurements(ActiveRecording& other); - void flushAccumulators(Recording* current); + void moveBaselineToTarget(); }; - Recording* mPrimaryRecording; Recording mFullRecording; std::list mActiveRecordings; }; -- cgit v1.2.3 From 041dfccd1ea5b59c1b3c4e37e9a5495cad342c8f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 12 Oct 2012 20:17:52 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system default to double precision now fixed unit conversion logic for LLUnit renamed LLTrace::Rate to LLTrace::Count and got rid of the old count as it was confusing some const correctness changes --- indra/llcommon/llpointer.h | 2 + indra/llcommon/lltrace.h | 93 ++++++++-------------- indra/llcommon/lltracerecording.cpp | 18 ++--- indra/llcommon/lltracerecording.h | 69 +++------------- indra/llcommon/lltracethreadrecorder.cpp | 4 +- indra/llcommon/llunit.h | 130 +++++++++++++++---------------- 6 files changed, 122 insertions(+), 194 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h index 0fee4f0990..6a3bbeb768 100644 --- a/indra/llcommon/llpointer.h +++ b/indra/llcommon/llpointer.h @@ -207,7 +207,9 @@ public: using LLPointer::operator >; + operator Type*() { return mPointer; } operator const Type*() const { return mPointer; } + Type* operator->() { return mPointer; } const Type* operator->() const { return mPointer; } }; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 0c618a2f4b..221c226ad1 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -91,6 +91,11 @@ namespace LLTrace return mStorage[index]; } + LL_FORCE_INLINE const ACCUMULATOR& operator[](size_t index) const + { + return mStorage[index]; + } + void addSamples(const AccumulatorBuffer& other) { llassert(mNextStorageSlot == other.mNextStorageSlot); @@ -178,7 +183,7 @@ namespace LLTrace } ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) { return (*buffer)[mAccumulatorIndex]; } - const ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) const { return (*buffer)[mAccumulatorIndex]; } + const ACCUMULATOR& getAccumulator(const AccumulatorBuffer* buffer) const { return (*buffer)[mAccumulatorIndex]; } protected: std::string mName; @@ -213,9 +218,9 @@ namespace LLTrace { mMax = value; } - F32 old_mean = mMean; - mMean += ((F32)value - old_mean) / (F32)mNumSamples; - mVarianceSum += ((F32)value - old_mean) * ((F32)value - mMean); + F64 old_mean = mMean; + mMean += ((F64)value - old_mean) / (F64)mNumSamples; + mVarianceSum += ((F64)value - old_mean) * ((F64)value - mMean); mLastValue = value; } @@ -231,14 +236,14 @@ namespace LLTrace mMax = other.mMax; } mNumSamples += other.mNumSamples; - F32 weight = (F32)mNumSamples / (F32)(mNumSamples + other.mNumSamples); + F64 weight = (F64)mNumSamples / (F64)(mNumSamples + other.mNumSamples); mMean = mMean * weight + other.mMean * (1.f - weight); - F32 n_1 = (F32)mNumSamples, - n_2 = (F32)other.mNumSamples; - F32 m_1 = mMean, + F64 n_1 = (F64)mNumSamples, + n_2 = (F64)other.mNumSamples; + F64 m_1 = mMean, m_2 = other.mMean; - F32 sd_1 = getStandardDeviation(), + F64 sd_1 = getStandardDeviation(), sd_2 = other.getStandardDeviation(); // combine variance (and hence standard deviation) of 2 different sized sample groups using // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm @@ -275,8 +280,8 @@ namespace LLTrace T getMin() const { return mMin; } T getMax() const { return mMax; } T getLastValue() const { return mLastValue; } - F32 getMean() const { return mMean; } - F32 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } + F64 getMean() const { return mMean; } + F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } private: T mSum, @@ -284,17 +289,17 @@ namespace LLTrace mMax, mLastValue; - F32 mMean, + F64 mMean, mVarianceSum; U32 mNumSamples; }; template - class LL_COMMON_API RateAccumulator + class LL_COMMON_API CountAccumulator { public: - RateAccumulator() + CountAccumulator() : mSum(0), mNumSamples(0) {} @@ -305,7 +310,7 @@ namespace LLTrace mSum += value; } - void addSamples(const RateAccumulator& other) + void addSamples(const CountAccumulator& other) { mSum += other.mSum; mNumSamples += other.mNumSamples; @@ -325,7 +330,7 @@ namespace LLTrace U32 mNumSamples; }; - template + template class LL_COMMON_API Measurement : public TraceType >, public LLInstanceTracker, std::string> @@ -352,8 +357,8 @@ namespace LLTrace public: typedef typename T::storage_t storage_t; typedef typename T::base_unit_t base_unit_t; - typedef Measurement base_measurement_t; + Measurement(const char* name, const char* description = NULL) : Measurement(name) {} @@ -361,20 +366,20 @@ namespace LLTrace template void sample(UNIT_T value) { - base_measurement_t::sample(value.value()); + base_measurement_t::sample(((T)value).value()); } }; - template - class LL_COMMON_API Rate - : public TraceType >, - public LLInstanceTracker, std::string> + template + class LL_COMMON_API Count + : public TraceType >, + public LLInstanceTracker, std::string> { public: typedef T storage_t; typedef T base_unit_t; - Rate(const char* name, const char* description = NULL) + Count(const char* name, const char* description = NULL) : TraceType(name), LLInstanceTracker(name) {} @@ -386,53 +391,23 @@ namespace LLTrace }; template - class LL_COMMON_API Rate - : public Rate + class LL_COMMON_API 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; - Rate(const char* name, const char* description = NULL) - : Rate(name) + Count(const char* name, const char* description = NULL) + : Count(name) {} template void add(UNIT_T value) { - getPrimaryAccumulator().add(value.value()); - } - }; - - template - class LL_COMMON_API Count - { - public: - typedef typename Rate::base_unit_t base_unit_t; - - Count(const char* name) - : mIncrease(name + "_increase"), - mDecrease(name + "_decrease"), - mTotal(name) - {} - - void count(T value) - { - if (value < 0) - { - mDecrease.add(value * -1); - } - else - { - mIncrease.add(value); - } - mTotal.add(value); + base_count_t::add(((T)value).value()); } - private: - friend LLTrace::Recording; - Rate mIncrease; - Rate mDecrease; - Rate mTotal; }; class LL_COMMON_API TimerAccumulator diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 5d7b231b7d..9a769ff344 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -39,8 +39,8 @@ namespace LLTrace Recording::Recording() : mElapsedSeconds(0), - mRates(new AccumulatorBuffer >()), - mMeasurements(new AccumulatorBuffer >()), + mCounts(new AccumulatorBuffer >()), + mMeasurements(new AccumulatorBuffer >()), mStackTimers(new AccumulatorBuffer()) {} @@ -59,7 +59,7 @@ void Recording::update() void Recording::handleReset() { - mRates.write()->reset(); + mCounts.write()->reset(); mMeasurements.write()->reset(); mStackTimers.write()->reset(); @@ -88,21 +88,22 @@ void Recording::handleSplitTo(Recording& other) void Recording::makePrimary() { - mRates.write()->makePrimary(); + mCounts.write()->makePrimary(); mMeasurements.write()->makePrimary(); mStackTimers.write()->makePrimary(); } bool Recording::isPrimary() const { - return mRates->isPrimary(); + return mCounts->isPrimary(); } void Recording::mergeRecording( const Recording& other ) { - mRates.write()->addSamples(*other.mRates); + mCounts.write()->addSamples(*other.mCounts); mMeasurements.write()->addSamples(*other.mMeasurements); mStackTimers.write()->addSamples(*other.mStackTimers); + mElapsedSeconds += other.mElapsedSeconds; } /////////////////////////////////////////////////////////////////////// @@ -149,9 +150,9 @@ Recording& PeriodicRecording::getTotalRecording() if (!mTotalValid) { mTotalRecording.reset(); - for (S32 i = (mCurPeriod + 1) % mNumPeriods; i < mCurPeriod; i++) + for (S32 i = mCurPeriod + 1; i < mCurPeriod + mNumPeriods; i++) { - mTotalRecording.mergeRecording(mRecordingPeriods[i]); + mTotalRecording.mergeRecording(mRecordingPeriods[i % mNumPeriods]); } } mTotalValid = true; @@ -212,7 +213,6 @@ void ExtendableRecording::handleSplitTo( ExtendableRecording& other ) PeriodicRecording& get_frame_recording() { static PeriodicRecording sRecording(64); - sRecording.start(); return sRecording; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 924a7bffd5..d9ac8c327a 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -111,17 +111,17 @@ namespace LLTrace void update(); - // Rate accessors + // Count accessors template - typename Rate::base_unit_t getSum(const Rate& stat) const + typename Count::base_unit_t getSum(const Count& stat) const { - return (typename Rate::base_unit_t)stat.getAccumulator(mRates).getSum(); + return (typename Count::base_unit_t)stat.getAccumulator(mCounts).getSum(); } template - typename Rate::base_unit_t getPerSec(const Rate& stat) const + typename Count::base_unit_t getPerSec(const Count& stat) const { - return (typename Rate::base_unit_t)stat.getAccumulator(mRates).getSum() / mElapsedSeconds; + return (typename Count::base_unit_t)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; } // Measurement accessors @@ -135,7 +135,7 @@ namespace LLTrace template typename Measurement::base_unit_t getPerSec(const Measurement& stat) const { - return (typename Rate::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; + return (typename Count::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; } template @@ -151,7 +151,7 @@ namespace LLTrace } template - typename Measurement::base_unit_t getMean(const Measurement& stat) const + typename Measurement::base_unit_t getMean(Measurement& stat) const { return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMean(); } @@ -168,56 +168,7 @@ namespace LLTrace return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getLastValue(); } - // Count accessors - template - typename Count::base_unit_t getSum(const Count& stat) const - { - return getSum(stat.mTotal); - } - - template - typename Count::base_unit_t getPerSec(const Count& stat) const - { - return getPerSec(stat.mTotal); - } - - template - typename Count::base_unit_t getIncrease(const Count& stat) const - { - return getPerSec(stat.mTotal); - } - - template - typename Count::base_unit_t getIncreasePerSec(const Count& stat) const - { - return getPerSec(stat.mIncrease); - } - - template - typename Count::base_unit_t getDecrease(const Count& stat) const - { - return getPerSec(stat.mDecrease); - } - - template - typename Count::base_unit_t getDecreasePerSec(const Count& stat) const - { - return getPerSec(stat.mDecrease); - } - - template - typename Count::base_unit_t getChurn(const Count& stat) const - { - return getIncrease(stat) + getDecrease(stat); - } - - template - typename Count::base_unit_t getChurnPerSec(const Count& stat) const - { - return getIncreasePerSec(stat) + getDecreasePerSec(stat); - } - - F64 getSampleTime() const { return mElapsedSeconds; } + F64 getDuration() const { return mElapsedSeconds; } // implementation for LLVCRControlsMixin /*virtual*/ void handleStart(); @@ -230,8 +181,8 @@ namespace LLTrace // returns data for current thread class ThreadRecorder* getThreadRecorder(); - LLCopyOnWritePointer > > mRates; - LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > > mCounts; + LLCopyOnWritePointer > > mMeasurements; LLCopyOnWritePointer > mStackTimers; LLTimer mSamplingTimer; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 48aa1a42f2..02dc55771b 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -114,10 +114,10 @@ ThreadRecorder::ActiveRecording::ActiveRecording( Recording* target ) void ThreadRecorder::ActiveRecording::moveBaselineToTarget() { mTargetRecording->mMeasurements.write()->addSamples(*mBaseline.mMeasurements); - mTargetRecording->mRates.write()->addSamples(*mBaseline.mRates); + mTargetRecording->mCounts.write()->addSamples(*mBaseline.mCounts); mTargetRecording->mStackTimers.write()->addSamples(*mBaseline.mStackTimers); mBaseline.mMeasurements.write()->reset(); - mBaseline.mRates.write()->reset(); + mBaseline.mCounts.write()->reset(); mBaseline.mStackTimers.write()->reset(); } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 2664bd77e9..090e42607e 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -51,7 +51,7 @@ struct LLUnitType : public BASE_UNIT value_t value() const { - return convertToDerived(mValue); + return convertToDerived(mBaseValue); } template @@ -72,22 +72,22 @@ struct LLUnitType : public BASE_UNIT unit_t operator + (const unit_t other) const { - return unit_t(mValue + other.mValue); + return unit_t(mBaseValue + other.mBaseValue); } unit_t operator - (const unit_t other) const { - return unit_t(mValue - other.mValue); + return unit_t(mBaseValue - other.mBaseValue); } unit_t operator * (value_t multiplicand) const { - return unit_t(mValue * multiplicand); + return unit_t(mBaseValue * multiplicand); } unit_t operator / (value_t divisor) const { - return unit_t(mValue / divisor); + return unit_t(mBaseValue / divisor); } }; @@ -100,11 +100,11 @@ struct LLUnitType typedef void is_unit_t; LLUnitType() - : mValue() + : mBaseValue() {} explicit LLUnitType(value_t value) - : mValue(value) + : mBaseValue(value) {} unit_t& operator=(value_t value) @@ -118,7 +118,7 @@ struct LLUnitType return static_cast(*this); } - value_t value() { return mValue; } + value_t value() const { return mBaseValue; } static value_t convertToBase(value_t derived_value) { @@ -132,73 +132,73 @@ struct LLUnitType unit_t operator + (const unit_t other) const { - return unit_t(mValue + other.mValue); + return unit_t(mBaseValue + other.mBaseValue); } void operator += (const unit_t other) { - mValue += other.mValue; + mBaseValue += other.mBaseValue; } unit_t operator - (const unit_t other) const { - return unit_t(mValue - other.mValue); + return unit_t(mBaseValue - other.mBaseValue); } void operator -= (const unit_t other) { - mValue -= other.mValue; + mBaseValue -= other.mBaseValue; } unit_t operator * (value_t multiplicand) const { - return unit_t(mValue * multiplicand); + return unit_t(mBaseValue * multiplicand); } void operator *= (value_t multiplicand) { - mValue *= multiplicand; + mBaseValue *= multiplicand; } unit_t operator / (value_t divisor) const { - return unit_t(mValue / divisor); + return unit_t(mBaseValue / divisor); } void operator /= (value_t divisor) { - mValue /= divisor; + mBaseValue /= divisor; } protected: void setBaseValue(value_t value) { - mValue = value; + mBaseValue = value; } - value_t mValue; + value_t mBaseValue; }; -#define LL_DECLARE_BASE_UNIT(unit_name) \ - template \ - struct unit_name : public LLUnitType > \ - { \ - typedef unit_name base_unit_t; \ - typedef STORAGE_TYPE storage_t; \ +#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(STORAGE_TYPE value) \ + unit_name(F64 value) \ : LLUnitType(value) \ - {} \ - \ - unit_name() \ - {} \ - \ + {} \ + \ + unit_name() \ + {} \ + \ template \ unit_name(const LLUnitType& source) \ - { \ - setBaseValue(source.unit_t::value()); \ - } \ - \ + { \ + setBaseValue((F64)source.unit_name::unit_t::value()); \ + } \ + \ using LLUnitType::operator +; \ using LLUnitType::operator +=; \ using LLUnitType::operator -; \ @@ -209,36 +209,36 @@ protected: using LLUnitType::operator /=; \ }; -#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ - template \ - struct derived_unit : public LLUnitType, derived_unit > \ - { \ - typedef base_unit base_unit_t; \ - typedef STORAGE_TYPE storage_t; \ - \ - derived_unit(value_t value) \ - : LLUnitType(value) \ - {} \ - \ - derived_unit() \ - {} \ - \ - template \ - derived_unit(const LLUnitType, SOURCE_TYPE>& source) \ - { \ - setBaseValue(source.base_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) \ + 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 /=; \ }; namespace LLUnits @@ -248,7 +248,7 @@ namespace LLUnits LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.f / 8.f)); - LL_DECLARE_DERIVED_UNIT(Bytes, Kilobit, (1024 / 8)); + LL_DECLARE_DERIVED_UNIT(Bytes, Kilobits, (1024 / 8)); LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); -- cgit v1.2.3 From 8d2f7a526545a10cd3669bf837a0b6f02cf5fe71 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 15 Oct 2012 19:43:35 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system converted all remaining LLViewerStats to lltrace --- indra/llcommon/llstatenums.h | 2 +- indra/llcommon/lltrace.h | 1 + indra/llcommon/lltracerecording.h | 15 ++++++++++++++- indra/llcommon/llunit.h | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llstatenums.h b/indra/llcommon/llstatenums.h index 81c4085d16..ab9b6709e8 100644 --- a/indra/llcommon/llstatenums.h +++ b/indra/llcommon/llstatenums.h @@ -26,7 +26,7 @@ #ifndef LL_LLSTATENUMS_H #define LL_LLSTATENUMS_H -enum +enum ESimStatID { LL_SIM_STAT_TIME_DILATION = 0, LL_SIM_STAT_FPS = 1, diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 221c226ad1..3e19c83bd7 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -282,6 +282,7 @@ namespace LLTrace T getLastValue() const { return mLastValue; } F64 getMean() const { return mMean; } F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } + U32 getSampleCount() const { return mNumSamples; } private: T mSum, diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index d9ac8c327a..bd4b944e5a 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -168,6 +168,12 @@ namespace LLTrace return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getLastValue(); } + template + U32 getSampleCount(const Measurement& stat) const + { + return stat.getAccumulator(mMeasurements).getSampleCount(); + } + F64 getDuration() const { return mElapsedSeconds; } // implementation for LLVCRControlsMixin @@ -208,7 +214,7 @@ namespace LLTrace return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; } - Recording& getCurRecordingPeriod() + Recording getCurRecordingPeriod() { return mRecordingPeriods[mCurPeriod]; } @@ -218,6 +224,13 @@ namespace LLTrace return mRecordingPeriods[mCurPeriod]; } + Recording snapshotCurRecordingPeriod() const + { + Recording recording_copy(getCurRecordingPeriod()); + recording_copy.stop(); + return recording_copy; + } + Recording& getTotalRecording(); private: diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 090e42607e..e8f6b2b2ba 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -261,6 +261,10 @@ namespace LLUnits LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.f / (1000000.f))); LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.f / (1000000000.f))); + LL_DECLARE_BASE_UNIT(Meters); + LL_DECLARE_DERIVED_UNIT(Meters, Kilometers, 1000); + LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, 1 / 100); + LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, 1 / 1000); } #endif // LL_LLUNIT_H -- cgit v1.2.3 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 From a52d203a4f1d2988e8ffba16258f3f132f22f56d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 17 Oct 2012 20:00:07 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system started conversion of llviewerassetstats removed old, dead LLViewerStats code made units tracing require units declaration clean up of units handling --- indra/llcommon/lltrace.h | 44 +++++++++--------- indra/llcommon/lltracerecording.h | 95 +++++++++++++++++++++++++++++++-------- indra/llcommon/llunit.h | 34 ++++++++++---- 3 files changed, 125 insertions(+), 48 deletions(-) (limited to 'indra/llcommon') 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 class LL_COMMON_API TraceType + : public LLInstanceTracker, std::string> { public: TraceType(const char* name, const char* description = NULL) - : mName(name), + : LLInstanceTracker(name), + mName(name), mDescription(description ? description : "") { mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); @@ -355,18 +357,17 @@ namespace LLTrace U32 mNumSamples; }; + typedef TraceType > measurement_common_t; + template class LL_COMMON_API Measurement - : public TraceType >, - public LLInstanceTracker, std::string> + : public TraceType > { 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 - class LL_COMMON_API Measurement - : public Measurement + class LL_COMMON_API Measurement + : public TraceType > { public: typedef typename T::storage_t storage_t; - typedef typename T::base_unit_t base_unit_t; typedef Measurement base_measurement_t; Measurement(const char* name, const char* description = NULL) - : Measurement(name, description) + : TraceType(name, description) {} template 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 > count_common_t; + template class LL_COMMON_API Count - : public TraceType >, - public LLInstanceTracker, std::string> + : public TraceType > { 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 - class LL_COMMON_API Count - : public Count + class LL_COMMON_API Count + : public TraceType > { public: typedef typename T::storage_t storage_t; - typedef typename T::base_unit_t base_unit_t; typedef Count base_count_t; Count(const char* name, const char* description = NULL) - : Count(name) + : TraceType(name) {} template 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 + T getSum(const TraceType >& stat) const + { + return (T)stat.getAccumulator(mCounts).getSum(); + } + template - typename Count::base_unit_t getSum(const Count& stat) const + T getSum(const Count& stat) const + { + return (T)stat.getAccumulator(mCounts).getSum(); + } + + template + T getPerSec(const TraceType >& stat) const { - return (typename Count::base_unit_t)stat.getAccumulator(mCounts).getSum(); + return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; } template - typename Count::base_unit_t getPerSec(const Count& stat) const + T getPerSec(const Count& stat) const { - return (typename Count::base_unit_t)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; + return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; } // Measurement accessors + template + T getSum(const TraceType >& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getSum(); + + } + template - typename Measurement::base_unit_t getSum(const Measurement& stat) const + T getSum(const Measurement& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getSum(); + return (T)stat.getAccumulator(mMeasurements).getSum(); + + } + template + T getPerSec(const TraceType >& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; } template - typename Measurement::base_unit_t getPerSec(const Measurement& stat) const + T getPerSec(const Measurement& stat) const { return (typename Count::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; } - template - typename Measurement::base_unit_t getMin(const Measurement& stat) const + template + T getMin(const TraceType >& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMin(); + return (T)stat.getAccumulator(mMeasurements).getMin(); } template - typename Measurement::base_unit_t getMax(const Measurement& stat) const + T getMin(const Measurement& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMax(); + return (T)stat.getAccumulator(mMeasurements).getMin(); + } + + + template + T getMax(const TraceType >& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getMax(); } template - typename Measurement::base_unit_t getMean(Measurement& stat) const + T getMax(const Measurement& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getMax(); + } + + template + T getMean(const TraceType >& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getMean(); + return (T)stat.getAccumulator(mMeasurements).getMean(); } template - typename Measurement::base_unit_t getStandardDeviation(const Measurement& stat) const + T getMean(Measurement& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getMean(); + } + + template + T getStandardDeviation(const TraceType >& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getStandardDeviation(); + return (T)stat.getAccumulator(mMeasurements).getStandardDeviation(); } template - typename Measurement::base_unit_t getLastValue(const Measurement& stat) const + T getStandardDeviation(const Measurement& stat) const { - return (typename Measurement::base_unit_t)stat.getAccumulator(mMeasurements).getLastValue(); + return (T)stat.getAccumulator(mMeasurements).getStandardDeviation(); + } + + template + T getLastValue(const TraceType >& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getLastValue(); } template - U32 getSampleCount(const Measurement& stat) const + T getLastValue(const Measurement& stat) const + { + return (T)stat.getAccumulator(mMeasurements).getLastValue(); + } + + + template + U32 getSampleCount(const TraceType >& 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 - storage_t value() const + storage_t as() const { return CONVERTED_TYPE(*this).value(); } @@ -80,8 +80,7 @@ struct LLUnitType { 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_t value() const { return mBaseValue; } + template + 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 first, LLUni template \ unit_name(LLUnitType, SOURCE_TYPE> source) \ { \ - setBaseValue((storage_t)source.unit_name::unit_t::value()); \ + assignFrom(source); \ } \ \ - }; + template \ + void assignFrom(LLUnitType, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.unit_name::unit_t::value()); \ + } \ + \ + }; \ #define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ template \ @@ -372,12 +384,18 @@ bool operator != (LLUnitType first, LLUni template \ derived_unit(LLUnitType, SOURCE_TYPE> source) \ { \ - setBaseValue((storage_t)source.base_unit::unit_t::value()); \ + assignFrom(source); \ + } \ + \ + template \ + void assignFrom(LLUnitType, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.base_unit::unit_t::value()); \ } \ \ static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ \ - }; + }; \ namespace LLUnit { -- cgit v1.2.3 From 1fadd6138eebf980776f80b9642f4c19279fcadd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 18 Oct 2012 17:32:44 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed trace recording on background threads hitting null pointer --- indra/llcommon/lltrace.h | 19 ++++++++++++++----- indra/llcommon/lltracethreadrecorder.cpp | 9 ++++----- indra/llcommon/lltracethreadrecorder.h | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 2a479b31d7..2cdae4b0d2 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -167,15 +167,24 @@ namespace LLTrace size_t next_slot = mNextStorageSlot++; if (next_slot >= mStorageSize) { - size_t new_size = mStorageSize + (mStorageSize >> 2); - delete [] mStorage; - mStorage = new ACCUMULATOR[new_size]; - mStorageSize = new_size; + resize(mStorageSize + (mStorageSize >> 2)); } - llassert(next_slot < mStorageSize); + llassert(mStorage && next_slot < mStorageSize); return next_slot; } + void resize(size_t new_size) + { + ACCUMULATOR* old_storage = mStorage; + mStorage = new ACCUMULATOR[new_size]; + for (S32 i = 0; i < mStorageSize; i++) + { + mStorage[i] = old_storage[i]; + } + mStorageSize = new_size; + delete[] old_storage; + } + static AccumulatorBuffer& getDefaultBuffer() { static AccumulatorBuffer sBuffer(STATIC_ALLOC); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 02dc55771b..e81333f7f2 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -127,7 +127,6 @@ void ThreadRecorder::ActiveRecording::moveBaselineToTarget() /////////////////////////////////////////////////////////////////////// SlaveThreadRecorder::SlaveThreadRecorder() -: ThreadRecorder(getMasterThreadRecorder()) { getMasterThreadRecorder().addSlaveThread(this); } @@ -149,14 +148,14 @@ void SlaveThreadRecorder::pushToMaster() void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) { - LLMutexLock lock(&mRecorderMutex); - mRecorder.mergeRecording(source); + LLMutexLock lock(&mRecordingMutex); + mRecording.mergeRecording(source); } void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) { - LLMutexLock lock(&mRecorderMutex); - sink.mergeRecording(mRecorder); + LLMutexLock lock(&mRecordingMutex); + sink.mergeRecording(mRecording); } /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 678b1a89f0..c9231265af 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -114,8 +114,8 @@ namespace LLTrace void copyFrom(const Recording& source); void copyTo(Recording& sink); private: - LLMutex mRecorderMutex; - Recording mRecorder; + LLMutex mRecordingMutex; + Recording mRecording; }; SharedData mSharedData; }; -- cgit v1.2.3 From 176ffa54b44f2ef73f23e3252dd439f52fab3265 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 19 Oct 2012 19:35:01 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system finished most of conversion of llviewerassetstats ported some param block fixes from viewer-chui converted viewer asset stats to param block format --- indra/llcommon/llinitparam.cpp | 5 ----- indra/llcommon/llinitparam.h | 43 +++++++++++++++++++++++++++++++------ indra/llcommon/llsdparam.cpp | 45 +++++++++++++++++++-------------------- indra/llcommon/lltracerecording.h | 2 +- 4 files changed, 59 insertions(+), 36 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index db72aa19b9..54e98e66f3 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -196,12 +196,7 @@ namespace LLInitParam if (serialize_func) { const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; - // each param descriptor remembers its serial number - // so we can inspect the same param under different names - // and see that it has the same number - name_stack.push_back(std::make_pair("", true)); serialize_func(*param, parser, name_stack, diff_param); - name_stack.pop_back(); } } diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index 9a6d1eff5c..b7607e91b9 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -1156,10 +1156,18 @@ namespace LLInitParam static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name) { + Parser::name_stack_range_t new_name_stack_range(name_stack_range); self_t& typed_param = static_cast(param); value_t value; + + // pop first element if empty string + if (new_name_stack_range.first != new_name_stack_range.second && new_name_stack_range.first->first.empty()) + { + ++new_name_stack_range.first; + } + // no further names in stack, attempt to parse value now - if (name_stack_range.first == name_stack_range.second) + if (new_name_stack_range.first == new_name_stack_range.second) { // attempt to read value directly if (parser.readValue(value)) @@ -1192,14 +1200,14 @@ namespace LLInitParam static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided() || name_stack.empty()) return; + if (!typed_param.isProvided()) return; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; ++it) { std::string key = it->getValueName(); - name_stack.back().second = true; + name_stack.push_back(std::make_pair(std::string(), true)); if(key.empty()) // not parsed via name values, write out value directly @@ -1221,6 +1229,8 @@ namespace LLInitParam break; } } + + name_stack.pop_back(); } } @@ -1351,10 +1361,19 @@ namespace LLInitParam static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name) { + Parser::name_stack_range_t new_name_stack_range(name_stack_range); self_t& typed_param = static_cast(param); bool new_value = false; + bool new_array_value = false; + + // pop first element if empty string + if (new_name_stack_range.first != new_name_stack_range.second && new_name_stack_range.first->first.empty()) + { + new_array_value = new_name_stack_range.first->second; + ++new_name_stack_range.first; + } - if (new_name || typed_param.mValues.empty()) + if (new_name || new_array_value || typed_param.mValues.empty()) { new_value = true; typed_param.mValues.push_back(value_t()); @@ -1363,9 +1382,13 @@ namespace LLInitParam param_value_t& value = typed_param.mValues.back(); // attempt to parse block... - if(value.deserializeBlock(parser, name_stack_range, new_name)) + if(value.deserializeBlock(parser, new_name_stack_range, new_name)) { typed_param.setProvided(); + if (new_array_value) + { + name_stack_range.first->second = false; + } return true; } else if(name_value_lookup_t::valueNamesExist()) @@ -1379,6 +1402,10 @@ namespace LLInitParam { typed_param.mValues.back().setValueName(name); typed_param.setProvided(); + if (new_array_value) + { + name_stack_range.first->second = false; + } return true; } @@ -1396,13 +1423,13 @@ namespace LLInitParam static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided() || name_stack.empty()) return; + if (!typed_param.isProvided()) return; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; ++it) { - name_stack.back().second = true; + name_stack.push_back(std::make_pair(std::string(), true)); std::string key = it->getValueName(); if (!key.empty()) @@ -1415,6 +1442,8 @@ namespace LLInitParam { it->serializeBlock(parser, name_stack, NULL); } + + name_stack.pop_back(); } } diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index 0e29873bb0..4b8a8dba5c 100644 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -223,10 +223,14 @@ LLSD& LLParamSDParserUtilities::getSDWriteNode(LLSD& input, LLInitParam::Parser: { bool new_traversal = it->second; - LLSD* child_sd = it->first.empty() ? sd_to_write : &(*sd_to_write)[it->first]; - - if (child_sd->isArray()) + LLSD* child_sd; + if (it->first.empty()) + { + child_sd = sd_to_write; + if (child_sd->isUndefined()) { + *child_sd = LLSD::emptyArray(); + } if (new_traversal) { // write to new element at end @@ -240,22 +244,7 @@ LLSD& LLParamSDParserUtilities::getSDWriteNode(LLSD& input, LLInitParam::Parser: } else { - if (new_traversal - && child_sd->isDefined() - && !child_sd->isArray()) - { - // copy child contents into first element of an array - LLSD new_array = LLSD::emptyArray(); - new_array.append(*child_sd); - // assign array to slot that previously held the single value - *child_sd = new_array; - // return next element in that array - sd_to_write = &((*child_sd)[1]); - } - else - { - sd_to_write = child_sd; - } + sd_to_write = &(*sd_to_write)[it->first]; } it->second = false; } @@ -283,8 +272,9 @@ void LLParamSDParserUtilities::readSDValues(read_sd_cb_t cb, const LLSD& sd, LLI it != sd.endArray(); ++it) { - stack.back().second = true; + stack.push_back(make_pair(std::string(), true)); readSDValues(cb, *it, stack); + stack.pop_back(); } } else if (sd.isUndefined()) @@ -315,6 +305,12 @@ namespace LLInitParam // block param interface bool ParamValue, false>::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack, bool new_name) { + if (name_stack.first == name_stack.second + && p.readValue(mValue)) + { + return true; + } + LLSD& sd = LLParamSDParserUtilities::getSDWriteNode(mValue, name_stack); LLSD::String string; @@ -335,8 +331,11 @@ namespace LLInitParam void ParamValue, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const { - // read from LLSD value and serialize out to parser (which could be LLSD, XUI, etc) - Parser::name_stack_t stack; - LLParamSDParserUtilities::readSDValues(boost::bind(&serializeElement, boost::ref(p), _1, _2), mValue, stack); + // attempt to write LLSD out directly + if (!p.writeValue(mValue, name_stack)) + { + // otherwise read from LLSD value and serialize out to parser (which could be LLSD, XUI, etc) + LLParamSDParserUtilities::readSDValues(boost::bind(&serializeElement, boost::ref(p), _1, _2), mValue, name_stack); + } } } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 25f4f5c721..d3f001ab6a 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -231,7 +231,7 @@ namespace LLTrace return stat.getAccumulator(mMeasurements).getSampleCount(); } - F64 getDuration() const { return mElapsedSeconds; } + LLUnit::Seconds getDuration() const { return mElapsedSeconds; } // implementation for LLVCRControlsMixin /*virtual*/ void handleStart(); -- cgit v1.2.3 From d6634fcd2433e18eea1a9bf31da6d7e531817d77 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 22 Oct 2012 19:54:10 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system sanitized param block code to accept isValid and isProvided at any point added predicates to control serialization --- indra/llcommon/CMakeLists.txt | 2 + indra/llcommon/llinitparam.cpp | 35 +++++-- indra/llcommon/llinitparam.h | 221 ++++++++++++++++++++++++++--------------- indra/llcommon/llpredicate.cpp | 33 ++++++ indra/llcommon/llpredicate.h | 173 ++++++++++++++++++++++++++++++++ indra/llcommon/llsdparam.cpp | 2 +- 6 files changed, 376 insertions(+), 90 deletions(-) create mode 100644 indra/llcommon/llpredicate.cpp create mode 100644 indra/llcommon/llpredicate.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index c0e9266aa9..d876842cf1 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -77,6 +77,7 @@ set(llcommon_SOURCE_FILES llmutex.cpp lloptioninterface.cpp llptrto.cpp + llpredicate.cpp llprocess.cpp llprocessor.cpp llqueuedthread.cpp @@ -205,6 +206,7 @@ set(llcommon_HEADER_FILES llnametable.h lloptioninterface.h llpointer.h + llpredicate.h llpreprocessor.h llpriqueuemap.h llprocess.h diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index 54e98e66f3..a63e792925 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -164,24 +164,37 @@ namespace LLInitParam bool BaseBlock::validateBlock(bool emit_errors) const { - const BlockDescriptor& block_data = mostDerivedBlockDescriptor(); - for (BlockDescriptor::param_validation_list_t::const_iterator it = block_data.mValidationList.begin(); it != block_data.mValidationList.end(); ++it) + // only validate block when it hasn't already passed validation with current data + if (!mValidated) { - const Param* param = getParamFromHandle(it->first); - if (!it->second(param)) + const BlockDescriptor& block_data = mostDerivedBlockDescriptor(); + for (BlockDescriptor::param_validation_list_t::const_iterator it = block_data.mValidationList.begin(); it != block_data.mValidationList.end(); ++it) { - if (emit_errors) + const Param* param = getParamFromHandle(it->first); + if (!it->second(param)) { - llwarns << "Invalid param \"" << getParamName(block_data, param) << "\"" << llendl; + if (emit_errors) + { + llwarns << "Invalid param \"" << getParamName(block_data, param) << "\"" << llendl; + } + return false; } - return false; } + mValidated = true; } - return true; + return mValidated; } - void BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const + void BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const LLInitParam::BaseBlock* diff_block) const { + if (!isProvided()) + { + if ((~predicate_rule_t(PROVIDED) && predicate_rule).isTriviallyFalse()) + { + return; + } + } + // named param is one like LLView::Params::follows // unnamed param is like LLView::Params::rect - implicit const BlockDescriptor& block_data = mostDerivedBlockDescriptor(); @@ -196,7 +209,7 @@ namespace LLInitParam if (serialize_func) { const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; - serialize_func(*param, parser, name_stack, diff_param); + serialize_func(*param, parser, name_stack, predicate_rule, diff_param); } } @@ -232,7 +245,7 @@ namespace LLInitParam name_stack.push_back(std::make_pair(it->first, !duplicate)); const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; - serialize_func(*param, parser, name_stack, diff_param); + serialize_func(*param, parser, name_stack, predicate_rule, diff_param); name_stack.pop_back(); } } diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index b7607e91b9..18c9669fba 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -32,10 +32,11 @@ #include #include #include -#include +//#include #include "llerror.h" #include "llstl.h" +#include "llpredicate.h" namespace LLInitParam { @@ -211,7 +212,6 @@ namespace LLInitParam LOG_CLASS(Parser); public: - typedef std::vector > name_stack_t; typedef std::pair name_stack_range_t; typedef std::vector possible_values_t; @@ -293,6 +293,17 @@ namespace LLInitParam class Param; + enum ESerializePredicates + { + PROVIDED, + REQUIRED, + VALID, + NON_DEFAULT + }; + + typedef LLPredicate::Rule predicate_rule_t; + + // various callbacks and constraints associated with an individual param struct LL_COMMON_API ParamDescriptor { @@ -303,8 +314,8 @@ namespace LLInitParam typedef bool(*merge_func_t)(Param&, const Param&, bool); typedef bool(*deserialize_func_t)(Param&, Parser&, const Parser::name_stack_range_t&, bool); - typedef void(*serialize_func_t)(const Param&, Parser&, Parser::name_stack_t&, const Param* diff_param); - typedef void(*inspect_func_t)(const Param&, Parser&, Parser::name_stack_t&, S32 min_count, S32 max_count); + typedef void(*serialize_func_t)(const Param&, Parser&, Parser::name_stack_t&, const predicate_rule_t, const Param*); + typedef void(*inspect_func_t)(const Param&, Parser&, Parser::name_stack_t&, S32, S32); typedef bool(*validation_func_t)(const Param*); ParamDescriptor(param_handle_t p, @@ -331,7 +342,7 @@ namespace LLInitParam UserData* mUserData; }; - typedef boost::shared_ptr ParamDescriptorPtr; + typedef ParamDescriptor* ParamDescriptorPtr; // each derived Block class keeps a static data structure maintaining offsets to various params class LL_COMMON_API BlockDescriptor @@ -484,12 +495,28 @@ namespace LLInitParam LOG_CLASS(BaseBlock); friend class Param; + BaseBlock() + : mValidated(false), + mParamProvided(false) + {} + virtual ~BaseBlock() {} bool submitValue(Parser::name_stack_t& name_stack, Parser& p, bool silent=false); param_handle_t getHandleFromParam(const Param* param) const; bool validateBlock(bool emit_errors = true) const; + bool isProvided() const + { + return mParamProvided; + } + + bool isValid() const + { + return validateBlock(false); + } + + Param* getParamFromHandle(const param_handle_t param_handle) { if (param_handle == 0) return NULL; @@ -507,10 +534,19 @@ namespace LLInitParam void addSynonym(Param& param, const std::string& synonym); // Blocks can override this to do custom tracking of changes - virtual void paramChanged(const Param& changed_param, bool user_provided) {} + virtual void paramChanged(const Param& changed_param, bool user_provided) + { + if (user_provided) + { + // a child param has been explicitly changed + // so *some* aspect of this block is now provided + mValidated = false; + mParamProvided = true; + } + } bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; + void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t rule = predicate_rule_t(), const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const; virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } @@ -549,6 +585,9 @@ namespace LLInitParam return sBlockDescriptor; } + mutable bool mValidated; // lazy validation flag + bool mParamProvided; + private: const std::string& getParamName(const BlockDescriptor& block_data, const Param* paramp) const; }; @@ -688,13 +727,11 @@ namespace LLInitParam typedef ParamValue self_t; ParamValue() - : T(), - mValidated(false) + : T() {} ParamValue(value_assignment_t other) - : T(other), - mValidated(false) + : T(other) {} void setValue(value_assignment_t val) @@ -736,9 +773,6 @@ namespace LLInitParam return *this; } - - protected: - mutable bool mValidated; // lazy validation flag }; template @@ -836,6 +870,8 @@ namespace LLInitParam bool isProvided() const { return Param::anyProvided(); } + bool isValid() const { return true; } + static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name) { self_t& typed_param = static_cast(param); @@ -870,10 +906,26 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const Param* diff_param) { const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + const self_t* diff_typed_param = static_cast(diff_param); + + LLPredicate::Value predicate; + if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) + { + predicate.set(NON_DEFAULT); + } + if (typed_param.isValid()) + { + predicate.set(VALID); + if (typed_param.anyProvided()) + { + predicate.set(PROVIDED); + } + } + + if (!predicate_rule.check(predicate)) return; if (!name_stack.empty()) { @@ -886,18 +938,18 @@ namespace LLInitParam if (!key.empty()) { - if (!diff_param || !ParamCompare::equals(static_cast(diff_param)->getValueName(), key)) + if (!diff_typed_param || !ParamCompare::equals(diff_typed_param->getValueName(), key)) { parser.writeValue(key, name_stack); } } // then try to serialize value directly - else if (!diff_param || !ParamCompare::equals(typed_param.getValue(), static_cast(diff_param)->getValue())) + else if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) { if (!parser.writeValue(typed_param.getValue(), name_stack)) { std::string calculated_key = typed_param.calcValueName(typed_param.getValue()); - if (!diff_param || !ParamCompare::equals(static_cast(diff_param)->getValueName(), calculated_key)) + if (!diff_typed_param || !ParamCompare::equals(diff_typed_param->getValueName(), calculated_key)) { parser.writeValue(calculated_key, name_stack); } @@ -1014,10 +1066,26 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const Param* diff_param) { const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + const self_t* diff_typed_param = static_cast(diff_param); + + LLPredicate::Value predicate; + if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) + { + predicate.set(NON_DEFAULT); + } + if (typed_param.isValid()) + { + predicate.set(VALID); + if (typed_param.anyProvided()) + { + predicate.set(PROVIDED); + } + } + + if (!predicate_rule.check(predicate)) return; if (!name_stack.empty()) { @@ -1034,7 +1102,7 @@ namespace LLInitParam } else { - typed_param.serializeBlock(parser, name_stack, static_cast(diff_param)); + typed_param.serializeBlock(parser, name_stack, predicate_rule, static_cast(diff_param)); } } @@ -1049,23 +1117,16 @@ namespace LLInitParam // *and* the block as a whole validates bool isProvided() const { - // only validate block when it hasn't already passed validation with current data - if (Param::anyProvided() && !param_value_t::mValidated) - { - // a sub-block is "provided" when it has been filled in enough to be valid - param_value_t::mValidated = param_value_t::validateBlock(false); - } - return Param::anyProvided() && param_value_t::mValidated; + return Param::anyProvided() && isValid(); } + using param_value_t::isValid; + // assign block contents to this param-that-is-a-block void set(value_assignment_t val, bool flag_as_provided = true) { setValue(val); param_value_t::clearValueName(); - // force revalidation of block - // next call to isProvided() will update provision status based on validity - param_value_t::mValidated = false; setProvided(flag_as_provided); } @@ -1080,9 +1141,6 @@ namespace LLInitParam param_value_t::paramChanged(changed_param, user_provided); if (user_provided) { - // a child param has been explicitly changed - // so *some* aspect of this block is now provided - param_value_t::mValidated = false; setProvided(); param_value_t::clearValueName(); } @@ -1134,7 +1192,9 @@ namespace LLInitParam typedef NAME_VALUE_LOOKUP name_value_lookup_t; TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) - : Param(block_descriptor.mCurrentBlockPtr) + : Param(block_descriptor.mCurrentBlockPtr), + mMinCount(min_count), + mMaxCount(max_count) { std::copy(value.begin(), value.end(), std::back_inserter(mValues)); @@ -1152,7 +1212,13 @@ namespace LLInitParam } } - bool isProvided() const { return Param::anyProvided(); } + bool isProvided() const { return Param::anyProvided() && isValid(); } + + bool isValid() const + { + size_t num_elements = numValidElements(); + return mMinCount < num_elements && num_elements < mMaxCount; + } static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name) { @@ -1197,7 +1263,7 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const Param* diff_param) { const self_t& typed_param = static_cast(param); if (!typed_param.isProvided()) return; @@ -1293,7 +1359,7 @@ namespace LLInitParam bool empty() const { return mValues.empty(); } size_t size() const { return mValues.size(); } - U32 numValidElements() const + size_t numValidElements() const { return mValues.size(); } @@ -1323,6 +1389,8 @@ namespace LLInitParam } container_t mValues; + size_t mMinCount, + mMaxCount; }; // container of block parameters @@ -1339,7 +1407,9 @@ namespace LLInitParam typedef NAME_VALUE_LOOKUP name_value_lookup_t; TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) - : Param(block_descriptor.mCurrentBlockPtr) + : Param(block_descriptor.mCurrentBlockPtr), + mMinCount(min_count), + mMaxCount(max_count) { std::copy(value.begin(), value.end(), back_inserter(mValues)); @@ -1357,7 +1427,14 @@ namespace LLInitParam } } - bool isProvided() const { return Param::anyProvided(); } + bool isProvided() const { return Param::anyProvided() && isValid(); } + + bool isValid() const + { + size_t num_elements = numValidElements(); + return mMinCount < num_elements && num_elements < mMaxCount; + } + static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name) { @@ -1420,9 +1497,13 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const Param* diff_param) { const self_t& typed_param = static_cast(param); + + LLPredicate::Value predicate_value; + if (typed_param.isProvided()) predicate_value.set(PROVIDED); + if (!typed_param.isProvided()) return; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); @@ -1437,10 +1518,10 @@ namespace LLInitParam parser.writeValue(key, name_stack); } // Not parsed via named values, write out value directly - // NOTE: currently we don't worry about removing default values in Multiple + // NOTE: currently we don't do diffing of Multiples else { - it->serializeBlock(parser, name_stack, NULL); + it->serializeBlock(parser, name_stack, predicate_rule, NULL); } name_stack.pop_back(); @@ -1500,14 +1581,14 @@ namespace LLInitParam bool empty() const { return mValues.empty(); } size_t size() const { return mValues.size(); } - U32 numValidElements() const + size_t numValidElements() const { - U32 count = 0; + size_t count = 0; for (const_iterator it = mValues.begin(), end_it = mValues.end(); it != end_it; ++it) { - if(it->validateBlock(false)) count++; + if(it->isValid()) count++; } return count; } @@ -1539,6 +1620,8 @@ namespace LLInitParam } container_t mValues; + size_t mMinCount, + mMaxCount; }; template @@ -1826,7 +1909,7 @@ namespace LLInitParam static bool validate(const Param* paramp) { - U32 num_valid = ((super_t*)paramp)->numValidElements(); + size_t num_valid = ((super_t*)paramp)->numValidElements(); return RANGE::minCount <= num_valid && num_valid <= RANGE::maxCount; } }; @@ -1943,13 +2026,11 @@ namespace LLInitParam typedef block_t value_t; ParamValue() - : block_t(), - mValidated(false) + : block_t() {} ParamValue(value_assignment_t other) - : block_t(other), - mValidated(false) + : block_t(other) { } @@ -1977,9 +2058,6 @@ namespace LLInitParam { return *this; } - - protected: - mutable bool mValidated; // lazy validation flag }; template @@ -1994,13 +2072,11 @@ namespace LLInitParam typedef T value_t; ParamValue() - : mValue(), - mValidated(false) + : mValue() {} ParamValue(value_assignment_t other) - : mValue(other), - mValidated(false) + : mValue(other) {} void setValue(value_assignment_t val) @@ -2033,11 +2109,11 @@ namespace LLInitParam return mValue.get().deserializeBlock(p, name_stack_range, new_name); } - void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const + void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const BaseBlock* diff_block = NULL) const { if (mValue.empty()) return; - mValue.get().serializeBlock(p, name_stack, diff_block); + mValue.get().serializeBlock(p, name_stack, predicate_rule, diff_block); } bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const @@ -2047,9 +2123,6 @@ namespace LLInitParam return mValue.get().inspectBlock(p, name_stack, min_count, max_count); } - protected: - mutable bool mValidated; // lazy validation flag - private: BaseBlock::Lazy mValue; }; @@ -2066,12 +2139,10 @@ namespace LLInitParam typedef const LLSD& value_assignment_t; ParamValue() - : mValidated(false) {} ParamValue(value_assignment_t other) - : mValue(other), - mValidated(false) + : mValue(other) {} void setValue(value_assignment_t val) { mValue = val; } @@ -2085,16 +2156,13 @@ namespace LLInitParam // block param interface LL_COMMON_API bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - LL_COMMON_API void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; + LL_COMMON_API void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const { //TODO: implement LLSD params as schema type Any return true; } - protected: - mutable bool mValidated; // lazy validation flag - private: static void serializeElement(Parser& p, const LLSD& sd, Parser::name_stack_t& name_stack); @@ -2123,8 +2191,7 @@ namespace LLInitParam CustomParamValue(const T& value = T()) : mValue(value), - mValueAge(VALUE_AUTHORITATIVE), - mValidated(false) + mValueAge(VALUE_AUTHORITATIVE) {} bool deserializeBlock(Parser& parser, Parser::name_stack_range_t name_stack_range, bool new_name) @@ -2148,7 +2215,7 @@ namespace LLInitParam return typed_param.BaseBlock::deserializeBlock(parser, name_stack_range, new_name); } - void serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const + void serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const BaseBlock* diff_block = NULL) const { const derived_t& typed_param = static_cast(*this); const derived_t* diff_param = static_cast(diff_block); @@ -2184,11 +2251,11 @@ namespace LLInitParam // and serialize those params derived_t copy(typed_param); copy.updateBlockFromValue(true); - copy.block_t::serializeBlock(parser, name_stack, NULL); + copy.block_t::serializeBlock(parser, name_stack, predicate_rule, NULL); } else { - block_t::serializeBlock(parser, name_stack, NULL); + block_t::serializeBlock(parser, name_stack, predicate_rule, NULL); } } } @@ -2309,8 +2376,6 @@ namespace LLInitParam return block_t::mergeBlock(block_data, source, overwrite); } - mutable bool mValidated; // lazy validation flag - private: mutable T mValue; mutable EValueAge mValueAge; diff --git a/indra/llcommon/llpredicate.cpp b/indra/llcommon/llpredicate.cpp new file mode 100644 index 0000000000..8dcd9247b7 --- /dev/null +++ b/indra/llcommon/llpredicate.cpp @@ -0,0 +1,33 @@ +/** + * @file llpredicate.cpp + * @brief abstraction for filtering objects by predicates, with arbitrary boolean expressions + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ +#include "linden_common.h" + +#include "llpredicate.h" + +namespace LLPredicate +{ + EmptyRule make_rule() { return EmptyRule(); } +} diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h new file mode 100644 index 0000000000..ad5ab363fa --- /dev/null +++ b/indra/llcommon/llpredicate.h @@ -0,0 +1,173 @@ +/** + * @file llpredicate.h + * @brief abstraction for filtering objects by predicates, with arbitrary boolean expressions + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLPREDICATE_H +#define LL_LLPREDICATE_H + +#include "llerror.h" + +namespace LLPredicate +{ + template class Rule; + + template + struct Value + { + friend Rule; + public: + Value(ENUM e) + : mPredicateFlags(0x1), + mPredicateCombinationFlags(0x1) + { + set(e); + } + + Value() + : mPredicateFlags(0x1), + mPredicateCombinationFlags(0x1) + {} + + void set(ENUM predicate) + { + llassert(predicate <= 5); + int predicate_flag = 0x1 << (0x1 << (int)predicate); + if (!(mPredicateFlags & predicate_flag)) + { + mPredicateCombinationFlags *= predicate_flag; + mPredicateFlags |= predicate_flag; + } + } + + bool get(ENUM predicate) + { + int predicate_flag = 0x1 << (0x1 << (int)predicate); + return (mPredicateFlags & predicate_flag) != 0; + } + + void clear(ENUM predicate) + { + llassert(predicate <= 5); + int predicate_flag = 0x1 << (0x1 << (int)predicate); + if (mPredicateFlags & predicate_flag) + { + mPredicateCombinationFlags /= predicate_flag; + mPredicateFlags &= ~predicate_flag; + } + } + + private: + int mPredicateCombinationFlags; + int mPredicateFlags; + }; + + struct EmptyRule {}; + + template + class Rule + { + public: + Rule(EmptyRule e) + : mPredicateRequirements(0x1) + {} + + Rule(ENUM value) + : mPredicateRequirements(predicateFromValue(value)) + {} + + Rule() + : mPredicateRequirements(0x1) + {} + + Rule operator~() + { + Rule new_rule; + new_rule.mPredicateRequirements = ~mPredicateRequirements; + return new_rule; + } + + Rule operator &&(const Rule& other) + { + Rule new_rule; + new_rule.mPredicateRequirements = mPredicateRequirements & other.mPredicateRequirements; + return new_rule; + } + + Rule operator ||(const Rule& other) + { + Rule new_rule; + new_rule.mPredicateRequirements = mPredicateRequirements | other.mPredicateRequirements; + return new_rule; + } + + bool check(const Value& value) const + { + return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; + } + + static int predicateFromValue(ENUM value) + { + int countdown = value; + bool bit_val = false; + + int predicate = 0x0; + + for (int bit_index = 0; bit_index < 32; bit_index++) + { + if (bit_val) + { + predicate |= 0x1 << bit_index; + } + + if (countdown-- == 0) + { + countdown = value; + bit_val = !bit_val; + } + } + return predicate; + } + + bool isTriviallyTrue() const + { + return mPredicateRequirements & 0x1; + } + + bool isTriviallyFalse() const + { + return mPredicateRequirements == 0; + } + + private: + int mPredicateRequirements; + }; + + template + Rule make_rule(ENUM e) { return Rule(e);} + + EmptyRule make_rule(); + +} +#endif // LL_LLPREDICATE_H diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index 4b8a8dba5c..713f5ac605 100644 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -329,7 +329,7 @@ namespace LLInitParam p.writeValue(sd.asString(), name_stack); } - void ParamValue, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const + void ParamValue, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const BaseBlock* diff_block) const { // attempt to write LLSD out directly if (!p.writeValue(mValue, name_stack)) -- cgit v1.2.3 From 50ad343366f5e18ced40e24e2a1cc2399411c7e5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 22 Oct 2012 22:46:45 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system added return value to serialize function to track if any values were written --- indra/llcommon/llinitparam.cpp | 14 ++++--- indra/llcommon/llinitparam.h | 84 ++++++++++++++++++++++++++---------------- indra/llcommon/llsdparam.cpp | 3 +- 3 files changed, 64 insertions(+), 37 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index 54e98e66f3..d6326a7c11 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -180,8 +180,9 @@ namespace LLInitParam return true; } - void BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const + bool BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const { + bool serialized = false; // named param is one like LLView::Params::follows // unnamed param is like LLView::Params::rect - implicit const BlockDescriptor& block_data = mostDerivedBlockDescriptor(); @@ -193,10 +194,10 @@ namespace LLInitParam param_handle_t param_handle = (*it)->mParamHandle; const Param* param = getParamFromHandle(param_handle); ParamDescriptor::serialize_func_t serialize_func = (*it)->mSerializeFunc; - if (serialize_func) + if (serialize_func && param->anyProvided()) { const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; - serialize_func(*param, parser, name_stack, diff_param); + serialized |= serialize_func(*param, parser, name_stack, diff_param); } } @@ -232,10 +233,13 @@ namespace LLInitParam name_stack.push_back(std::make_pair(it->first, !duplicate)); const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; - serialize_func(*param, parser, name_stack, diff_param); + serialized |= serialize_func(*param, parser, name_stack, diff_param); name_stack.pop_back(); } } + + // was anything serialized in this block? + return serialized; } bool BaseBlock::inspectBlock(Parser& parser, Parser::name_stack_t name_stack, S32 min_count, S32 max_count) const @@ -354,7 +358,7 @@ namespace LLInitParam } //static - void BaseBlock::addParam(BlockDescriptor& block_data, const ParamDescriptorPtr in_param, const char* char_name) + void BaseBlock::addParam(BlockDescriptor& block_data, ParamDescriptorPtr in_param, const char* char_name) { // create a copy of the param descriptor in mAllParams // so other data structures can store a pointer to it diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index b7607e91b9..93e24d4040 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -32,10 +32,10 @@ #include #include #include -#include #include "llerror.h" #include "llstl.h" +#include "llmemory.h" namespace LLInitParam { @@ -303,7 +303,7 @@ namespace LLInitParam typedef bool(*merge_func_t)(Param&, const Param&, bool); typedef bool(*deserialize_func_t)(Param&, Parser&, const Parser::name_stack_range_t&, bool); - typedef void(*serialize_func_t)(const Param&, Parser&, Parser::name_stack_t&, const Param* diff_param); + typedef bool(*serialize_func_t)(const Param&, Parser&, Parser::name_stack_t&, const Param* diff_param); typedef void(*inspect_func_t)(const Param&, Parser&, Parser::name_stack_t&, S32 min_count, S32 max_count); typedef bool(*validation_func_t)(const Param*); @@ -331,7 +331,7 @@ namespace LLInitParam UserData* mUserData; }; - typedef boost::shared_ptr ParamDescriptorPtr; + typedef ParamDescriptor* ParamDescriptorPtr; // each derived Block class keeps a static data structure maintaining offsets to various params class LL_COMMON_API BlockDescriptor @@ -510,7 +510,7 @@ namespace LLInitParam virtual void paramChanged(const Param& changed_param, bool user_provided) {} bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; + bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const; virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } @@ -870,10 +870,11 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static bool serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { + bool serialized = false; const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + if (!typed_param.isProvided()) return false; if (!name_stack.empty()) { @@ -888,21 +889,23 @@ namespace LLInitParam { if (!diff_param || !ParamCompare::equals(static_cast(diff_param)->getValueName(), key)) { - parser.writeValue(key, name_stack); + serialized = parser.writeValue(key, name_stack); } } // then try to serialize value directly else if (!diff_param || !ParamCompare::equals(typed_param.getValue(), static_cast(diff_param)->getValue())) { - if (!parser.writeValue(typed_param.getValue(), name_stack)) + serialized = parser.writeValue(typed_param.getValue(), name_stack); + if (!serialized) { std::string calculated_key = typed_param.calcValueName(typed_param.getValue()); if (!diff_param || !ParamCompare::equals(static_cast(diff_param)->getValueName(), calculated_key)) { - parser.writeValue(calculated_key, name_stack); + serialized = parser.writeValue(calculated_key, name_stack); } } } + return serialized; } static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) @@ -1014,10 +1017,10 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static bool serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + if (!typed_param.isProvided()) return false; if (!name_stack.empty()) { @@ -1027,15 +1030,17 @@ namespace LLInitParam std::string key = typed_param.getValueName(); if (!key.empty()) { - if (!parser.writeValue(key, name_stack)) + if (parser.writeValue(key, name_stack)) { - return; + return true; } } else { - typed_param.serializeBlock(parser, name_stack, static_cast(diff_param)); + return typed_param.serializeBlock(parser, name_stack, static_cast(diff_param)); } + + return false; } static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) @@ -1197,10 +1202,11 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static bool serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { + bool serialized = false; const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + if (!typed_param.isProvided()) return false; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; @@ -1216,7 +1222,11 @@ namespace LLInitParam if (!value_written) { std::string calculated_key = it->calcValueName(it->getValue()); - if (!parser.writeValue(calculated_key, name_stack)) + if (parser.writeValue(calculated_key, name_stack)) + { + serialized = true; + } + else { break; } @@ -1224,7 +1234,11 @@ namespace LLInitParam } else { - if(!parser.writeValue(key, name_stack)) + if(parser.writeValue(key, name_stack)) + { + serialized = true; + } + else { break; } @@ -1232,6 +1246,7 @@ namespace LLInitParam name_stack.pop_back(); } + return serialized; } static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) @@ -1420,10 +1435,11 @@ namespace LLInitParam return false; } - static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) + static bool serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param) { + bool serialized = false; const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return; + if (!typed_param.isProvided()) return false; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; @@ -1434,17 +1450,18 @@ namespace LLInitParam std::string key = it->getValueName(); if (!key.empty()) { - parser.writeValue(key, name_stack); + serialized |= parser.writeValue(key, name_stack); } // Not parsed via named values, write out value directly // NOTE: currently we don't worry about removing default values in Multiple else { - it->serializeBlock(parser, name_stack, NULL); + serialized = it->serializeBlock(parser, name_stack, NULL); } name_stack.pop_back(); } + return serialized; } static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) @@ -2033,11 +2050,11 @@ namespace LLInitParam return mValue.get().deserializeBlock(p, name_stack_range, new_name); } - void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const + bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const { - if (mValue.empty()) return; + if (mValue.empty()) return false; - mValue.get().serializeBlock(p, name_stack, diff_block); + return mValue.get().serializeBlock(p, name_stack, diff_block); } bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const @@ -2085,7 +2102,7 @@ namespace LLInitParam // block param interface LL_COMMON_API bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - LL_COMMON_API void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; + LL_COMMON_API bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const { //TODO: implement LLSD params as schema type Any @@ -2148,7 +2165,7 @@ namespace LLInitParam return typed_param.BaseBlock::deserializeBlock(parser, name_stack_range, new_name); } - void serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const + bool serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const { const derived_t& typed_param = static_cast(*this); const derived_t* diff_param = static_cast(diff_block); @@ -2160,14 +2177,18 @@ namespace LLInitParam { if (!diff_param || !ParamCompare::equals(diff_param->getValueName(), key)) { - parser.writeValue(key, name_stack); + return parser.writeValue(key, name_stack); } } // then try to serialize value directly else if (!diff_param || !ParamCompare::equals(typed_param.getValue(), diff_param->getValue())) { - if (!parser.writeValue(typed_param.getValue(), name_stack)) + if (parser.writeValue(typed_param.getValue(), name_stack)) + { + return true; + } + else { //RN: *always* serialize provided components of BlockValue (don't pass diff_param on), // since these tend to be viewed as the constructor arguments for the value T. It seems @@ -2184,14 +2205,15 @@ namespace LLInitParam // and serialize those params derived_t copy(typed_param); copy.updateBlockFromValue(true); - copy.block_t::serializeBlock(parser, name_stack, NULL); + return copy.block_t::serializeBlock(parser, name_stack, NULL); } else { - block_t::serializeBlock(parser, name_stack, NULL); + return block_t::serializeBlock(parser, name_stack, NULL); } } } + return false; } bool inspectBlock(Parser& parser, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index 4b8a8dba5c..e25a966609 100644 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -329,7 +329,7 @@ namespace LLInitParam p.writeValue(sd.asString(), name_stack); } - void ParamValue, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const + bool ParamValue, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const { // attempt to write LLSD out directly if (!p.writeValue(mValue, name_stack)) @@ -337,5 +337,6 @@ namespace LLInitParam // otherwise read from LLSD value and serialize out to parser (which could be LLSD, XUI, etc) LLParamSDParserUtilities::readSDValues(boost::bind(&serializeElement, boost::ref(p), _1, _2), mValue, name_stack); } + return true; } } -- cgit v1.2.3 From 638a16eedd12fe03b85703fb821bc05f40aab355 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 22:35:47 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system improved predicate system, added uncertain/unknown predicates --- indra/llcommon/llinitparam.cpp | 2 +- indra/llcommon/llinitparam.h | 69 +++++++++++++++++++++++++++++++--------- indra/llcommon/llpredicate.h | 71 ++++++++++++++++++++---------------------- 3 files changed, 88 insertions(+), 54 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index b4dcf3493c..69f97e87c4 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -185,7 +185,7 @@ namespace LLInitParam return mValidated; } - bool BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const + bool BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const LLInitParam::BaseBlock* diff_block) const { bool serialized = false; if (!isProvided()) diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index d3a0438d93..a3a5b3dc37 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -914,14 +914,15 @@ namespace LLInitParam LLPredicate::Value predicate; if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) { - predicate.set(NON_DEFAULT); + predicate.add(NON_DEFAULT); } + predicate.unknown(REQUIRED); if (typed_param.isValid()) { - predicate.set(VALID); + predicate.add(VALID); if (typed_param.anyProvided()) { - predicate.set(PROVIDED); + predicate.add(PROVIDED); } } @@ -1071,19 +1072,17 @@ namespace LLInitParam static bool serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const Param* diff_param) { const self_t& typed_param = static_cast(param); - const self_t* diff_typed_param = static_cast(diff_param); LLPredicate::Value predicate; - if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) - { - predicate.set(NON_DEFAULT); - } + predicate.unknown(NON_DEFAULT); + predicate.unknown(REQUIRED); + if (typed_param.isValid()) { - predicate.set(VALID); + predicate.add(VALID); if (typed_param.anyProvided()) { - predicate.set(PROVIDED); + predicate.add(PROVIDED); } } @@ -1271,7 +1270,29 @@ namespace LLInitParam { bool serialized = false; const self_t& typed_param = static_cast(param); - if (!typed_param.isProvided()) return false; + + LLPredicate::Value predicate; + predicate.unknown(NON_DEFAULT); + + if (typed_param.mMinCount > 0) + { + predicate.add(REQUIRED); + } + else + { + predicate.unknown(REQUIRED); + } + + if (typed_param.isValid()) + { + predicate.add(VALID); + if (typed_param.anyProvided()) + { + predicate.add(PROVIDED); + } + } + + if (!predicate_rule.check(predicate)) return false; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; @@ -1516,10 +1537,28 @@ namespace LLInitParam bool serialized = false; const self_t& typed_param = static_cast(param); - LLPredicate::Value predicate_value; - if (typed_param.isProvided()) predicate_value.set(PROVIDED); - - if (!typed_param.isProvided()) return false; + LLPredicate::Value predicate; + predicate.unknown(NON_DEFAULT); + + if (typed_param.mMinCount > 0) + { + predicate.add(REQUIRED); + } + else + { + predicate.unknown(REQUIRED); + } + + if (typed_param.isValid()) + { + predicate.add(VALID); + if (typed_param.anyProvided()) + { + predicate.add(PROVIDED); + } + } + + if (!predicate_rule.check(predicate)) return false; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); it != end_it; diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index ad5ab363fa..35ef22138c 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -42,34 +42,28 @@ namespace LLPredicate : mPredicateFlags(0x1), mPredicateCombinationFlags(0x1) { - set(e); + add(e); } Value() - : mPredicateFlags(0x1), + : mPredicateFlags(0x1), mPredicateCombinationFlags(0x1) {} - void set(ENUM predicate) + void add(ENUM predicate) { - llassert(predicate <= 5); - int predicate_flag = 0x1 << (0x1 << (int)predicate); - if (!(mPredicateFlags & predicate_flag)) + llassert(predicate < 5); + if (!has(predicate)) { + int predicate_flag = 0x1 << (0x1 << (int)predicate); mPredicateCombinationFlags *= predicate_flag; mPredicateFlags |= predicate_flag; } } - bool get(ENUM predicate) - { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - return (mPredicateFlags & predicate_flag) != 0; - } - - void clear(ENUM predicate) + void remove(ENUM predicate) { - llassert(predicate <= 5); + llassert(predicate < 5); int predicate_flag = 0x1 << (0x1 << (int)predicate); if (mPredicateFlags & predicate_flag) { @@ -78,6 +72,19 @@ namespace LLPredicate } } + void unknown(ENUM predicate) + { + add(predicate); + int predicate_shift = 0x1 << (int)predicate; + mPredicateCombinationFlags |= mPredicateCombinationFlags << predicate_shift; + } + + bool has(ENUM predicate) + { + int predicate_flag = 0x1 << (0x1 << (int)predicate); + return (mPredicateFlags & predicate_flag) != 0; + } + private: int mPredicateCombinationFlags; int mPredicateFlags; @@ -89,16 +96,12 @@ namespace LLPredicate class Rule { public: - Rule(EmptyRule e) - : mPredicateRequirements(0x1) - {} - Rule(ENUM value) - : mPredicateRequirements(predicateFromValue(value)) + : mPredicateRequirements(predicateFromValue(value)) {} Rule() - : mPredicateRequirements(0x1) + : mPredicateRequirements(0x1) {} Rule operator~() @@ -129,25 +132,16 @@ namespace LLPredicate static int predicateFromValue(ENUM value) { - int countdown = value; - bool bit_val = false; - - int predicate = 0x0; - - for (int bit_index = 0; bit_index < 32; bit_index++) + llassert(value < 5); + static const int predicates[5] = { - if (bit_val) - { - predicate |= 0x1 << bit_index; - } - - if (countdown-- == 0) - { - countdown = value; - bit_val = !bit_val; - } - } - return predicate; + 0xAAAAaaaa, // 10101010101010101010101010101010 + 0xCCCCcccc, // 11001100110011001100110011001100 + 0xF0F0F0F0, // 11110000111100001111000011110000 + 0xFF00FF00, // 11111111000000001111111100000000 + 0xFFFF0000 // 11111111111111110000000000000000 + }; + return predicates[value]; } bool isTriviallyTrue() const @@ -167,6 +161,7 @@ namespace LLPredicate template Rule make_rule(ENUM e) { return Rule(e);} + // return generic empty rule class to avoid requiring template argument to create an empty rule EmptyRule make_rule(); } -- cgit v1.2.3 From 28179ab0070a1c13193808bc1493761a8fed167f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 23:12:33 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system cleaned up predicate system, made unknown work with remove --- indra/llcommon/llpredicate.cpp | 14 +++++++++++ indra/llcommon/llpredicate.h | 55 +++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 33 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llpredicate.cpp b/indra/llcommon/llpredicate.cpp index 8dcd9247b7..1ab1ab08f1 100644 --- a/indra/llcommon/llpredicate.cpp +++ b/indra/llcommon/llpredicate.cpp @@ -30,4 +30,18 @@ namespace LLPredicate { EmptyRule make_rule() { return EmptyRule(); } + + int predicateFlagsFromValue(int value) + { + llassert(value < 5); + static const int predicates[5] = + { + 0xAAAAaaaa, // 10101010101010101010101010101010 + 0xCCCCcccc, // 11001100110011001100110011001100 + 0xF0F0F0F0, // 11110000111100001111000011110000 + 0xFF00FF00, // 11111111000000001111111100000000 + 0xFFFF0000 // 11111111111111110000000000000000 + }; + return predicates[value]; + } } diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 35ef22138c..096238713c 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,21 +33,21 @@ namespace LLPredicate { template class Rule; + int predicateFlagsFromValue(int value); + template struct Value { friend Rule; public: Value(ENUM e) - : mPredicateFlags(0x1), - mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0x1) { add(e); } Value() - : mPredicateFlags(0x1), - mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0x1) {} void add(ENUM predicate) @@ -55,39 +55,42 @@ namespace LLPredicate llassert(predicate < 5); if (!has(predicate)) { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - mPredicateCombinationFlags *= predicate_flag; - mPredicateFlags |= predicate_flag; + int predicate_shift = 0x1 << (int)predicate; + mPredicateCombinationFlags <<= predicate_shift; } } void remove(ENUM predicate) { llassert(predicate < 5); - int predicate_flag = 0x1 << (0x1 << (int)predicate); - if (mPredicateFlags & predicate_flag) - { - mPredicateCombinationFlags /= predicate_flag; - mPredicateFlags &= ~predicate_flag; - } + int predicate_shift = 0x1 << (int)predicate; + int flag_mask = predicateFlagsFromValue(predicate); + int flags_to_modify = mPredicateCombinationFlags & flag_mask; + // clear flags containing predicate to be removed + mPredicateCombinationFlags &= ~flag_mask; + // shift flags, in effect removing predicate + flags_to_modify >>= predicate_shift; + // put modified flags back + mPredicateCombinationFlags |= flags_to_modify; } void unknown(ENUM predicate) { add(predicate); - int predicate_shift = 0x1 << (int)predicate; - mPredicateCombinationFlags |= mPredicateCombinationFlags << predicate_shift; + int flags_with_predicate = mPredicateCombinationFlags; + remove(predicate); + // unknown is result of adding and removing predicate at the same time! + mPredicateCombinationFlags |= flags_with_predicate; } bool has(ENUM predicate) { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - return (mPredicateFlags & predicate_flag) != 0; + int flag_mask = predicateFlagsFromValue(predicate); + return (mPredicateCombinationFlags & flag_mask) != 0; } private: int mPredicateCombinationFlags; - int mPredicateFlags; }; struct EmptyRule {}; @@ -97,7 +100,7 @@ namespace LLPredicate { public: Rule(ENUM value) - : mPredicateRequirements(predicateFromValue(value)) + : mPredicateRequirements(predicateFlagsFromValue(value)) {} Rule() @@ -130,20 +133,6 @@ namespace LLPredicate return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; } - static int predicateFromValue(ENUM value) - { - llassert(value < 5); - static const int predicates[5] = - { - 0xAAAAaaaa, // 10101010101010101010101010101010 - 0xCCCCcccc, // 11001100110011001100110011001100 - 0xF0F0F0F0, // 11110000111100001111000011110000 - 0xFF00FF00, // 11111111000000001111111100000000 - 0xFFFF0000 // 11111111111111110000000000000000 - }; - return predicates[value]; - } - bool isTriviallyTrue() const { return mPredicateRequirements & 0x1; -- cgit v1.2.3 From 1de6ecb23851e0784016a2c4c9f691c976c6bda7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 23:35:15 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system converted "int" to "S32" --- indra/llcommon/llpredicate.cpp | 4 ++-- indra/llcommon/llpredicate.h | 34 +++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llpredicate.cpp b/indra/llcommon/llpredicate.cpp index 1ab1ab08f1..e3410ef3f6 100644 --- a/indra/llcommon/llpredicate.cpp +++ b/indra/llcommon/llpredicate.cpp @@ -31,10 +31,10 @@ namespace LLPredicate { EmptyRule make_rule() { return EmptyRule(); } - int predicateFlagsFromValue(int value) + S32 predicateFlagsFromValue(S32 value) { llassert(value < 5); - static const int predicates[5] = + static const S32 predicates[5] = { 0xAAAAaaaa, // 10101010101010101010101010101010 0xCCCCcccc, // 11001100110011001100110011001100 diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 096238713c..5fd1d30295 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,7 +33,7 @@ namespace LLPredicate { template class Rule; - int predicateFlagsFromValue(int value); + S32 predicateFlagsFromValue(S32 value); template struct Value @@ -41,31 +41,35 @@ namespace LLPredicate friend Rule; public: Value(ENUM e) - : mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0xFFFFffff) { add(e); } Value() - : mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0xFFFFffff) {} void add(ENUM predicate) { llassert(predicate < 5); - if (!has(predicate)) - { - int predicate_shift = 0x1 << (int)predicate; - mPredicateCombinationFlags <<= predicate_shift; - } + S32 predicate_shift = 0x1 << (S32)predicate; + S32 flag_mask = predicateFlagsFromValue(predicate); + S32 flags_to_modify = mPredicateCombinationFlags & ~flag_mask; + // clear flags containing predicate to be removed + mPredicateCombinationFlags &= ~flag_mask; + // shift flags, in effect removing predicate + flags_to_modify <<= predicate_shift; + // put modified flags back + mPredicateCombinationFlags |= flags_to_modify; } void remove(ENUM predicate) { llassert(predicate < 5); - int predicate_shift = 0x1 << (int)predicate; - int flag_mask = predicateFlagsFromValue(predicate); - int flags_to_modify = mPredicateCombinationFlags & flag_mask; + S32 predicate_shift = 0x1 << (S32)predicate; + S32 flag_mask = predicateFlagsFromValue(predicate); + S32 flags_to_modify = mPredicateCombinationFlags & flag_mask; // clear flags containing predicate to be removed mPredicateCombinationFlags &= ~flag_mask; // shift flags, in effect removing predicate @@ -77,7 +81,7 @@ namespace LLPredicate void unknown(ENUM predicate) { add(predicate); - int flags_with_predicate = mPredicateCombinationFlags; + S32 flags_with_predicate = mPredicateCombinationFlags; remove(predicate); // unknown is result of adding and removing predicate at the same time! mPredicateCombinationFlags |= flags_with_predicate; @@ -85,12 +89,12 @@ namespace LLPredicate bool has(ENUM predicate) { - int flag_mask = predicateFlagsFromValue(predicate); + S32 flag_mask = predicateFlagsFromValue(predicate); return (mPredicateCombinationFlags & flag_mask) != 0; } private: - int mPredicateCombinationFlags; + S32 mPredicateCombinationFlags; }; struct EmptyRule {}; @@ -144,7 +148,7 @@ namespace LLPredicate } private: - int mPredicateRequirements; + S32 mPredicateRequirements; }; template -- cgit v1.2.3 From 7f97aa2d5db0d1429136a40d04d2e4428cb184fe Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 25 Oct 2012 17:30:03 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed crash on exit --- indra/llcommon/llinitparam.h | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index a3a5b3dc37..9530e562f6 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -916,7 +916,6 @@ namespace LLInitParam { predicate.add(NON_DEFAULT); } - predicate.unknown(REQUIRED); if (typed_param.isValid()) { predicate.add(VALID); @@ -1074,8 +1073,6 @@ namespace LLInitParam const self_t& typed_param = static_cast(param); LLPredicate::Value predicate; - predicate.unknown(NON_DEFAULT); - predicate.unknown(REQUIRED); if (typed_param.isValid()) { @@ -1272,16 +1269,11 @@ namespace LLInitParam const self_t& typed_param = static_cast(param); LLPredicate::Value predicate; - predicate.unknown(NON_DEFAULT); if (typed_param.mMinCount > 0) { predicate.add(REQUIRED); } - else - { - predicate.unknown(REQUIRED); - } if (typed_param.isValid()) { @@ -1538,16 +1530,11 @@ namespace LLInitParam const self_t& typed_param = static_cast(param); LLPredicate::Value predicate; - predicate.unknown(NON_DEFAULT); if (typed_param.mMinCount > 0) { predicate.add(REQUIRED); } - else - { - predicate.unknown(REQUIRED); - } if (typed_param.isValid()) { -- cgit v1.2.3 From 3ffd0be53af0c5338e6fdc77d240e976aeb10451 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 26 Oct 2012 20:03:33 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed llpredicate so that values and rules work uniformly with predicate logic and/or/negate works in parallel with set/clear --- indra/llcommon/llinitparam.cpp | 2 +- indra/llcommon/llinitparam.h | 64 ++++++------- indra/llcommon/llpredicate.cpp | 22 ++--- indra/llcommon/llpredicate.h | 199 ++++++++++++++++++++++++++--------------- 4 files changed, 166 insertions(+), 121 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index 69f97e87c4..c66659a696 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -190,7 +190,7 @@ namespace LLInitParam bool serialized = false; if (!isProvided()) { - if ((~predicate_rule_t(PROVIDED) && predicate_rule).isTriviallyFalse()) + if (predicate_rule_t(~ll_predicate(PROVIDED) && predicate_rule).isTriviallyFalse()) { return false; } diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index 9530e562f6..b52ac809e0 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -545,7 +545,7 @@ namespace LLInitParam } bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t rule = predicate_rule_t(), const BaseBlock* diff_block = NULL) const; + bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t rule = predicate_rule_t(ll_predicate(PROVIDED) && ll_predicate(NON_DEFAULT)), const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const; virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } @@ -912,17 +912,17 @@ namespace LLInitParam const self_t* diff_typed_param = static_cast(diff_param); LLPredicate::Value predicate; - if (!diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) + predicate.set(NON_DEFAULT, !diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())); + + if (typed_param.isValid()) { - predicate.add(NON_DEFAULT); + predicate.set(VALID, true); + predicate.set(PROVIDED, typed_param.anyProvided()); } - if (typed_param.isValid()) + else { - predicate.add(VALID); - if (typed_param.anyProvided()) - { - predicate.add(PROVIDED); - } + predicate.set(VALID, false); + predicate.set(PROVIDED, false); } if (!predicate_rule.check(predicate)) return false; @@ -1076,11 +1076,13 @@ namespace LLInitParam if (typed_param.isValid()) { - predicate.add(VALID); - if (typed_param.anyProvided()) - { - predicate.add(PROVIDED); - } + predicate.set(VALID, true); + predicate.set(PROVIDED, typed_param.anyProvided()); + } + else + { + predicate.set(VALID, false); + predicate.set(PROVIDED, false); } if (!predicate_rule.check(predicate)) return false; @@ -1270,19 +1272,18 @@ namespace LLInitParam LLPredicate::Value predicate; - if (typed_param.mMinCount > 0) - { - predicate.add(REQUIRED); - } + predicate.set(REQUIRED, typed_param.mMinCount > 0); if (typed_param.isValid()) { - predicate.add(VALID); - if (typed_param.anyProvided()) - { - predicate.add(PROVIDED); - } + predicate.set(VALID, true); + predicate.set(PROVIDED, typed_param.anyProvided()); } + else + { + predicate.set(VALID, false); + predicate.set(PROVIDED, false); + } if (!predicate_rule.check(predicate)) return false; @@ -1531,19 +1532,18 @@ namespace LLInitParam LLPredicate::Value predicate; - if (typed_param.mMinCount > 0) - { - predicate.add(REQUIRED); - } + predicate.set(REQUIRED, typed_param.mMinCount > 0); if (typed_param.isValid()) { - predicate.add(VALID); - if (typed_param.anyProvided()) - { - predicate.add(PROVIDED); - } + predicate.set(VALID, true); + predicate.set(PROVIDED, typed_param.anyProvided()); } + else + { + predicate.set(VALID, false); + predicate.set(PROVIDED, false); + } if (!predicate_rule.check(predicate)) return false; diff --git a/indra/llcommon/llpredicate.cpp b/indra/llcommon/llpredicate.cpp index e3410ef3f6..1278948e24 100644 --- a/indra/llcommon/llpredicate.cpp +++ b/indra/llcommon/llpredicate.cpp @@ -29,19 +29,13 @@ namespace LLPredicate { - EmptyRule make_rule() { return EmptyRule(); } - - S32 predicateFlagsFromValue(S32 value) + const U32 cPredicateFlagsFromEnum[5] = { - llassert(value < 5); - static const S32 predicates[5] = - { - 0xAAAAaaaa, // 10101010101010101010101010101010 - 0xCCCCcccc, // 11001100110011001100110011001100 - 0xF0F0F0F0, // 11110000111100001111000011110000 - 0xFF00FF00, // 11111111000000001111111100000000 - 0xFFFF0000 // 11111111111111110000000000000000 - }; - return predicates[value]; - } + 0xAAAAaaaa, // 10101010101010101010101010101010 + 0xCCCCcccc, // 11001100110011001100110011001100 + 0xF0F0F0F0, // 11110000111100001111000011110000 + 0xFF00FF00, // 11111111000000001111111100000000 + 0xFFFF0000 // 11111111111111110000000000000000 + }; } + diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 5fd1d30295..3f1bf1c8e6 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,129 +33,180 @@ namespace LLPredicate { template class Rule; - S32 predicateFlagsFromValue(S32 value); + extern const U32 cPredicateFlagsFromEnum[5]; template - struct Value + class Literal { friend Rule; + public: - Value(ENUM e) - : mPredicateCombinationFlags(0xFFFFffff) + typedef U32 predicate_flag_t; + static const S32 cMaxEnum = 5; + + Literal(ENUM e) + : mPredicateFlags(cPredicateFlagsFromEnum[e]) { - add(e); + llassert(0 <= e && e < cMaxEnum); } - Value() - : mPredicateCombinationFlags(0xFFFFffff) + Literal() + : mPredicateFlags(0xFFFFffff) {} - void add(ENUM predicate) + Literal operator~() { - llassert(predicate < 5); - S32 predicate_shift = 0x1 << (S32)predicate; - S32 flag_mask = predicateFlagsFromValue(predicate); - S32 flags_to_modify = mPredicateCombinationFlags & ~flag_mask; - // clear flags containing predicate to be removed - mPredicateCombinationFlags &= ~flag_mask; - // shift flags, in effect removing predicate - flags_to_modify <<= predicate_shift; - // put modified flags back - mPredicateCombinationFlags |= flags_to_modify; + Literal new_rule; + new_rule.mPredicateFlags = ~mPredicateFlags; + return new_rule; } - void remove(ENUM predicate) + Literal operator &&(const Literal& other) { - llassert(predicate < 5); - S32 predicate_shift = 0x1 << (S32)predicate; - S32 flag_mask = predicateFlagsFromValue(predicate); - S32 flags_to_modify = mPredicateCombinationFlags & flag_mask; - // clear flags containing predicate to be removed - mPredicateCombinationFlags &= ~flag_mask; - // shift flags, in effect removing predicate - flags_to_modify >>= predicate_shift; - // put modified flags back - mPredicateCombinationFlags |= flags_to_modify; + Literal new_rule; + new_rule.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; + return new_rule; } - void unknown(ENUM predicate) + Literal operator ||(const Literal& other) { - add(predicate); - S32 flags_with_predicate = mPredicateCombinationFlags; - remove(predicate); - // unknown is result of adding and removing predicate at the same time! - mPredicateCombinationFlags |= flags_with_predicate; + Literal new_rule; + new_rule.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; + return new_rule; } - bool has(ENUM predicate) + void set(ENUM e, bool value) { - S32 flag_mask = predicateFlagsFromValue(predicate); - return (mPredicateCombinationFlags & flag_mask) != 0; + llassert(0 <= e && e < cMaxEnum); + modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); + } + + void set(const Literal& other, bool value) + { + U32 predicate_flags = other.mPredicateFlags; + while(predicate_flags) + { + U32 next_flags = clearLSB(predicate_flags); + lsb_flag = predicate_flags ^ next_flags; + U32 mask = 0; + for (S32 i = 0; i < cMaxEnum; i++) + { + if (cPredicateFlagsFromEnum[i] & lsb_flag) + { + mask |= cPredicateFlagsFromEnum[i]; + } + } + + modifyPredicate(lsb_flag, mask, value); + + predicate_flags = next_flags; + } + } + + void forget(ENUM e) + { + set(e, true); + U32 flags_with_predicate = mPredicateFlags; + set(e, false); + // ambiguous value is result of adding and removing predicate at the same time! + mPredicateFlags |= flags_with_predicate; + } + + void forget(const Literal& literal) + { + set(literal, true); + U32 flags_with_predicate = mPredicateFlags; + set(literal, false); + // ambiguous value is result of adding and removing predicate at the same time! + mPredicateFlags |= flags_with_predicate; } private: - S32 mPredicateCombinationFlags; + + predicate_flag_t clearLSB(predicate_flag_t value) + { + return value & (value - 1); + } + + void modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, bool value) + { + llassert(clearLSB(predicate_flag) == 0); + predicate_flag_t flags_to_modify; + + if (value) + { + flags_to_modify = (mPredicateFlags & ~mask); + // clear flags not containing predicate to be added + mPredicateFlags &= mask; + // shift flags, in effect adding predicate + flags_to_modify *= predicate_flag; + } + else + { + flags_to_modify = mPredicateFlags & mask; + // clear flags containing predicate to be removed + mPredicateFlags &= ~mask; + // shift flags, in effect removing predicate + flags_to_modify /= predicate_flag; + } + // put modified flags back + mPredicateFlags |= flags_to_modify; + } + + predicate_flag_t mPredicateFlags; }; - struct EmptyRule {}; + template + struct Value + : public Literal + { + public: + Value(ENUM e) + : Literal(e) + {} + + Value() + {} + }; template class Rule + : public Literal { public: Rule(ENUM value) - : mPredicateRequirements(predicateFlagsFromValue(value)) + : Literal(value) {} - Rule() - : mPredicateRequirements(0x1) + Rule(const Literal other) + : Literal(other) {} - Rule operator~() - { - Rule new_rule; - new_rule.mPredicateRequirements = ~mPredicateRequirements; - return new_rule; - } - - Rule operator &&(const Rule& other) - { - Rule new_rule; - new_rule.mPredicateRequirements = mPredicateRequirements & other.mPredicateRequirements; - return new_rule; - } - - Rule operator ||(const Rule& other) - { - Rule new_rule; - new_rule.mPredicateRequirements = mPredicateRequirements | other.mPredicateRequirements; - return new_rule; - } + Rule() + {} bool check(const Value& value) const { - return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; + return (value.mPredicateFlags & mPredicateFlags) != 0; } bool isTriviallyTrue() const { - return mPredicateRequirements & 0x1; + return mPredicateFlags == 0xFFFFffff; } bool isTriviallyFalse() const { - return mPredicateRequirements == 0; + return mPredicateFlags == 0; } - - private: - S32 mPredicateRequirements; }; +} - template - Rule make_rule(ENUM e) { return Rule(e);} +template +LLPredicate::Literal ll_predicate(ENUM e) +{ + return LLPredicate::Literal(e); +} - // return generic empty rule class to avoid requiring template argument to create an empty rule - EmptyRule make_rule(); -} #endif // LL_LLPREDICATE_H -- cgit v1.2.3 From b71e991c1860bbea0387f9434cc2b4b31a26469a Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 29 Oct 2012 18:44:37 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed predicate update logic and reduced to 2 classes --- indra/llcommon/llinitparam.cpp | 2 +- indra/llcommon/llpredicate.h | 112 +++++++++++++++++++++++++---------------- 2 files changed, 69 insertions(+), 45 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index c66659a696..afeac0a905 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -190,7 +190,7 @@ namespace LLInitParam bool serialized = false; if (!isProvided()) { - if (predicate_rule_t(~ll_predicate(PROVIDED) && predicate_rule).isTriviallyFalse()) + if ((predicate_rule && !ll_predicate(PROVIDED)).isTriviallyFalse()) { return false; } diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 3f1bf1c8e6..a13172da68 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -36,43 +36,41 @@ namespace LLPredicate extern const U32 cPredicateFlagsFromEnum[5]; template - class Literal + class Value { - friend Rule; - public: typedef U32 predicate_flag_t; static const S32 cMaxEnum = 5; - Literal(ENUM e) + Value(ENUM e) : mPredicateFlags(cPredicateFlagsFromEnum[e]) { llassert(0 <= e && e < cMaxEnum); } - Literal() + Value() : mPredicateFlags(0xFFFFffff) {} - Literal operator~() + Value operator!() const { - Literal new_rule; - new_rule.mPredicateFlags = ~mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = ~mPredicateFlags; + return new_value; } - Literal operator &&(const Literal& other) + Value operator &&(const Value other) const { - Literal new_rule; - new_rule.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; + return new_value; } - Literal operator ||(const Literal& other) + Value operator ||(const Value other) const { - Literal new_rule; - new_rule.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; + return new_value; } void set(ENUM e, bool value) @@ -81,19 +79,21 @@ namespace LLPredicate modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); } - void set(const Literal& other, bool value) + void set(const Value other, bool value) { U32 predicate_flags = other.mPredicateFlags; while(predicate_flags) { U32 next_flags = clearLSB(predicate_flags); lsb_flag = predicate_flags ^ next_flags; + U32 mask = 0; for (S32 i = 0; i < cMaxEnum; i++) { if (cPredicateFlagsFromEnum[i] & lsb_flag) { mask |= cPredicateFlagsFromEnum[i]; + modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value); } } @@ -112,15 +112,25 @@ namespace LLPredicate mPredicateFlags |= flags_with_predicate; } - void forget(const Literal& literal) + void forget(const Value value) { - set(literal, true); + set(value, true); U32 flags_with_predicate = mPredicateFlags; - set(literal, false); + set(value, false); // ambiguous value is result of adding and removing predicate at the same time! mPredicateFlags |= flags_with_predicate; } + bool allSet() const + { + return mPredicateFlags == ~0; + } + + bool noneSet() const + { + return mPredicateFlags == 0; + } + private: predicate_flag_t clearLSB(predicate_flag_t value) @@ -156,56 +166,70 @@ namespace LLPredicate predicate_flag_t mPredicateFlags; }; - template - struct Value - : public Literal - { - public: - Value(ENUM e) - : Literal(e) - {} - - Value() - {} - }; - template class Rule - : public Literal { public: Rule(ENUM value) - : Literal(value) + : mRule(value) + {} + + Rule(const Rule& other) + : mRule(other.mRule) {} - Rule(const Literal other) - : Literal(other) + Rule(const Value other) + : mRule(other) {} Rule() {} - bool check(const Value& value) const + bool check(const Value value) const { - return (value.mPredicateFlags & mPredicateFlags) != 0; + return !(mRule && value).noneSet(); } bool isTriviallyTrue() const { - return mPredicateFlags == 0xFFFFffff; + return mRule.allSet(); } bool isTriviallyFalse() const { - return mPredicateFlags == 0; + return mRule.noneSet(); + } + + Rule operator!() const + { + Rule new_rule; + new_rule.mRule = !mRule; + return new_rule; } + + Rule operator &&(const Rule other) const + { + Rule new_rule; + new_rule.mRule = mRule && other.mRule; + return new_rule; + } + + Rule operator ||(const Rule other) const + { + Rule new_rule; + new_rule.mRule = mRule || other.mRule; + return new_rule; + } + + private: + Value mRule; }; } template -LLPredicate::Literal ll_predicate(ENUM e) +LLPredicate::Value ll_predicate(ENUM e) { - return LLPredicate::Literal(e); + return LLPredicate::Value(e); } -- cgit v1.2.3 From 819adb5eb4d7f982121f3dbd82750e05d26864d9 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 1 Nov 2012 00:26:44 -0700 Subject: SH-3405 FIX convert existing stats to lltrace system final removal of remaining LLStat code --- indra/llcommon/CMakeLists.txt | 2 - indra/llcommon/llinstancetracker.h | 10 +- indra/llcommon/llmetricperformancetester.cpp | 1 - indra/llcommon/llpredicate.h | 4 + indra/llcommon/llstat.cpp | 352 --------------------------- indra/llcommon/llstat.h | 103 -------- indra/llcommon/lltrace.h | 90 ++++--- indra/llcommon/lltracerecording.cpp | 119 ++++++++- indra/llcommon/lltracerecording.h | 216 +++++++++------- indra/llcommon/lltracethreadrecorder.cpp | 4 + 10 files changed, 319 insertions(+), 582 deletions(-) delete mode 100644 indra/llcommon/llstat.cpp delete mode 100644 indra/llcommon/llstat.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index d876842cf1..0f5ded86ed 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -91,7 +91,6 @@ set(llcommon_SOURCE_FILES llsdutil.cpp llsecondlifeurls.cpp llsingleton.cpp - llstat.cpp llstacktrace.cpp llstreamqueue.cpp llstreamtools.cpp @@ -234,7 +233,6 @@ set(llcommon_HEADER_FILES llsortedvector.h llstack.h llstacktrace.h - llstat.h llstatenums.h llstl.h llstreamqueue.h diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index 403df08990..3a1187a4c1 100644 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -77,8 +77,8 @@ protected: /// This mix-in class adds support for tracking all instances of the specified class parameter T /// The (optional) key associates a value of type KEY with a given instance of T, for quick lookup /// If KEY is not provided, then instances are stored in a simple set -/// @NOTE: see explicit specialization below for default KEY==T* case -template +/// @NOTE: see explicit specialization below for default KEY==void case +template class LLInstanceTracker : public LLInstanceTrackerBase { typedef LLInstanceTracker MyT; @@ -224,12 +224,12 @@ private: KEY mInstanceKey; }; -/// explicit specialization for default case where KEY is T* +/// explicit specialization for default case where KEY is void /// use a simple std::set template -class LLInstanceTracker : public LLInstanceTrackerBase +class LLInstanceTracker : public LLInstanceTrackerBase { - typedef LLInstanceTracker MyT; + typedef LLInstanceTracker MyT; typedef typename std::set InstanceSet; struct StaticData: public StaticBase { diff --git a/indra/llcommon/llmetricperformancetester.cpp b/indra/llcommon/llmetricperformancetester.cpp index 41d3eb0bf3..a1b0a684c5 100644 --- a/indra/llcommon/llmetricperformancetester.cpp +++ b/indra/llcommon/llmetricperformancetester.cpp @@ -29,7 +29,6 @@ #include "indra_constants.h" #include "llerror.h" #include "llsdserialize.h" -#include "llstat.h" #include "lltreeiterators.h" #include "llmetricperformancetester.h" diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 3f1bf1c8e6..75744667d9 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -165,6 +165,10 @@ namespace LLPredicate : Literal(e) {} + Value(const Literal other) + : Literal(other) + {} + Value() {} }; diff --git a/indra/llcommon/llstat.cpp b/indra/llcommon/llstat.cpp deleted file mode 100644 index b46d2e58b2..0000000000 --- a/indra/llcommon/llstat.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/** - * @file llstat.cpp - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "llstat.h" -#include "lllivefile.h" -#include "llerrorcontrol.h" -#include "llframetimer.h" -#include "timing.h" -#include "llsd.h" -#include "llsdserialize.h" -#include "llstl.h" -#include "u64.h" - - -// statics -//------------------------------------------------------------------------ -LLTimer LLStat::sTimer; -LLFrameTimer LLStat::sFrameTimer; - -void LLStat::reset() -{ - mNumValues = 0; - mLastValue = 0.f; - delete[] mBins; - mBins = new ValueEntry[mNumBins]; - mCurBin = mNumBins-1; - mNextBin = 0; -} - -LLStat::LLStat(std::string name, BOOL use_frame_timer) -: LLInstanceTracker(name), - mUseFrameTimer(use_frame_timer), - mNumBins(50), - mName(name), - mBins(NULL) -{ - llassert(mNumBins > 0); - mLastTime = 0.f; - - reset(); -} - -LLStat::~LLStat() -{ - delete[] mBins; -} -// -//void LLStat::start() -//{ -// if (mUseFrameTimer) -// { -// mBins[mNextBin].mBeginTime = sFrameTimer.getElapsedSeconds(); -// } -// else -// { -// mBins[mNextBin].mBeginTime = sTimer.getElapsedTimeF64(); -// } -//} - -void LLStat::addValue(const F32 value) -{ - if (mNumValues < mNumBins) - { - mNumValues++; - } - - // Increment the bin counters. - mCurBin++; - if (mCurBin >= mNumBins) - { - mCurBin = 0; - } - mNextBin++; - if (mNextBin >= mNumBins) - { - mNextBin = 0; - } - - mBins[mCurBin].mValue = value; - if (mUseFrameTimer) - { - mBins[mCurBin].mTime = sFrameTimer.getElapsedSeconds(); - } - else - { - mBins[mCurBin].mTime = sTimer.getElapsedTimeF64(); - } - mBins[mCurBin].mDT = (F32)(mBins[mCurBin].mTime - mBins[mCurBin].mBeginTime); - - //this value is used to prime the min/max calls - mLastTime = mBins[mCurBin].mTime; - mLastValue = value; - - // Set the begin time for the next stat segment. - mBins[mNextBin].mBeginTime = mBins[mCurBin].mTime; - mBins[mNextBin].mTime = mBins[mCurBin].mTime; - mBins[mNextBin].mDT = 0.f; -} - - -F32 LLStat::getMax() const -{ - S32 i; - F32 current_max = mLastValue; - if (mNumBins == 0) - { - current_max = 0.f; - } - else - { - for (i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - if (mBins[i].mValue > current_max) - { - current_max = mBins[i].mValue; - } - } - } - return current_max; -} - -F32 LLStat::getMean() const -{ - S32 i; - F32 current_mean = 0.f; - S32 samples = 0; - for (i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - current_mean += mBins[i].mValue; - samples++; - } - - // There will be a wrap error at 2^32. :) - if (samples != 0) - { - current_mean /= samples; - } - else - { - current_mean = 0.f; - } - return current_mean; -} - -F32 LLStat::getMin() const -{ - S32 i; - F32 current_min = mLastValue; - - if (mNumBins == 0) - { - current_min = 0.f; - } - else - { - for (i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - if (mBins[i].mValue < current_min) - { - current_min = mBins[i].mValue; - } - } - } - return current_min; -} - -F32 LLStat::getPrev(S32 age) const -{ - S32 bin; - bin = mCurBin - age; - - while (bin < 0) - { - bin += mNumBins; - } - - if (bin == mNextBin) - { - // Bogus for bin we're currently working on. - return 0.f; - } - return mBins[bin].mValue; -} - -F32 LLStat::getPrevPerSec(S32 age) const -{ - S32 bin; - bin = mCurBin - age; - - while (bin < 0) - { - bin += mNumBins; - } - - if (bin == mNextBin) - { - // Bogus for bin we're currently working on. - return 0.f; - } - return mBins[bin].mValue / mBins[bin].mDT; -} - -F32 LLStat::getCurrent() const -{ - return mBins[mCurBin].mValue; -} - -F32 LLStat::getCurrentPerSec() const -{ - return mBins[mCurBin].mValue / mBins[mCurBin].mDT; -} - -F32 LLStat::getMeanPerSec() const -{ - S32 i; - F32 value = 0.f; - F32 dt = 0.f; - - for (i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - value += mBins[i].mValue; - dt += mBins[i].mDT; - } - - if (dt > 0.f) - { - return value/dt; - } - else - { - return 0.f; - } -} - -F32 LLStat::getMaxPerSec() const -{ - F32 value; - - if (mNextBin != 0) - { - value = mBins[0].mValue/mBins[0].mDT; - } - else if (mNumValues > 0) - { - value = mBins[1].mValue/mBins[1].mDT; - } - else - { - value = 0.f; - } - - for (S32 i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - value = llmax(value, mBins[i].mValue/mBins[i].mDT); - } - return value; -} - -F32 LLStat::getMinPerSec() const -{ - S32 i; - F32 value; - - if (mNextBin != 0) - { - value = mBins[0].mValue/mBins[0].mDT; - } - else if (mNumValues > 0) - { - value = mBins[1].mValue/mBins[0].mDT; - } - else - { - value = 0.f; - } - - for (i = 0; (i < mNumBins) && (i < mNumValues); i++) - { - // Skip the bin we're currently filling. - if (i == mNextBin) - { - continue; - } - value = llmin(value, mBins[i].mValue/mBins[i].mDT); - } - return value; -} - -U32 LLStat::getNumValues() const -{ - return mNumValues; -} - -S32 LLStat::getNumBins() const -{ - return mNumBins; -} - -S32 LLStat::getNextBin() const -{ - return mNextBin; -} - diff --git a/indra/llcommon/llstat.h b/indra/llcommon/llstat.h deleted file mode 100644 index 82a246275d..0000000000 --- a/indra/llcommon/llstat.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @file llstat.h - * @brief Runtime statistics accumulation. - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLSTAT_H -#define LL_LLSTAT_H - -#include - -#include "lltimer.h" -#include "llframetimer.h" -#include "llinstancetracker.h" - -class LLSD; - -// ---------------------------------------------------------------------------- -class LL_COMMON_API LLStat : public LLInstanceTracker -{ -public: - LLStat(std::string name = std::string(), BOOL use_frame_timer = FALSE); - ~LLStat(); - - //void start(); // Start the timer for the current "frame", otherwise uses the time tracked from - // the last addValue - void reset(); - void addValue(const F32 value = 1.f); // Adds the current value being tracked, and tracks the DT. - void addValue(const S32 value) { addValue((F32)value); } - void addValue(const U32 value) { addValue((F32)value); } - - S32 getNextBin() const; - - F32 getPrev(S32 age) const; // Age is how many "addValues" previously - zero is current - F32 getPrevPerSec(S32 age) const; // Age is how many "addValues" previously - zero is current - - F32 getCurrent() const; - F32 getCurrentPerSec() const; - - F32 getMin() const; - F32 getMinPerSec() const; - - F32 getMean() const; - F32 getMeanPerSec() const; - - F32 getMax() const; - F32 getMaxPerSec() const; - - U32 getNumValues() const; - S32 getNumBins() const; - -private: - bool mUseFrameTimer; - U32 mNumValues; - U32 mNumBins; - F32 mLastValue; - F64 mLastTime; - - struct ValueEntry - { - ValueEntry() - : mValue(0.f), - mBeginTime(0.0), - mTime(0.0), - mDT(0.f) - {} - F32 mValue; - F64 mBeginTime; - F64 mTime; - F32 mDT; - }; - ValueEntry* mBins; - - S32 mCurBin; - S32 mNextBin; - - std::string mName; - - static LLTimer sTimer; - static LLFrameTimer sFrameTimer; -}; - -#endif // LL_STAT_ diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 2cdae4b0d2..2823db5cbb 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -227,10 +227,33 @@ namespace LLTrace }; + template + struct StorageType + { + typedef T type_t; + }; + + template + struct StorageType + { + typedef typename StorageType::type_t type_t; + }; + + template<> struct StorageType { typedef F64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template<> struct StorageType { typedef S64 type_t; }; + template class LL_COMMON_API MeasurementAccumulator { public: + typedef T value_t; + typedef MeasurementAccumulator self_t; + MeasurementAccumulator() : mSum(0), mMin(std::numeric_limits::max()), @@ -243,23 +266,24 @@ namespace LLTrace LL_FORCE_INLINE void sample(T value) { + T storage_value(value); mNumSamples++; - mSum += value; - if (value < mMin) + mSum += storage_value; + if (storage_value < mMin) { - mMin = value; + mMin = storage_value; } - else if (value > mMax) + if (storage_value > mMax) { - mMax = value; + mMax = storage_value; } F64 old_mean = mMean; - mMean += ((F64)value - old_mean) / (F64)mNumSamples; - mVarianceSum += ((F64)value - old_mean) * ((F64)value - mMean); - mLastValue = value; + mMean += ((F64)storage_value - old_mean) / (F64)mNumSamples; + mVarianceSum += ((F64)storage_value - old_mean) * ((F64)storage_value - mMean); + mLastValue = storage_value; } - void addSamples(const MeasurementAccumulator& other) + void addSamples(const self_t& other) { mSum += other.mSum; if (other.mMin < mMin) @@ -293,7 +317,7 @@ namespace LLTrace } else { - mVarianceSum = (F32)mNumSamples + mVarianceSum = (F64)mNumSamples * ((((n_1 - 1.f) * sd_1 * sd_1) + ((n_2 - 1.f) * sd_2 * sd_2) + (((n_1 * n_2) / (n_1 + n_2)) @@ -311,10 +335,10 @@ namespace LLTrace mMax = 0; } - T getSum() const { return mSum; } - T getMin() const { return mMin; } - T getMax() const { return mMax; } - T getLastValue() const { return mLastValue; } + T getSum() const { return (T)mSum; } + T getMin() const { return (T)mMin; } + T getMax() const { return (T)mMax; } + T getLastValue() const { return (T)mLastValue; } F64 getMean() const { return mMean; } F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } U32 getSampleCount() const { return mNumSamples; } @@ -325,7 +349,7 @@ namespace LLTrace mMax, mLastValue; - F64 mMean, + F64 mMean, mVarianceSum; U32 mNumSamples; @@ -335,6 +359,8 @@ namespace LLTrace class LL_COMMON_API CountAccumulator { public: + typedef T value_t; + CountAccumulator() : mSum(0), mNumSamples(0) @@ -358,7 +384,7 @@ namespace LLTrace mSum = 0; } - T getSum() const { return mSum; } + T getSum() const { return (T)mSum; } private: T mSum; @@ -366,14 +392,15 @@ namespace LLTrace U32 mNumSamples; }; - typedef TraceType > measurement_common_t; + typedef TraceType > measurement_common_float_t; + typedef TraceType > measurement_common_int_t; template class LL_COMMON_API Measurement - : public TraceType > + : public TraceType::type_t> > { public: - typedef T storage_t; + typedef typename StorageType::type_t storage_t; Measurement(const char* name, const char* description = NULL) : TraceType(name, description) @@ -381,17 +408,16 @@ namespace LLTrace void sample(T value) { - getPrimaryAccumulator().sample(value); + getPrimaryAccumulator().sample((storage_t)value); } }; template class LL_COMMON_API Measurement - : public TraceType > + : public TraceType::type_t> > { public: - typedef typename T::storage_t storage_t; - typedef Measurement base_measurement_t; + typedef typename StorageType::type_t storage_t; Measurement(const char* name, const char* description = NULL) : TraceType(name, description) @@ -402,18 +428,19 @@ namespace LLTrace { T converted_value; converted_value.assignFrom(value); - getPrimaryAccumulator().sample(converted_value.value()); + getPrimaryAccumulator().sample((storage_t)converted_value.value()); } }; - typedef TraceType > count_common_t; + typedef TraceType > count_common_float_t; + typedef TraceType > count_common_int_t; template class LL_COMMON_API Count - : public TraceType > + : public TraceType::type_t> > { public: - typedef T storage_t; + typedef typename StorageType::type_t storage_t; Count(const char* name, const char* description = NULL) : TraceType(name) @@ -421,17 +448,16 @@ namespace LLTrace void add(T value) { - getPrimaryAccumulator().add(value); + getPrimaryAccumulator().add((storage_t)value); } }; template class LL_COMMON_API Count - : public TraceType > + : public TraceType::type_t> > { public: - typedef typename T::storage_t storage_t; - typedef Count base_count_t; + typedef typename StorageType::type_t storage_t; Count(const char* name, const char* description = NULL) : TraceType(name) @@ -442,7 +468,7 @@ namespace LLTrace { T converted_value; converted_value.assignFrom(value); - getPrimaryAccumulator().add(converted_value.value()); + getPrimaryAccumulator().add((storage_t)converted_value.value()); } }; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 9a769ff344..f44a0a2764 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -39,8 +39,10 @@ namespace LLTrace Recording::Recording() : mElapsedSeconds(0), - mCounts(new AccumulatorBuffer >()), - mMeasurements(new AccumulatorBuffer >()), + mCountsFloat(new AccumulatorBuffer >()), + mMeasurementsFloat(new AccumulatorBuffer >()), + mCounts(new AccumulatorBuffer >()), + mMeasurements(new AccumulatorBuffer >()), mStackTimers(new AccumulatorBuffer()) {} @@ -59,6 +61,8 @@ void Recording::update() void Recording::handleReset() { + mCountsFloat.write()->reset(); + mMeasurementsFloat.write()->reset(); mCounts.write()->reset(); mMeasurements.write()->reset(); mStackTimers.write()->reset(); @@ -88,6 +92,8 @@ void Recording::handleSplitTo(Recording& other) void Recording::makePrimary() { + mCountsFloat.write()->makePrimary(); + mMeasurementsFloat.write()->makePrimary(); mCounts.write()->makePrimary(); mMeasurements.write()->makePrimary(); mStackTimers.write()->makePrimary(); @@ -100,14 +106,120 @@ bool Recording::isPrimary() const void Recording::mergeRecording( const Recording& other ) { + mCountsFloat.write()->addSamples(*other.mCountsFloat); + mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); mCounts.write()->addSamples(*other.mCounts); mMeasurements.write()->addSamples(*other.mMeasurements); mStackTimers.write()->addSamples(*other.mStackTimers); mElapsedSeconds += other.mElapsedSeconds; } +F64 Recording::getSum( const TraceType >& stat ) const +{ + return stat.getAccumulator(mCountsFloat).getSum(); +} + +S64 Recording::getSum( const TraceType >& stat ) const +{ + return stat.getAccumulator(mCounts).getSum(); +} + +F64 Recording::getSum( const TraceType >& stat ) const +{ + return (F64)stat.getAccumulator(mMeasurementsFloat).getSum(); +} + +S64 Recording::getSum( const TraceType >& stat ) const +{ + return (S64)stat.getAccumulator(mMeasurements).getSum(); +} + + + +F64 Recording::getPerSec( const TraceType >& stat ) const +{ + return stat.getAccumulator(mCountsFloat).getSum() / mElapsedSeconds; +} + +F64 Recording::getPerSec( const TraceType >& stat ) const +{ + return (F64)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; +} + +F64 Recording::getPerSec( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getSum() / mElapsedSeconds; +} + +F64 Recording::getPerSec( const TraceType >& stat ) const +{ + return (F64)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; +} + +F64 Recording::getMin( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getMin(); +} + +S64 Recording::getMin( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getMin(); +} + +F64 Recording::getMax( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getMax(); +} + +S64 Recording::getMax( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getMax(); +} + +F64 Recording::getMean( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getMean(); +} + +F64 Recording::getMean( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getMean(); +} + +F64 Recording::getStandardDeviation( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getStandardDeviation(); +} + +F64 Recording::getStandardDeviation( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getStandardDeviation(); +} + +F64 Recording::getLastValue( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getLastValue(); +} + +S64 Recording::getLastValue( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getLastValue(); +} + +U32 Recording::getSampleCount( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurementsFloat).getSampleCount(); +} + +U32 Recording::getSampleCount( const TraceType >& stat ) const +{ + return stat.getAccumulator(mMeasurements).getSampleCount(); +} + + + /////////////////////////////////////////////////////////////////////// -// Recording +// PeriodicRecording /////////////////////////////////////////////////////////////////////// PeriodicRecording::PeriodicRecording( S32 num_periods ) @@ -179,6 +291,7 @@ void PeriodicRecording::handleSplitTo( PeriodicRecording& other ) getCurRecordingPeriod().handleSplitTo(other.getCurRecordingPeriod()); } + /////////////////////////////////////////////////////////////////////// // ExtendableRecording /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index d3f001ab6a..4af973515d 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -112,124 +112,81 @@ namespace LLTrace void update(); // Count accessors + F64 getSum(const TraceType >& stat) const; + S64 getSum(const TraceType >& stat) const; template - T getSum(const TraceType >& stat) const + T getSum(const Count& stat) const { - return (T)stat.getAccumulator(mCounts).getSum(); - } - - template - T getSum(const Count& stat) const - { - return (T)stat.getAccumulator(mCounts).getSum(); + return (T)getSum(static_cast::type_t> >&> (stat)); } + F64 getPerSec(const TraceType >& stat) const; + F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const TraceType >& stat) const + T getPerSec(const Count& stat) const { - return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; - } - - template - T getPerSec(const Count& stat) const - { - return (T)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; + return (T)getPerSec(static_cast::type_t> >&> (stat)); } // Measurement accessors + F64 getSum(const TraceType >& stat) const; + S64 getSum(const TraceType >& stat) const; template - T getSum(const TraceType >& stat) const + T getSum(const Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getSum(); - - } - - template - T getSum(const Measurement& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getSum(); - + return (T)getSum(static_cast::type_t> >&> (stat)); } + F64 getPerSec(const TraceType >& stat) const; + F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const TraceType >& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; - } - - template - T getPerSec(const Measurement& stat) const + T getPerSec(const Measurement& stat) const { - return (typename Count::base_unit_t)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; + return (T)getPerSec(static_cast::type_t> >&> (stat)); } + F64 getMin(const TraceType >& stat) const; + S64 getMin(const TraceType >& stat) const; template - T getMin(const TraceType >& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getMin(); - } - - template - T getMin(const Measurement& stat) const + T getMin(const Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getMin(); + return (T)getMin(static_cast::type_t> >&> (stat)); } - + F64 getMax(const TraceType >& stat) const; + S64 getMax(const TraceType >& stat) const; template - T getMax(const TraceType >& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getMax(); - } - - template - T getMax(const Measurement& stat) const + T getMax(const Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getMax(); + return (T)getMax(static_cast::type_t> >&> (stat)); } + F64 getMean(const TraceType >& stat) const; + F64 getMean(const TraceType >& stat) const; template - T getMean(const TraceType >& stat) const + T getMean(Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getMean(); - } - - template - T getMean(Measurement& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getMean(); + return (T)getMean(static_cast::type_t> >&> (stat)); } + F64 getStandardDeviation(const TraceType >& stat) const; + F64 getStandardDeviation(const TraceType >& stat) const; template - T getStandardDeviation(const TraceType >& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getStandardDeviation(); - } - - template - T getStandardDeviation(const Measurement& stat) const + T getStandardDeviation(const Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getStandardDeviation(); + return (T)getMean(static_cast::type_t> >&> (stat)); } + F64 getLastValue(const TraceType >& stat) const; + S64 getLastValue(const TraceType >& stat) const; template - T getLastValue(const TraceType >& stat) const - { - return (T)stat.getAccumulator(mMeasurements).getLastValue(); - } - - template - T getLastValue(const Measurement& stat) const + T getLastValue(const Measurement& stat) const { - return (T)stat.getAccumulator(mMeasurements).getLastValue(); + return (T)getLastValue(static_cast::type_t> >&> (stat)); } - - template - U32 getSampleCount(const TraceType >& stat) const - { - return stat.getAccumulator(mMeasurements).getSampleCount(); - } + U32 getSampleCount(const TraceType >& stat) const; + U32 getSampleCount(const TraceType >& stat) const; LLUnit::Seconds getDuration() const { return mElapsedSeconds; } @@ -244,8 +201,10 @@ namespace LLTrace // returns data for current thread class ThreadRecorder* getThreadRecorder(); - LLCopyOnWritePointer > > mCounts; - LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > > mCountsFloat; + LLCopyOnWritePointer > > mMeasurementsFloat; + LLCopyOnWritePointer > > mCounts; + LLCopyOnWritePointer > > mMeasurements; LLCopyOnWritePointer > mStackTimers; LLTimer mSamplingTimer; @@ -260,6 +219,7 @@ namespace LLTrace ~PeriodicRecording(); void nextPeriod(); + S32 getNumPeriods() { return mNumPeriods; } Recording& getLastRecordingPeriod() { @@ -268,7 +228,7 @@ namespace LLTrace const Recording& getLastRecordingPeriod() const { - return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; + return getPrevRecordingPeriod(1); } Recording& getCurRecordingPeriod() @@ -281,6 +241,16 @@ namespace LLTrace return mRecordingPeriods[mCurPeriod]; } + Recording& getPrevRecordingPeriod(S32 offset) + { + return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; + } + + const Recording& getPrevRecordingPeriod(S32 offset) const + { + return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; + } + Recording snapshotCurRecordingPeriod() const { Recording recording_copy(getCurRecordingPeriod()); @@ -290,6 +260,84 @@ namespace LLTrace Recording& getTotalRecording(); + template + typename T getPeriodMin(const TraceType >& stat) const + { + T min_val = std::numeric_limits::max(); + for (S32 i = 0; i < mNumPeriods; i++) + { + min_val = llmin(min_val, mRecordingPeriods[i].getSum(stat)); + } + return (T)min_val; + } + + template + F64 getPeriodMinPerSec(const TraceType >& stat) const + { + F64 min_val = std::numeric_limits::max(); + for (S32 i = 0; i < mNumPeriods; i++) + { + min_val = llmin(min_val, mRecordingPeriods[i].getPerSec(stat)); + } + return min_val; + } + + template + T getPeriodMax(const TraceType >& stat) const + { + T max_val = std::numeric_limits::min(); + for (S32 i = 0; i < mNumPeriods; i++) + { + max_val = llmax(max_val, mRecordingPeriods[i].getSum(stat)); + } + return max_val; + } + + template + F64 getPeriodMaxPerSec(const TraceType >& stat) const + { + F64 max_val = std::numeric_limits::min(); + for (S32 i = 0; i < mNumPeriods; i++) + { + max_val = llmax(max_val, mRecordingPeriods[i].getPerSec(stat)); + } + return max_val; + } + + template + F64 getPeriodMean(const TraceType >& stat) const + { + F64 mean = 0.0; + F64 count = 0; + for (S32 i = 0; i < mNumPeriods; i++) + { + if (mRecordingPeriods[i].getDuration() > 0.f) + { + count++; + mean += mRecordingPeriods[i].getSum(stat); + } + } + mean /= (F64)mNumPeriods; + return mean; + } + + template + F64 getPeriodMeanPerSec(const TraceType >& stat) const + { + F64 mean = 0.0; + F64 count = 0; + for (S32 i = 0; i < mNumPeriods; i++) + { + if (mRecordingPeriods[i].getDuration() > 0.f) + { + count++; + mean += mRecordingPeriods[i].getPerSec(stat); + } + } + mean /= count; + return mean; + } + private: // implementation for LLVCRControlsMixin diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index e81333f7f2..15056b80e4 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -113,9 +113,13 @@ ThreadRecorder::ActiveRecording::ActiveRecording( Recording* target ) void ThreadRecorder::ActiveRecording::moveBaselineToTarget() { + mTargetRecording->mMeasurementsFloat.write()->addSamples(*mBaseline.mMeasurementsFloat); + mTargetRecording->mCountsFloat.write()->addSamples(*mBaseline.mCountsFloat); mTargetRecording->mMeasurements.write()->addSamples(*mBaseline.mMeasurements); mTargetRecording->mCounts.write()->addSamples(*mBaseline.mCounts); mTargetRecording->mStackTimers.write()->addSamples(*mBaseline.mStackTimers); + mBaseline.mMeasurementsFloat.write()->reset(); + mBaseline.mCountsFloat.write()->reset(); mBaseline.mMeasurements.write()->reset(); mBaseline.mCounts.write()->reset(); mBaseline.mStackTimers.write()->reset(); -- cgit v1.2.3 From 74fe126590fba03752d1d8d88dd3bb59c6900026 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 1 Nov 2012 17:52:11 -0700 Subject: SH-3405 FIX convert existing stats to lltrace system output of floater_stats is now identical to pre-lltrace system (with some tweaks) --- indra/llcommon/lltrace.h | 95 +++++++++++++++++--------------- indra/llcommon/lltracerecording.cpp | 34 +++++++++--- indra/llcommon/lltracerecording.h | 6 +- indra/llcommon/lltracethreadrecorder.cpp | 6 +- 4 files changed, 83 insertions(+), 58 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 2823db5cbb..735c45754c 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -138,11 +138,11 @@ namespace LLTrace } } - void reset() + void reset(const AccumulatorBuffer* other = NULL) { for (size_t i = 0; i < mNextStorageSlot; i++) { - mStorage[i].reset(); + mStorage[i].reset(other ? &other->mStorage[i] : NULL); } } @@ -285,54 +285,60 @@ namespace LLTrace void addSamples(const self_t& other) { - mSum += other.mSum; - if (other.mMin < mMin) - { - mMin = other.mMin; - } - if (other.mMax > mMax) - { - mMax = other.mMax; - } - mNumSamples += other.mNumSamples; - F64 weight = (F64)mNumSamples / (F64)(mNumSamples + other.mNumSamples); - mMean = mMean * weight + other.mMean * (1.f - weight); - - F64 n_1 = (F64)mNumSamples, - n_2 = (F64)other.mNumSamples; - F64 m_1 = mMean, - m_2 = other.mMean; - F64 sd_1 = getStandardDeviation(), - sd_2 = other.getStandardDeviation(); - // combine variance (and hence standard deviation) of 2 different sized sample groups using - // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm - if (n_1 == 0) + if (other.mNumSamples) { - mVarianceSum = other.mVarianceSum; + mSum += other.mSum; + if (other.mMin < mMin) + { + mMin = other.mMin; + } + if (other.mMax > mMax) + { + mMax = other.mMax; + } + F64 weight = (F64)mNumSamples / (F64)(mNumSamples + other.mNumSamples); + mNumSamples += other.mNumSamples; + mMean = mMean * weight + other.mMean * (1.f - weight); + + F64 n_1 = (F64)mNumSamples, + n_2 = (F64)other.mNumSamples; + F64 m_1 = mMean, + m_2 = other.mMean; + F64 sd_1 = getStandardDeviation(), + sd_2 = other.getStandardDeviation(); + // combine variance (and hence standard deviation) of 2 different sized sample groups using + // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm + if (n_1 == 0) + { + mVarianceSum = other.mVarianceSum; + } + else if (n_2 == 0) + { + // don't touch variance + // mVarianceSum = mVarianceSum; + } + else + { + mVarianceSum = (F64)mNumSamples + * ((((n_1 - 1.f) * sd_1 * sd_1) + + ((n_2 - 1.f) * sd_2 * sd_2) + + (((n_1 * n_2) / (n_1 + n_2)) + * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) + / (n_1 + n_2 - 1.f)); + } + mLastValue = other.mLastValue; } - else if (n_2 == 0) - { - // don't touch variance - // mVarianceSum = mVarianceSum; - } - else - { - mVarianceSum = (F64)mNumSamples - * ((((n_1 - 1.f) * sd_1 * sd_1) - + ((n_2 - 1.f) * sd_2 * sd_2) - + (((n_1 * n_2) / (n_1 + n_2)) - * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) - / (n_1 + n_2 - 1.f)); - } - mLastValue = other.mLastValue; } - void reset() + void reset(const self_t* other) { mNumSamples = 0; mSum = 0; mMin = 0; mMax = 0; + mMean = 0; + mVarianceSum = 0; + mLastValue = other ? other->mLastValue : 0; } T getSum() const { return (T)mSum; } @@ -359,6 +365,7 @@ namespace LLTrace class LL_COMMON_API CountAccumulator { public: + typedef CountAccumulator self_t; typedef T value_t; CountAccumulator() @@ -378,7 +385,7 @@ namespace LLTrace mNumSamples += other.mNumSamples; } - void reset() + void reset(const self_t* other) { mNumSamples = 0; mSum = 0; @@ -475,6 +482,8 @@ namespace LLTrace class LL_COMMON_API TimerAccumulator { public: + typedef TimerAccumulator self_t; + U32 mTotalTimeCounter, mChildTimeCounter, mCalls; @@ -493,7 +502,7 @@ namespace LLTrace mCalls += other.mCalls; } - void reset() + void reset(const self_t* other) { mTotalTimeCounter = 0; mChildTimeCounter = 0; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index f44a0a2764..a2733fd0e7 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -87,6 +87,8 @@ void Recording::handleSplitTo(Recording& other) { stop(); other.restart(); + other.mMeasurementsFloat.write()->reset(mMeasurementsFloat); + other.mMeasurements.write()->reset(mMeasurements); } @@ -104,7 +106,7 @@ bool Recording::isPrimary() const return mCounts->isPrimary(); } -void Recording::mergeRecording( const Recording& other ) +void Recording::appendRecording( const Recording& other ) { mCountsFloat.write()->addSamples(*other.mCountsFloat); mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); @@ -138,22 +140,34 @@ S64 Recording::getSum( const TraceType >& stat ) con F64 Recording::getPerSec( const TraceType >& stat ) const { - return stat.getAccumulator(mCountsFloat).getSum() / mElapsedSeconds; + F64 sum = stat.getAccumulator(mCountsFloat).getSum(); + return (sum != 0.0) + ? (sum / mElapsedSeconds) + : 0.0; } F64 Recording::getPerSec( const TraceType >& stat ) const { - return (F64)stat.getAccumulator(mCounts).getSum() / mElapsedSeconds; + S64 sum = stat.getAccumulator(mCounts).getSum(); + return (sum != 0) + ? ((F64)sum / mElapsedSeconds) + : 0.0; } F64 Recording::getPerSec( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getSum() / mElapsedSeconds; + F64 sum = stat.getAccumulator(mMeasurementsFloat).getSum(); + return (sum != 0.0) + ? (sum / mElapsedSeconds) + : 0.0; } F64 Recording::getPerSec( const TraceType >& stat ) const { - return (F64)stat.getAccumulator(mMeasurements).getSum() / mElapsedSeconds; + S64 sum = stat.getAccumulator(mMeasurements).getSum(); + return (sum != 0) + ? ((F64)sum / mElapsedSeconds) + : 0.0; } F64 Recording::getMin( const TraceType >& stat ) const @@ -240,17 +254,19 @@ PeriodicRecording::~PeriodicRecording() void PeriodicRecording::nextPeriod() { EPlayState play_state = getPlayState(); - getCurRecordingPeriod().stop(); + Recording& old_recording = getCurRecordingPeriod(); mCurPeriod = (mCurPeriod + 1) % mNumPeriods; + old_recording.splitTo(getCurRecordingPeriod()); + switch(play_state) { case STOPPED: + getCurRecordingPeriod().stop(); break; case PAUSED: getCurRecordingPeriod().pause(); break; case STARTED: - getCurRecordingPeriod().start(); break; } // new period, need to recalculate total @@ -264,7 +280,7 @@ Recording& PeriodicRecording::getTotalRecording() mTotalRecording.reset(); for (S32 i = mCurPeriod + 1; i < mCurPeriod + mNumPeriods; i++) { - mTotalRecording.mergeRecording(mRecordingPeriods[i % mNumPeriods]); + mTotalRecording.appendRecording(mRecordingPeriods[i % mNumPeriods]); } } mTotalValid = true; @@ -298,7 +314,7 @@ void PeriodicRecording::handleSplitTo( PeriodicRecording& other ) void ExtendableRecording::extend() { - mAcceptedRecording.mergeRecording(mPotentialRecording); + mAcceptedRecording.appendRecording(mPotentialRecording); mPotentialRecording.reset(); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 4af973515d..a11f04b14b 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -81,12 +81,12 @@ class LLVCRControlsMixin public: void splitTo(DERIVED& other) { - onSplitTo(other); + handleSplitTo(other); } void splitFrom(DERIVED& other) { - other.onSplitTo(*this); + other.handleSplitTo(*this); } private: // atomically stop this object while starting the other @@ -107,7 +107,7 @@ namespace LLTrace void makePrimary(); bool isPrimary() const; - void mergeRecording(const Recording& other); + void appendRecording(const Recording& other); void update(); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 15056b80e4..0feb3ab7af 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -73,7 +73,7 @@ std::list::iterator ThreadRecorder::update( Rec if (next_it != mActiveRecordings.end()) { // ...push our gathered data down to it - next_it->mBaseline.mergeRecording(it->mBaseline); + next_it->mBaseline.appendRecording(it->mBaseline); } // copy accumulated measurements into result buffer and clear accumulator (mBaseline) @@ -153,13 +153,13 @@ void SlaveThreadRecorder::pushToMaster() void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) { LLMutexLock lock(&mRecordingMutex); - mRecording.mergeRecording(source); + mRecording.appendRecording(source); } void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) { LLMutexLock lock(&mRecordingMutex); - sink.mergeRecording(mRecording); + sink.appendRecording(mRecording); } /////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From bb6bda9eef48f5b08b56af46321b79fe7f1d49d7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 1 Nov 2012 19:55:06 -0700 Subject: SH-3499 Ensure asset stats output is correct added support for specifying predicates for xui and llsd serialization --- indra/llcommon/llinitparam.cpp | 11 ++++------- indra/llcommon/llinitparam.h | 2 +- indra/llcommon/llpredicate.h | 8 ++++---- indra/llcommon/llsdparam.cpp | 4 ++-- indra/llcommon/llsdparam.h | 2 +- indra/llcommon/lltracerecording.cpp | 12 ++++++------ indra/llcommon/lltracerecording.h | 22 +++++++++++----------- 7 files changed, 29 insertions(+), 32 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index afeac0a905..53254c3b56 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -188,12 +188,9 @@ namespace LLInitParam bool BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const predicate_rule_t predicate_rule, const LLInitParam::BaseBlock* diff_block) const { bool serialized = false; - if (!isProvided()) + if (!predicate_rule.check(ll_make_predicate(PROVIDED, isProvided()))) { - if ((predicate_rule && !ll_predicate(PROVIDED)).isTriviallyFalse()) - { - return false; - } + return false; } // named param is one like LLView::Params::follows // unnamed param is like LLView::Params::rect - implicit @@ -206,7 +203,7 @@ namespace LLInitParam param_handle_t param_handle = (*it)->mParamHandle; const Param* param = getParamFromHandle(param_handle); ParamDescriptor::serialize_func_t serialize_func = (*it)->mSerializeFunc; - if (serialize_func && param->anyProvided()) + if (serialize_func && predicate_rule.check(ll_make_predicate(PROVIDED, param->anyProvided()))) { const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL; serialized |= serialize_func(*param, parser, name_stack, predicate_rule, diff_param); @@ -220,7 +217,7 @@ namespace LLInitParam param_handle_t param_handle = it->second->mParamHandle; const Param* param = getParamFromHandle(param_handle); ParamDescriptor::serialize_func_t serialize_func = it->second->mSerializeFunc; - if (serialize_func && param->anyProvided()) + if (serialize_func && predicate_rule.check(ll_make_predicate(PROVIDED, param->anyProvided()))) { // Ensure this param has not already been serialized // Prevents from being serialized as its own tag. diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index b52ac809e0..c82b1226ee 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -545,7 +545,7 @@ namespace LLInitParam } bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); - bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t rule = predicate_rule_t(ll_predicate(PROVIDED) && ll_predicate(NON_DEFAULT)), const BaseBlock* diff_block = NULL) const; + bool serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const predicate_rule_t rule, const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const; virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index a13172da68..3f7abe67f1 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -42,8 +42,8 @@ namespace LLPredicate typedef U32 predicate_flag_t; static const S32 cMaxEnum = 5; - Value(ENUM e) - : mPredicateFlags(cPredicateFlagsFromEnum[e]) + Value(ENUM e, bool predicate_value = true) + : mPredicateFlags(predicate_value ? cPredicateFlagsFromEnum[e] : ~cPredicateFlagsFromEnum[e]) { llassert(0 <= e && e < cMaxEnum); } @@ -227,9 +227,9 @@ namespace LLPredicate } template -LLPredicate::Value ll_predicate(ENUM e) +LLPredicate::Value ll_make_predicate(ENUM e, bool predicate_value = true) { - return LLPredicate::Value(e); + return LLPredicate::Value(e, predicate_value); } diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index 42ecc9897d..c10e1b1e20 100644 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -102,13 +102,13 @@ void LLParamSDParser::readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool //readSDValues(sd, block); } -void LLParamSDParser::writeSD(LLSD& sd, const LLInitParam::BaseBlock& block) +void LLParamSDParser::writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules) { mNameStack.clear(); mWriteRootSD = &sd; name_stack_t name_stack; - block.serializeBlock(*this, name_stack); + block.serializeBlock(*this, name_stack, rules); } /*virtual*/ std::string LLParamSDParser::getCurrentElementName() diff --git a/indra/llcommon/llsdparam.h b/indra/llcommon/llsdparam.h index 6ef5debd7b..032e506fd8 100644 --- a/indra/llcommon/llsdparam.h +++ b/indra/llcommon/llsdparam.h @@ -50,7 +50,7 @@ typedef LLInitParam::Parser parser_t; public: LLParamSDParser(); void readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool silent = false); - void writeSD(LLSD& sd, const LLInitParam::BaseBlock& block); + void writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules = LLInitParam::predicate_rule_t(LLInitParam::PROVIDED) && LLInitParam::NON_DEFAULT); /*virtual*/ std::string getCurrentElementName(); diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index a2733fd0e7..a8e1a5eec9 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -347,7 +347,7 @@ PeriodicRecording& get_frame_recording() } -void LLVCRControlsMixinCommon::start() +void LLStopWatchControlsMixinCommon::start() { switch (mPlayState) { @@ -365,7 +365,7 @@ void LLVCRControlsMixinCommon::start() mPlayState = STARTED; } -void LLVCRControlsMixinCommon::stop() +void LLStopWatchControlsMixinCommon::stop() { switch (mPlayState) { @@ -381,7 +381,7 @@ void LLVCRControlsMixinCommon::stop() mPlayState = STOPPED; } -void LLVCRControlsMixinCommon::pause() +void LLStopWatchControlsMixinCommon::pause() { switch (mPlayState) { @@ -396,7 +396,7 @@ void LLVCRControlsMixinCommon::pause() mPlayState = PAUSED; } -void LLVCRControlsMixinCommon::resume() +void LLStopWatchControlsMixinCommon::resume() { switch (mPlayState) { @@ -412,7 +412,7 @@ void LLVCRControlsMixinCommon::resume() mPlayState = STARTED; } -void LLVCRControlsMixinCommon::restart() +void LLStopWatchControlsMixinCommon::restart() { switch (mPlayState) { @@ -431,7 +431,7 @@ void LLVCRControlsMixinCommon::restart() mPlayState = STARTED; } -void LLVCRControlsMixinCommon::reset() +void LLStopWatchControlsMixinCommon::reset() { handleReset(); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index a11f04b14b..3a786c1357 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -34,10 +34,10 @@ #include "lltimer.h" #include "lltrace.h" -class LL_COMMON_API LLVCRControlsMixinCommon +class LL_COMMON_API LLStopWatchControlsMixinCommon { public: - virtual ~LLVCRControlsMixinCommon() {} + virtual ~LLStopWatchControlsMixinCommon() {} enum EPlayState { @@ -59,7 +59,7 @@ public: EPlayState getPlayState() { return mPlayState; } protected: - LLVCRControlsMixinCommon() + LLStopWatchControlsMixinCommon() : mPlayState(STOPPED) {} @@ -75,8 +75,8 @@ private: }; template -class LLVCRControlsMixin -: public LLVCRControlsMixinCommon +class LLStopWatchControlsMixin +: public LLStopWatchControlsMixinCommon { public: void splitTo(DERIVED& other) @@ -97,7 +97,7 @@ private: namespace LLTrace { - class LL_COMMON_API Recording : public LLVCRControlsMixin + class LL_COMMON_API Recording : public LLStopWatchControlsMixin { public: Recording(); @@ -190,7 +190,7 @@ namespace LLTrace LLUnit::Seconds getDuration() const { return mElapsedSeconds; } - // implementation for LLVCRControlsMixin + // implementation for LLStopWatchControlsMixin /*virtual*/ void handleStart(); /*virtual*/ void handleStop(); /*virtual*/ void handleReset(); @@ -212,7 +212,7 @@ namespace LLTrace }; class LL_COMMON_API PeriodicRecording - : public LLVCRControlsMixin + : public LLStopWatchControlsMixin { public: PeriodicRecording(S32 num_periods); @@ -340,7 +340,7 @@ namespace LLTrace private: - // implementation for LLVCRControlsMixin + // implementation for LLStopWatchControlsMixin /*virtual*/ void handleStart(); /*virtual*/ void handleStop(); /*virtual*/ void handleReset(); @@ -357,12 +357,12 @@ namespace LLTrace PeriodicRecording& get_frame_recording(); class ExtendableRecording - : public LLVCRControlsMixin + : public LLStopWatchControlsMixin { void extend(); private: - // implementation for LLVCRControlsMixin + // implementation for LLStopWatchControlsMixin /*virtual*/ void handleStart(); /*virtual*/ void handleStop(); /*virtual*/ void handleReset(); -- cgit v1.2.3 From f8eaee753174d0cab4e4edcf795f422706d6f302 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 2 Nov 2012 20:03:44 -0700 Subject: SH-3499 Ensure asset stats output is correct improvements to predicate API default rules encapsulated in LLInitParam removed empty flag from viewer asset stats --- indra/llcommon/llinitparam.cpp | 10 ++++++ indra/llcommon/llinitparam.h | 25 +++++++++++-- indra/llcommon/llpredicate.h | 80 +++++++++++++++++++++++++----------------- indra/llcommon/llsdparam.cpp | 4 +-- indra/llcommon/llsdparam.h | 19 +++++++++- 5 files changed, 101 insertions(+), 37 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index 53254c3b56..d20fc03227 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -32,6 +32,12 @@ namespace LLInitParam { + + predicate_rule_t default_parse_rules() + { + return ll_make_predicate(PROVIDED) && !ll_make_predicate(EMPTY) && !ll_make_predicate(HAS_DEFAULT_VALUE); + } + // // Param // @@ -247,6 +253,10 @@ namespace LLInitParam } } + if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY))) + { + serialized |= parser.writeValue(Flag(), name_stack); + } // was anything serialized in this block? return serialized; } diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index c82b1226ee..6177cc7d12 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -297,11 +297,13 @@ namespace LLInitParam PROVIDED, REQUIRED, VALID, - NON_DEFAULT + HAS_DEFAULT_VALUE, + EMPTY }; typedef LLPredicate::Rule predicate_rule_t; + predicate_rule_t default_parse_rules(); // various callbacks and constraints associated with an individual param struct LL_COMMON_API ParamDescriptor @@ -912,7 +914,10 @@ namespace LLInitParam const self_t* diff_typed_param = static_cast(diff_param); LLPredicate::Value predicate; - predicate.set(NON_DEFAULT, !diff_typed_param || ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())); + if (diff_typed_param && ParamCompare::equals(typed_param.getValue(), diff_typed_param->getValue())) + { + predicate.set(HAS_DEFAULT_VALUE); + } if (typed_param.isValid()) { @@ -925,6 +930,8 @@ namespace LLInitParam predicate.set(PROVIDED, false); } + predicate.set(EMPTY, false); + if (!predicate_rule.check(predicate)) return false; if (!name_stack.empty()) @@ -1285,6 +1292,8 @@ namespace LLInitParam predicate.set(PROVIDED, false); } + predicate.set(EMPTY, typed_param.mValues.empty()); + if (!predicate_rule.check(predicate)) return false; for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end(); @@ -1325,6 +1334,12 @@ namespace LLInitParam name_stack.pop_back(); } + + if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY))) + { + serialized |= parser.writeValue(Flag(), name_stack); + } + return serialized; } @@ -1567,6 +1582,12 @@ namespace LLInitParam name_stack.pop_back(); } + + if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY))) + { + serialized |= parser.writeValue(Flag(), name_stack); + } + return serialized; } diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 3f7abe67f1..6c9e5fc145 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -73,43 +73,37 @@ namespace LLPredicate return new_value; } - void set(ENUM e, bool value) + void set(ENUM e, bool value = true) { llassert(0 <= e && e < cMaxEnum); - modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); + mPredicateFlags = modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value, mPredicateFlags); } void set(const Value other, bool value) { - U32 predicate_flags = other.mPredicateFlags; - while(predicate_flags) + predicate_flag_t predicate_flags_to_set = other.mPredicateFlags; + predicate_flag_t cumulative_flags = 0; + while(predicate_flags_to_set) { - U32 next_flags = clearLSB(predicate_flags); - lsb_flag = predicate_flags ^ next_flags; + predicate_flag_t next_flags = clearLSB(predicate_flags_to_set); + predicate_flag_t lsb_flag = predicate_flags_to_set ^ next_flags; - U32 mask = 0; + predicate_flag_t mask = 0; + predicate_flag_t cur_flags = mPredicateFlags; for (S32 i = 0; i < cMaxEnum; i++) { if (cPredicateFlagsFromEnum[i] & lsb_flag) { mask |= cPredicateFlagsFromEnum[i]; - modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value); + cur_flags = modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value, cur_flags); } } - modifyPredicate(lsb_flag, mask, value); + cumulative_flags |= modifyPredicate(lsb_flag, mask, value, cur_flags); - predicate_flags = next_flags; - } - } - - void forget(ENUM e) - { - set(e, true); - U32 flags_with_predicate = mPredicateFlags; - set(e, false); - // ambiguous value is result of adding and removing predicate at the same time! - mPredicateFlags |= flags_with_predicate; + predicate_flags_to_set = next_flags; + } + mPredicateFlags = cumulative_flags; } void forget(const Value value) @@ -131,6 +125,11 @@ namespace LLPredicate return mPredicateFlags == 0; } + bool someSet() const + { + return mPredicateFlags != 0; + } + private: predicate_flag_t clearLSB(predicate_flag_t value) @@ -138,16 +137,16 @@ namespace LLPredicate return value & (value - 1); } - void modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, bool value) + predicate_flag_t modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, predicate_flag_t value, bool set) { llassert(clearLSB(predicate_flag) == 0); predicate_flag_t flags_to_modify; - if (value) + if (set) { flags_to_modify = (mPredicateFlags & ~mask); // clear flags not containing predicate to be added - mPredicateFlags &= mask; + value &= mask; // shift flags, in effect adding predicate flags_to_modify *= predicate_flag; } @@ -155,12 +154,13 @@ namespace LLPredicate { flags_to_modify = mPredicateFlags & mask; // clear flags containing predicate to be removed - mPredicateFlags &= ~mask; + value &= ~mask; // shift flags, in effect removing predicate flags_to_modify /= predicate_flag; } // put modified flags back - mPredicateFlags |= flags_to_modify; + value |= flags_to_modify; + return value; } predicate_flag_t mPredicateFlags; @@ -174,10 +174,6 @@ namespace LLPredicate : mRule(value) {} - Rule(const Rule& other) - : mRule(other.mRule) - {} - Rule(const Value other) : mRule(other) {} @@ -185,17 +181,37 @@ namespace LLPredicate Rule() {} + void require(const Value value) + { + mRule.set(value, require); + } + + void allow(const Value value) + { + mRule.forget(value); + } + bool check(const Value value) const { - return !(mRule && value).noneSet(); + return (mRule && value).someSet(); + } + + bool requires(const Value value) const + { + return (mRule && value).someSet() && (!mRule && value).noneSet(); + } + + bool isAmbivalent(const Value value) const + { + return (mRule && value).someSet() && (!mRule && value).someSet(); } - bool isTriviallyTrue() const + bool acceptsAll() const { return mRule.allSet(); } - bool isTriviallyFalse() const + bool acceptsNone() const { return mRule.noneSet(); } diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index c10e1b1e20..345e30f4b4 100644 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -102,13 +102,13 @@ void LLParamSDParser::readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool //readSDValues(sd, block); } -void LLParamSDParser::writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules) +void LLParamSDParser::writeSDImpl(LLSD& sd, const LLInitParam::BaseBlock& block, const LLInitParam::predicate_rule_t rules, const LLInitParam::BaseBlock* diff_block) { mNameStack.clear(); mWriteRootSD = &sd; name_stack_t name_stack; - block.serializeBlock(*this, name_stack, rules); + block.serializeBlock(*this, name_stack, rules, diff_block); } /*virtual*/ std::string LLParamSDParser::getCurrentElementName() diff --git a/indra/llcommon/llsdparam.h b/indra/llcommon/llsdparam.h index 032e506fd8..1181c2d433 100644 --- a/indra/llcommon/llsdparam.h +++ b/indra/llcommon/llsdparam.h @@ -50,11 +50,28 @@ typedef LLInitParam::Parser parser_t; public: LLParamSDParser(); void readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool silent = false); - void writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules = LLInitParam::predicate_rule_t(LLInitParam::PROVIDED) && LLInitParam::NON_DEFAULT); + template + void writeSD(LLSD& sd, + const BLOCK& block, + const LLInitParam::predicate_rule_t rules = LLInitParam::default_parse_rules(), + const LLInitParam::BaseBlock* diff_block = NULL) + { + if (!diff_block + && !rules.isAmbivalent(LLInitParam::HAS_DEFAULT_VALUE)) + { + diff_block = &LLInitParam::defaultValue(); + } + writeSDImpl(sd, block, rules, diff_block); + } /*virtual*/ std::string getCurrentElementName(); private: + void writeSDImpl(LLSD& sd, + const LLInitParam::BaseBlock& block, + const LLInitParam::predicate_rule_t, + const LLInitParam::BaseBlock* diff_block); + void submit(LLInitParam::BaseBlock& block, const LLSD& sd, LLInitParam::Parser::name_stack_t& name_stack); template -- cgit v1.2.3 From 0007114cf5a60779319ab8cbd0a23a0d462b8010 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 5 Nov 2012 16:10:57 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct fixed copy behavior of recordings and accumulator buffers --- indra/llcommon/llinitparam.cpp | 2 +- indra/llcommon/llinitparam.h | 81 ++++++++-------------------- indra/llcommon/llpredicate.h | 90 +++++++++----------------------- indra/llcommon/lltrace.h | 15 +++--- indra/llcommon/lltracerecording.cpp | 3 +- indra/llcommon/lltracerecording.h | 29 ++++++++-- indra/llcommon/lltracethreadrecorder.cpp | 5 ++ 7 files changed, 88 insertions(+), 137 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index d20fc03227..32d4eec607 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -35,7 +35,7 @@ namespace LLInitParam predicate_rule_t default_parse_rules() { - return ll_make_predicate(PROVIDED) && !ll_make_predicate(EMPTY) && !ll_make_predicate(HAS_DEFAULT_VALUE); + return ll_make_predicate(PROVIDED) && !ll_make_predicate(EMPTY); } // diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index 6177cc7d12..3d4e4331c0 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -919,17 +919,8 @@ namespace LLInitParam predicate.set(HAS_DEFAULT_VALUE); } - if (typed_param.isValid()) - { - predicate.set(VALID, true); - predicate.set(PROVIDED, typed_param.anyProvided()); - } - else - { - predicate.set(VALID, false); - predicate.set(PROVIDED, false); - } - + predicate.set(VALID, typed_param.isValid()); + predicate.set(PROVIDED, typed_param.anyProvided()); predicate.set(EMPTY, false); if (!predicate_rule.check(predicate)) return false; @@ -1014,15 +1005,15 @@ namespace LLInitParam }; // parameter that is a block - template - class TypedParam + template + class TypedParam : public Param, - public ParamValue + public ParamValue { public: - typedef ParamValue param_value_t; + typedef ParamValue param_value_t; typedef typename param_value_t::value_assignment_t value_assignment_t; - typedef TypedParam self_t; + typedef TypedParam self_t; typedef NAME_VALUE_LOOKUP name_value_lookup_t; using param_value_t::operator(); @@ -1081,16 +1072,8 @@ namespace LLInitParam LLPredicate::Value predicate; - if (typed_param.isValid()) - { - predicate.set(VALID, true); - predicate.set(PROVIDED, typed_param.anyProvided()); - } - else - { - predicate.set(VALID, false); - predicate.set(PROVIDED, false); - } + predicate.set(VALID, typed_param.isValid()); + predicate.set(PROVIDED, typed_param.anyProvided()); if (!predicate_rule.check(predicate)) return false; @@ -1187,13 +1170,13 @@ namespace LLInitParam }; // container of non-block parameters - template - class TypedParam + template + class TypedParam : public Param { public: - typedef TypedParam self_t; - typedef ParamValue param_value_t; + typedef TypedParam self_t; + typedef ParamValue param_value_t; typedef typename std::vector container_t; typedef const container_t& value_assignment_t; @@ -1280,18 +1263,8 @@ namespace LLInitParam LLPredicate::Value predicate; predicate.set(REQUIRED, typed_param.mMinCount > 0); - - if (typed_param.isValid()) - { - predicate.set(VALID, true); - predicate.set(PROVIDED, typed_param.anyProvided()); - } - else - { - predicate.set(VALID, false); - predicate.set(PROVIDED, false); - } - + predicate.set(VALID, typed_param.isValid()); + predicate.set(PROVIDED, typed_param.anyProvided()); predicate.set(EMPTY, typed_param.mValues.empty()); if (!predicate_rule.check(predicate)) return false; @@ -1345,7 +1318,7 @@ namespace LLInitParam static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) { - parser.inspectValue(name_stack, min_count, max_count, NULL); + parser.inspectValue(name_stack, min_count, max_count, NULL); if (name_value_lookup_t::getPossibleValues()) { parser.inspectValue(name_stack, min_count, max_count, name_value_lookup_t::getPossibleValues()); @@ -1437,13 +1410,13 @@ namespace LLInitParam }; // container of block parameters - template - class TypedParam + template + class TypedParam : public Param { public: - typedef TypedParam self_t; - typedef ParamValue param_value_t; + typedef TypedParam self_t; + typedef ParamValue param_value_t; typedef typename std::vector container_t; typedef const container_t& value_assignment_t; typedef typename param_value_t::value_t value_t; @@ -1548,17 +1521,9 @@ namespace LLInitParam LLPredicate::Value predicate; predicate.set(REQUIRED, typed_param.mMinCount > 0); - - if (typed_param.isValid()) - { - predicate.set(VALID, true); - predicate.set(PROVIDED, typed_param.anyProvided()); - } - else - { - predicate.set(VALID, false); - predicate.set(PROVIDED, false); - } + predicate.set(VALID, typed_param.isValid()); + predicate.set(PROVIDED, typed_param.anyProvided()); + predicate.set(EMPTY, typed_param.mValues.empty()); if (!predicate_rule.check(predicate)) return false; diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 6c9e5fc145..a0e970a799 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -76,41 +76,31 @@ namespace LLPredicate void set(ENUM e, bool value = true) { llassert(0 <= e && e < cMaxEnum); - mPredicateFlags = modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value, mPredicateFlags); - } - - void set(const Value other, bool value) - { - predicate_flag_t predicate_flags_to_set = other.mPredicateFlags; - predicate_flag_t cumulative_flags = 0; - while(predicate_flags_to_set) - { - predicate_flag_t next_flags = clearLSB(predicate_flags_to_set); - predicate_flag_t lsb_flag = predicate_flags_to_set ^ next_flags; - - predicate_flag_t mask = 0; - predicate_flag_t cur_flags = mPredicateFlags; - for (S32 i = 0; i < cMaxEnum; i++) - { - if (cPredicateFlagsFromEnum[i] & lsb_flag) - { - mask |= cPredicateFlagsFromEnum[i]; - cur_flags = modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value, cur_flags); - } - } - - cumulative_flags |= modifyPredicate(lsb_flag, mask, value, cur_flags); - - predicate_flags_to_set = next_flags; + predicate_flag_t flags_to_modify; + predicate_flag_t mask = cPredicateFlagsFromEnum[e]; + if (value) + { // add predicate "e" to flags that don't contain it already + flags_to_modify = (mPredicateFlags & ~mask); + // clear flags not containing e + mPredicateFlags &= mask; + // add back flags shifted to contain e + mPredicateFlags |= flags_to_modify << (0x1 << e); + } + else + { // remove predicate "e" from flags that contain it + flags_to_modify = (mPredicateFlags & mask); + // clear flags containing e + mPredicateFlags &= ~mask; + // add back flags shifted to not contain e + mPredicateFlags |= flags_to_modify >> (0x1 << e); } - mPredicateFlags = cumulative_flags; } - void forget(const Value value) + void forget(ENUM e) { - set(value, true); + set(e, true); U32 flags_with_predicate = mPredicateFlags; - set(value, false); + set(e, false); // ambiguous value is result of adding and removing predicate at the same time! mPredicateFlags |= flags_with_predicate; } @@ -131,38 +121,6 @@ namespace LLPredicate } private: - - predicate_flag_t clearLSB(predicate_flag_t value) - { - return value & (value - 1); - } - - predicate_flag_t modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, predicate_flag_t value, bool set) - { - llassert(clearLSB(predicate_flag) == 0); - predicate_flag_t flags_to_modify; - - if (set) - { - flags_to_modify = (mPredicateFlags & ~mask); - // clear flags not containing predicate to be added - value &= mask; - // shift flags, in effect adding predicate - flags_to_modify *= predicate_flag; - } - else - { - flags_to_modify = mPredicateFlags & mask; - // clear flags containing predicate to be removed - value &= ~mask; - // shift flags, in effect removing predicate - flags_to_modify /= predicate_flag; - } - // put modified flags back - value |= flags_to_modify; - return value; - } - predicate_flag_t mPredicateFlags; }; @@ -181,14 +139,14 @@ namespace LLPredicate Rule() {} - void require(const Value value) + void require(ENUM e) { - mRule.set(value, require); + mRule.set(e, require); } - void allow(const Value value) + void allow(ENUM e) { - mRule.forget(value); + mRule.forget(e); } bool check(const Value value) const diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 735c45754c..8ad391e6e5 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -38,9 +38,9 @@ #include -#define TOKEN_PASTE_ACTUAL(x, y) x##y -#define TOKEN_PASTE(x, y) TOKEN_PASTE_ACTUAL(x, y) -#define RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); +#define LL_TOKEN_PASTE_ACTUAL(x, y) x##y +#define LL_TOKEN_PASTE(x, y) LL_TOKEN_PASTE_ACTUAL(x, y) +#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder LL_TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); namespace LLTrace { @@ -93,13 +93,16 @@ namespace LLTrace public: - // copying an accumulator buffer does not copy the actual contents, but simply initializes the buffer size - // to be identical to the other buffer AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) : mStorageSize(other.mStorageSize), mStorage(new ACCUMULATOR[other.mStorageSize]), mNextStorageSlot(other.mNextStorageSlot) - {} + { + for (S32 i = 0; i < mNextStorageSlot; i++) + { + mStorage[i] = other.mStorage[i]; + } + } ~AccumulatorBuffer() { diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index a8e1a5eec9..9cdd89c223 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -52,9 +52,8 @@ Recording::~Recording() void Recording::update() { if (isStarted()) -{ + { LLTrace::get_thread_recorder()->update(this); - mElapsedSeconds = 0.0; mSamplingTimer.reset(); } } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 3a786c1357..e994949150 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -53,16 +53,20 @@ public: void restart(); void reset(); - bool isStarted() { return mPlayState == STARTED; } - bool isPaused() { return mPlayState == PAUSED; } - bool isStopped() { return mPlayState == STOPPED; } - EPlayState getPlayState() { return mPlayState; } + bool isStarted() const { return mPlayState == STARTED; } + bool isPaused() const { return mPlayState == PAUSED; } + bool isStopped() const { return mPlayState == STOPPED; } + EPlayState getPlayState() const { return mPlayState; } protected: LLStopWatchControlsMixinCommon() : mPlayState(STOPPED) {} + // derived classes can call this from their constructor in order + // to enforce invariants + void forceState(EPlayState state) { mPlayState = state; } + private: // trigger data accumulation (without reset) virtual void handleStart() = 0; @@ -102,6 +106,23 @@ namespace LLTrace public: Recording(); + Recording(const Recording& other) + { + mSamplingTimer = other.mSamplingTimer; + mElapsedSeconds = other.mElapsedSeconds; + mCountsFloat = other.mCountsFloat; + mMeasurementsFloat = other.mMeasurementsFloat; + mCounts = other.mCounts; + mMeasurements = other.mMeasurements; + mStackTimers = other.mStackTimers; + + if (other.isStarted()) + { + handleStart(); + } + + forceState(other.getPlayState()); + } ~Recording(); void makePrimary(); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 0feb3ab7af..af66a69492 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -86,6 +86,11 @@ std::list::iterator ThreadRecorder::update( Rec } } + if (it == end_it) + { + llerrs << "Recording not active on this thread" << llendl; + } + return it; } -- cgit v1.2.3 From 860ff2f7e2a7fe932dfb7c148f0dbc0067018038 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 7 Nov 2012 00:38:21 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct fixed trace data gathering and routing from background thread simplified slave->master thread communication (eliminated redundant recording and proxy object) improved performance of fast timer data gathering (slow iterators) --- indra/llcommon/llapr.h | 3 +- indra/llcommon/llfasttimer.cpp | 8 +- indra/llcommon/llqueuedthread.cpp | 5 +- indra/llcommon/lltrace.h | 5 +- indra/llcommon/lltracerecording.cpp | 189 ++++++++++++++++++++++--------- indra/llcommon/lltracerecording.h | 112 +++++++++--------- indra/llcommon/lltracethreadrecorder.cpp | 19 ++-- indra/llcommon/lltracethreadrecorder.h | 11 +- 8 files changed, 219 insertions(+), 133 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 821274aeb3..510725ffc6 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -334,14 +334,13 @@ public: {} explicit LLThreadLocalPointer(T* value) - : LLThreadLocalPointerBase(&cleanup) { set(value); } LLThreadLocalPointer(const LLThreadLocalPointer& other) - : LLThreadLocalPointerBase(other, &cleanup) + : LLThreadLocalPointerBase(other) { set(other.get()); } diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 0abaf73063..4f67004773 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -319,7 +319,7 @@ void LLFastTimer::NamedTimer::buildHierarchy() // set up initial tree { - for (instance_iter it = beginInstances(); it != endInstances(); ++it) + for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { NamedTimer& timer = *it; if (&timer == NamedTimerFactory::instance().getRootTimer()) continue; @@ -449,7 +449,7 @@ void LLFastTimer::NamedTimer::resetFrame() LLSD sd; { - for (instance_iter it = beginInstances(); it != endInstances(); ++it) + for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { NamedTimer& timer = *it; FrameState& info = timer.getFrameState(); @@ -472,7 +472,7 @@ void LLFastTimer::NamedTimer::resetFrame() } // reset for next frame - for (instance_iter it = beginInstances(); it != endInstances(); ++it) + for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { NamedTimer& timer = *it; @@ -512,7 +512,7 @@ void LLFastTimer::NamedTimer::reset() // reset all history { - for (instance_iter it = beginInstances(); it != endInstances(); ++it) + for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { NamedTimer& timer = *it; if (&timer != NamedTimerFactory::instance().getRootTimer()) diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp index 218f6dbcd0..956642e97a 100644 --- a/indra/llcommon/llqueuedthread.cpp +++ b/indra/llcommon/llqueuedthread.cpp @@ -112,8 +112,6 @@ void LLQueuedThread::shutdown() // virtual S32 LLQueuedThread::update(F32 max_time_ms) { - LLTrace::get_thread_recorder()->pushToMaster(); - if (!mStarted) { if (!mThreaded) @@ -511,6 +509,9 @@ void LLQueuedThread::run() threadedUpdate(); int res = processNextRequest(); + + LLTrace::get_thread_recorder()->pushToMaster(); + if (res == 0) { mIdleThread = TRUE; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 8ad391e6e5..e2530a8a24 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -220,8 +220,7 @@ namespace LLTrace return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; } - ACCUMULATOR& getAccumulator(AccumulatorBuffer* buffer) { return (*buffer)[mAccumulatorIndex]; } - const ACCUMULATOR& getAccumulator(const AccumulatorBuffer* buffer) const { return (*buffer)[mAccumulatorIndex]; } + size_t getIndex() const { return mAccumulatorIndex; } protected: std::string mName; @@ -396,6 +395,8 @@ namespace LLTrace T getSum() const { return (T)mSum; } + U32 getSampleCount() const { return mNumSamples; } + private: T mSum; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 9cdd89c223..435c49106f 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -117,29 +117,29 @@ void Recording::appendRecording( const Recording& other ) F64 Recording::getSum( const TraceType >& stat ) const { - return stat.getAccumulator(mCountsFloat).getSum(); + return (*mCountsFloat)[stat.getIndex()].getSum(); } S64 Recording::getSum( const TraceType >& stat ) const { - return stat.getAccumulator(mCounts).getSum(); + return (*mCounts)[stat.getIndex()].getSum(); } F64 Recording::getSum( const TraceType >& stat ) const { - return (F64)stat.getAccumulator(mMeasurementsFloat).getSum(); + return (F64)(*mMeasurementsFloat)[stat.getIndex()].getSum(); } S64 Recording::getSum( const TraceType >& stat ) const { - return (S64)stat.getAccumulator(mMeasurements).getSum(); + return (S64)(*mMeasurements)[stat.getIndex()].getSum(); } F64 Recording::getPerSec( const TraceType >& stat ) const { - F64 sum = stat.getAccumulator(mCountsFloat).getSum(); + F64 sum = (*mCountsFloat)[stat.getIndex()].getSum(); return (sum != 0.0) ? (sum / mElapsedSeconds) : 0.0; @@ -147,15 +147,26 @@ F64 Recording::getPerSec( const TraceType >& stat ) const F64 Recording::getPerSec( const TraceType >& stat ) const { - S64 sum = stat.getAccumulator(mCounts).getSum(); + S64 sum = (*mCounts)[stat.getIndex()].getSum(); return (sum != 0) ? ((F64)sum / mElapsedSeconds) : 0.0; } +U32 Recording::getSampleCount( const TraceType >& stat ) const +{ + return (*mCountsFloat)[stat.getIndex()].getSampleCount(); +} + +U32 Recording::getSampleCount( const TraceType >& stat ) const +{ + return (*mMeasurementsFloat)[stat.getIndex()].getSampleCount(); +} + + F64 Recording::getPerSec( const TraceType >& stat ) const { - F64 sum = stat.getAccumulator(mMeasurementsFloat).getSum(); + F64 sum = (*mMeasurementsFloat)[stat.getIndex()].getSum(); return (sum != 0.0) ? (sum / mElapsedSeconds) : 0.0; @@ -163,7 +174,7 @@ F64 Recording::getPerSec( const TraceType >& stat ) F64 Recording::getPerSec( const TraceType >& stat ) const { - S64 sum = stat.getAccumulator(mMeasurements).getSum(); + S64 sum = (*mMeasurements)[stat.getIndex()].getSum(); return (sum != 0) ? ((F64)sum / mElapsedSeconds) : 0.0; @@ -171,62 +182,62 @@ F64 Recording::getPerSec( const TraceType >& stat ) F64 Recording::getMin( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getMin(); + return (*mMeasurementsFloat)[stat.getIndex()].getMin(); } S64 Recording::getMin( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getMin(); + return (*mMeasurements)[stat.getIndex()].getMin(); } F64 Recording::getMax( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getMax(); + return (*mMeasurementsFloat)[stat.getIndex()].getMax(); } S64 Recording::getMax( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getMax(); + return (*mMeasurements)[stat.getIndex()].getMax(); } F64 Recording::getMean( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getMean(); + return (*mMeasurementsFloat)[stat.getIndex()].getMean(); } F64 Recording::getMean( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getMean(); + return (*mMeasurements)[stat.getIndex()].getMean(); } F64 Recording::getStandardDeviation( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getStandardDeviation(); + return (*mMeasurementsFloat)[stat.getIndex()].getStandardDeviation(); } F64 Recording::getStandardDeviation( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getStandardDeviation(); + return (*mMeasurements)[stat.getIndex()].getStandardDeviation(); } F64 Recording::getLastValue( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getLastValue(); + return (*mMeasurementsFloat)[stat.getIndex()].getLastValue(); } S64 Recording::getLastValue( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getLastValue(); + return (*mMeasurements)[stat.getIndex()].getLastValue(); } U32 Recording::getSampleCount( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurementsFloat).getSampleCount(); + return (*mMeasurementsFloat)[stat.getIndex()].getSampleCount(); } U32 Recording::getSampleCount( const TraceType >& stat ) const { - return stat.getAccumulator(mMeasurements).getSampleCount(); + return (*mMeasurements)[stat.getIndex()].getSampleCount(); } @@ -235,13 +246,14 @@ U32 Recording::getSampleCount( const TraceType >& st // PeriodicRecording /////////////////////////////////////////////////////////////////////// -PeriodicRecording::PeriodicRecording( S32 num_periods ) +PeriodicRecording::PeriodicRecording( S32 num_periods, EStopWatchState state) : mNumPeriods(num_periods), mCurPeriod(0), mTotalValid(false), mRecordingPeriods( new Recording[num_periods]) { llassert(mNumPeriods > 0); + initTo(state); } PeriodicRecording::~PeriodicRecording() @@ -252,7 +264,7 @@ PeriodicRecording::~PeriodicRecording() void PeriodicRecording::nextPeriod() { - EPlayState play_state = getPlayState(); + EStopWatchState play_state = getPlayState(); Recording& old_recording = getCurRecordingPeriod(); mCurPeriod = (mCurPeriod + 1) % mNumPeriods; old_recording.splitTo(getCurRecordingPeriod()); @@ -286,24 +298,44 @@ Recording& PeriodicRecording::getTotalRecording() return mTotalRecording; } -void PeriodicRecording::handleStart() +void PeriodicRecording::start() +{ + getCurRecordingPeriod().start(); +} + +void PeriodicRecording::stop() +{ + getCurRecordingPeriod().stop(); +} + +void PeriodicRecording::pause() { - getCurRecordingPeriod().handleStart(); + getCurRecordingPeriod().pause(); } -void PeriodicRecording::handleStop() +void PeriodicRecording::resume() { - getCurRecordingPeriod().handleStop(); + getCurRecordingPeriod().resume(); } -void PeriodicRecording::handleReset() +void PeriodicRecording::restart() { - getCurRecordingPeriod().handleReset(); + getCurRecordingPeriod().restart(); } -void PeriodicRecording::handleSplitTo( PeriodicRecording& other ) +void PeriodicRecording::reset() { - getCurRecordingPeriod().handleSplitTo(other.getCurRecordingPeriod()); + getCurRecordingPeriod().reset(); +} + +void PeriodicRecording::splitTo(PeriodicRecording& other) +{ + getCurRecordingPeriod().splitTo(other.getCurRecordingPeriod()); +} + +void PeriodicRecording::splitFrom(PeriodicRecording& other) +{ + getCurRecordingPeriod().splitFrom(other.getCurRecordingPeriod()); } @@ -317,38 +349,59 @@ void ExtendableRecording::extend() mPotentialRecording.reset(); } -void ExtendableRecording::handleStart() +void ExtendableRecording::start() { - mPotentialRecording.handleStart(); + mPotentialRecording.start(); } -void ExtendableRecording::handleStop() +void ExtendableRecording::stop() { - mPotentialRecording.handleStop(); + mPotentialRecording.stop(); } -void ExtendableRecording::handleReset() +void ExtendableRecording::pause() { - mAcceptedRecording.handleReset(); - mPotentialRecording.handleReset(); + mPotentialRecording.pause(); } -void ExtendableRecording::handleSplitTo( ExtendableRecording& other ) +void ExtendableRecording::resume() { - mPotentialRecording.handleSplitTo(other.mPotentialRecording); + mPotentialRecording.resume(); +} + +void ExtendableRecording::restart() +{ + mAcceptedRecording.reset(); + mPotentialRecording.restart(); +} + +void ExtendableRecording::reset() +{ + mAcceptedRecording.reset(); + mPotentialRecording.reset(); +} + +void ExtendableRecording::splitTo(ExtendableRecording& other) +{ + mPotentialRecording.splitTo(other.mPotentialRecording); +} + +void ExtendableRecording::splitFrom(ExtendableRecording& other) +{ + mPotentialRecording.splitFrom(other.mPotentialRecording); } PeriodicRecording& get_frame_recording() { - static PeriodicRecording sRecording(64); - return sRecording; + static LLThreadLocalPointer sRecording(new PeriodicRecording(64, PeriodicRecording::STARTED)); + return *sRecording; } } void LLStopWatchControlsMixinCommon::start() { - switch (mPlayState) + switch (mState) { case STOPPED: handleReset(); @@ -360,13 +413,16 @@ void LLStopWatchControlsMixinCommon::start() case STARTED: handleReset(); break; + default: + llassert(false); + break; } - mPlayState = STARTED; + mState = STARTED; } void LLStopWatchControlsMixinCommon::stop() { - switch (mPlayState) + switch (mState) { case STOPPED: break; @@ -376,13 +432,16 @@ void LLStopWatchControlsMixinCommon::stop() case STARTED: handleStop(); break; + default: + llassert(false); + break; } - mPlayState = STOPPED; + mState = STOPPED; } void LLStopWatchControlsMixinCommon::pause() { - switch (mPlayState) + switch (mState) { case STOPPED: break; @@ -391,13 +450,16 @@ void LLStopWatchControlsMixinCommon::pause() case STARTED: handleStop(); break; + default: + llassert(false); + break; } - mPlayState = PAUSED; + mState = PAUSED; } void LLStopWatchControlsMixinCommon::resume() { - switch (mPlayState) + switch (mState) { case STOPPED: handleStart(); @@ -407,13 +469,16 @@ void LLStopWatchControlsMixinCommon::resume() break; case STARTED: break; + default: + llassert(false); + break; } - mPlayState = STARTED; + mState = STARTED; } void LLStopWatchControlsMixinCommon::restart() { - switch (mPlayState) + switch (mState) { case STOPPED: handleReset(); @@ -426,11 +491,33 @@ void LLStopWatchControlsMixinCommon::restart() case STARTED: handleReset(); break; + default: + llassert(false); + break; } - mPlayState = STARTED; + mState = STARTED; } void LLStopWatchControlsMixinCommon::reset() { handleReset(); } + +void LLStopWatchControlsMixinCommon::initTo( EStopWatchState state ) +{ + switch(state) + { + case STOPPED: + break; + case PAUSED: + break; + case STARTED: + handleStart(); + break; + default: + llassert(false); + break; + } + + mState = state; +} diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index e994949150..31901b599c 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -39,43 +39,42 @@ class LL_COMMON_API LLStopWatchControlsMixinCommon public: virtual ~LLStopWatchControlsMixinCommon() {} - enum EPlayState + enum EStopWatchState { STOPPED, PAUSED, STARTED }; - void start(); - void stop(); - void pause(); - void resume(); - void restart(); - void reset(); + virtual void start(); + virtual void stop(); + virtual void pause(); + virtual void resume(); + virtual void restart(); + virtual void reset(); - bool isStarted() const { return mPlayState == STARTED; } - bool isPaused() const { return mPlayState == PAUSED; } - bool isStopped() const { return mPlayState == STOPPED; } - EPlayState getPlayState() const { return mPlayState; } + bool isStarted() const { return mState == STARTED; } + bool isPaused() const { return mState == PAUSED; } + bool isStopped() const { return mState == STOPPED; } + EStopWatchState getPlayState() const { return mState; } protected: LLStopWatchControlsMixinCommon() - : mPlayState(STOPPED) + : mState(STOPPED) {} - // derived classes can call this from their constructor in order - // to enforce invariants - void forceState(EPlayState state) { mPlayState = state; } - + // derived classes can call this from their copy constructor in order + // to duplicate play state of source + void initTo(EStopWatchState state); private: - // trigger data accumulation (without reset) - virtual void handleStart() = 0; - // stop data accumulation, should put object in queryable state - virtual void handleStop() = 0; - // clear accumulated values, can be called while started - virtual void handleReset() = 0; - - EPlayState mPlayState; + // trigger active behavior (without reset) + virtual void handleStart(){}; + // stop active behavior + virtual void handleStop(){}; + // clear accumulated state, can be called while started + virtual void handleReset(){}; + + EStopWatchState mState; }; template @@ -83,19 +82,20 @@ class LLStopWatchControlsMixin : public LLStopWatchControlsMixinCommon { public: - void splitTo(DERIVED& other) + typedef LLStopWatchControlsMixin self_t; + virtual void splitTo(DERIVED& other) { handleSplitTo(other); } - void splitFrom(DERIVED& other) + virtual void splitFrom(DERIVED& other) { - other.handleSplitTo(*this); + static_cast(other).handleSplitTo(*static_cast(this)); } private: // atomically stop this object while starting the other // no data can be missed in between stop and start - virtual void handleSplitTo(DERIVED& other) = 0; + virtual void handleSplitTo(DERIVED& other) {}; }; @@ -108,20 +108,20 @@ namespace LLTrace Recording(const Recording& other) { - mSamplingTimer = other.mSamplingTimer; - mElapsedSeconds = other.mElapsedSeconds; - mCountsFloat = other.mCountsFloat; + mSamplingTimer = other.mSamplingTimer; + mElapsedSeconds = other.mElapsedSeconds; + mCountsFloat = other.mCountsFloat; mMeasurementsFloat = other.mMeasurementsFloat; - mCounts = other.mCounts; - mMeasurements = other.mMeasurements; - mStackTimers = other.mStackTimers; + mCounts = other.mCounts; + mMeasurements = other.mMeasurements; + mStackTimers = other.mStackTimers; + LLStopWatchControlsMixin::initTo(other.getPlayState()); if (other.isStarted()) { handleStart(); } - forceState(other.getPlayState()); } ~Recording(); @@ -149,6 +149,10 @@ namespace LLTrace return (T)getPerSec(static_cast::type_t> >&> (stat)); } + U32 getSampleCount(const TraceType >& stat) const; + U32 getSampleCount(const TraceType >& stat) const; + + // Measurement accessors F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; @@ -211,14 +215,15 @@ namespace LLTrace LLUnit::Seconds getDuration() const { return mElapsedSeconds; } + private: + friend class ThreadRecorder; + // implementation for LLStopWatchControlsMixin /*virtual*/ void handleStart(); /*virtual*/ void handleStop(); /*virtual*/ void handleReset(); /*virtual*/ void handleSplitTo(Recording& other); - private: - friend class ThreadRecorder; // returns data for current thread class ThreadRecorder* getThreadRecorder(); @@ -236,7 +241,7 @@ namespace LLTrace : public LLStopWatchControlsMixin { public: - PeriodicRecording(S32 num_periods); + PeriodicRecording(S32 num_periods, EStopWatchState state = STOPPED); ~PeriodicRecording(); void nextPeriod(); @@ -359,15 +364,17 @@ namespace LLTrace return mean; } - private: - // implementation for LLStopWatchControlsMixin - /*virtual*/ void handleStart(); - /*virtual*/ void handleStop(); - /*virtual*/ void handleReset(); - - /*virtual*/ void handleSplitTo(PeriodicRecording& other); + /*virtual*/ void start(); + /*virtual*/ void stop(); + /*virtual*/ void pause(); + /*virtual*/ void resume(); + /*virtual*/ void restart(); + /*virtual*/ void reset(); + /*virtual*/ void splitTo(PeriodicRecording& other); + /*virtual*/ void splitFrom(PeriodicRecording& other); + private: Recording* mRecordingPeriods; Recording mTotalRecording; bool mTotalValid; @@ -382,13 +389,16 @@ namespace LLTrace { void extend(); - private: // implementation for LLStopWatchControlsMixin - /*virtual*/ void handleStart(); - /*virtual*/ void handleStop(); - /*virtual*/ void handleReset(); - /*virtual*/ void handleSplitTo(ExtendableRecording& other); - + /*virtual*/ void start(); + /*virtual*/ void stop(); + /*virtual*/ void pause(); + /*virtual*/ void resume(); + /*virtual*/ void restart(); + /*virtual*/ void reset(); + /*virtual*/ void splitTo(ExtendableRecording& other); + /*virtual*/ void splitFrom(ExtendableRecording& other); + private: Recording mAcceptedRecording; Recording mPotentialRecording; }; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index af66a69492..5a6ff14f97 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -171,15 +171,20 @@ void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) // MasterThreadRecorder /////////////////////////////////////////////////////////////////////// +LLFastTimer::DeclareTimer FTM_PULL_TRACE_DATA_FROM_SLAVES("Pull slave trace data"); void MasterThreadRecorder::pullFromSlaveThreads() { + LLFastTimer _(FTM_PULL_TRACE_DATA_FROM_SLAVES); + if (mActiveRecordings.empty()) return; + LLMutexLock lock(&mSlaveListMutex); + Recording& target_recording = mActiveRecordings.front().mBaseline; for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) { - (*it)->mRecorder->mSharedData.copyTo((*it)->mSlaveRecording); + (*it)->mSharedData.copyTo(target_recording); } } @@ -187,7 +192,7 @@ void MasterThreadRecorder::addSlaveThread( class SlaveThreadRecorder* child ) { LLMutexLock lock(&mSlaveListMutex); - mSlaveThreadRecorders.push_back(new SlaveThreadRecorderProxy(child)); + mSlaveThreadRecorders.push_back(child); } void MasterThreadRecorder::removeSlaveThread( class SlaveThreadRecorder* child ) @@ -198,7 +203,7 @@ void MasterThreadRecorder::removeSlaveThread( class SlaveThreadRecorder* child ) it != end_it; ++it) { - if ((*it)->mRecorder == child) + if ((*it) == child) { mSlaveThreadRecorders.erase(it); break; @@ -212,12 +217,4 @@ void MasterThreadRecorder::pushToMaster() MasterThreadRecorder::MasterThreadRecorder() {} -/////////////////////////////////////////////////////////////////////// -// MasterThreadRecorder::SlaveThreadTraceProxy -/////////////////////////////////////////////////////////////////////// - -MasterThreadRecorder::SlaveThreadRecorderProxy::SlaveThreadRecorderProxy( class SlaveThreadRecorder* recorder) -: mRecorder(recorder) -{} - } diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index c9231265af..44fe67384b 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -81,17 +81,8 @@ namespace LLTrace LLMutex* getSlaveListMutex() { return &mSlaveListMutex; } private: - struct SlaveThreadRecorderProxy - { - SlaveThreadRecorderProxy(class SlaveThreadRecorder* recorder); - class SlaveThreadRecorder* mRecorder; - Recording mSlaveRecording; - private: - //no need to copy these and then have to duplicate the storage - SlaveThreadRecorderProxy(const SlaveThreadRecorderProxy& other) {} - }; - typedef std::list slave_thread_recorder_list_t; + typedef std::list slave_thread_recorder_list_t; slave_thread_recorder_list_t mSlaveThreadRecorders; LLMutex mSlaveListMutex; -- cgit v1.2.3 From 9d70448a1275b80a829e16b6d08d29919748c823 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 7 Nov 2012 00:43:56 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct removed explicit constructor of LLUnit from integral types, as C++ already guarantees that I can't convert from LLUnit to LLUnits (requires 2 user defined conversions). Now this allows seamless replacement of existing integral types with Unit labeled types. --- indra/llcommon/llunit.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index e778383959..98e4de32fa 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -41,7 +41,7 @@ struct LLUnitType : public BASE_UNIT LLUnitType() {} - explicit LLUnitType(storage_t value) + LLUnitType(storage_t value) : BASE_UNIT(convertToBase(value)) {} @@ -86,7 +86,7 @@ struct LLUnitType : mBaseValue() {} - explicit LLUnitType(storage_t value) + LLUnitType(storage_t value) : mBaseValue(value) {} -- cgit v1.2.3 From ed17c181dd37f56b808838748d289ee7bb5567ec Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 7 Nov 2012 15:32:12 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct further fixes to implicit conversion of unit types --- indra/llcommon/lldate.cpp | 11 +-- indra/llcommon/lldate.h | 3 +- indra/llcommon/lltimer.cpp | 15 ++-- indra/llcommon/lltimer.h | 21 +++--- indra/llcommon/lltracerecording.cpp | 19 +++++ indra/llcommon/lltracerecording.h | 18 +---- indra/llcommon/llunit.h | 141 +++++++++--------------------------- 7 files changed, 80 insertions(+), 148 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp index 030ef6a3c7..d8b3dfe6c6 100644 --- a/indra/llcommon/lldate.cpp +++ b/indra/llcommon/lldate.cpp @@ -48,18 +48,15 @@ static const F64 LL_APR_USEC_PER_SEC = 1000000.0; LLDate::LLDate() : mSecondsSinceEpoch(DATE_EPOCH) -{ -} +{} LLDate::LLDate(const LLDate& date) : mSecondsSinceEpoch(date.mSecondsSinceEpoch) -{ -} +{} -LLDate::LLDate(F64 seconds_since_epoch) : +LLDate::LLDate(LLUnit::Seconds seconds_since_epoch) : mSecondsSinceEpoch(seconds_since_epoch) -{ -} +{} LLDate::LLDate(const std::string& iso8601_date) { diff --git a/indra/llcommon/lldate.h b/indra/llcommon/lldate.h index 7ff8b550ad..0500b1dcd8 100644 --- a/indra/llcommon/lldate.h +++ b/indra/llcommon/lldate.h @@ -33,6 +33,7 @@ #include #include "stdtypes.h" +#include "llunit.h" /** * @class LLDate @@ -58,7 +59,7 @@ public: * * @pararm seconds_since_epoch The number of seconds since UTC epoch. */ - LLDate(F64 seconds_since_epoch); + LLDate(LLUnit::Seconds seconds_since_epoch); /** * @brief Construct a date from a string representation diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 9ebc6de7f4..05f6b789e4 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -287,14 +287,15 @@ LLTimer::~LLTimer() } // static -U64 LLTimer::getTotalTime() +LLUnit::Microseconds LLTimer::getTotalTime() { + LLUnit::Seconds sec = LLUnit::Milliseconds(2000) + LLUnit::Hours(1.f / 360.f); // simply call into the implementation function. return totalTime(); } // static -F64 LLTimer::getTotalSeconds() +LLUnit::Seconds LLTimer::getTotalSeconds() { return U64_to_F64(getTotalTime()) * USEC_TO_SEC_F64; } @@ -343,23 +344,23 @@ U64 getElapsedTimeAndUpdate(U64& lastClockCount) } -F64 LLTimer::getElapsedTimeF64() const +LLUnit::Seconds LLTimer::getElapsedTimeF64() const { U64 last = mLastClockCount; return (F64)getElapsedTimeAndUpdate(last) * gClockFrequencyInv; } -F32 LLTimer::getElapsedTimeF32() const +LLUnit::Seconds LLTimer::getElapsedTimeF32() const { return (F32)getElapsedTimeF64(); } -F64 LLTimer::getElapsedTimeAndResetF64() +LLUnit::Seconds LLTimer::getElapsedTimeAndResetF64() { return (F64)getElapsedTimeAndUpdate(mLastClockCount) * gClockFrequencyInv; } -F32 LLTimer::getElapsedTimeAndResetF32() +LLUnit::Seconds LLTimer::getElapsedTimeAndResetF32() { return (F32)getElapsedTimeAndResetF64(); } @@ -372,7 +373,7 @@ void LLTimer::setTimerExpirySec(F32 expiration) + (U64)((F32)(expiration * gClockFrequency)); } -F32 LLTimer::getRemainingTimeF32() const +LLUnit::Seconds LLTimer::getRemainingTimeF32() const { U64 cur_ticks = get_clock_count(); if (cur_ticks > mExpirationTicks) diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index 513de0605d..e0a880a346 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -37,6 +37,7 @@ #include #include // units conversions +#include "llunit.h" #ifndef USEC_PER_SEC const U32 USEC_PER_SEC = 1000000; #endif @@ -55,7 +56,7 @@ public: protected: U64 mLastClockCount; U64 mExpirationTicks; - BOOL mStarted; + bool mStarted; public: LLTimer(); @@ -66,16 +67,16 @@ public: // Return a high precision number of seconds since the start of // this application instance. - static F64 getElapsedSeconds() + static LLUnit::Seconds getElapsedSeconds() { return sTimer->getElapsedTimeF64(); } // Return a high precision usec since epoch - static U64 getTotalTime(); + static LLUnit::Microseconds getTotalTime(); // Return a high precision seconds since epoch - static F64 getTotalSeconds(); + static LLUnit::Seconds getTotalSeconds(); // MANIPULATORS @@ -86,18 +87,18 @@ public: void setTimerExpirySec(F32 expiration); BOOL checkExpirationAndReset(F32 expiration); BOOL hasExpired() const; - F32 getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset - F64 getElapsedTimeAndResetF64(); + LLUnit::Seconds getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset + LLUnit::Seconds getElapsedTimeAndResetF64(); - F32 getRemainingTimeF32() const; + LLUnit::Seconds getRemainingTimeF32() const; static BOOL knownBadTimer(); // ACCESSORS - F32 getElapsedTimeF32() const; // Returns elapsed time in seconds - F64 getElapsedTimeF64() const; // Returns elapsed time in seconds + LLUnit::Seconds getElapsedTimeF32() const; // Returns elapsed time in seconds + LLUnit::Seconds getElapsedTimeF64() const; // Returns elapsed time in seconds - BOOL getStarted() const { return mStarted; } + bool getStarted() const { return mStarted; } static U64 getCurrentClockCount(); // Returns the raw clockticks diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 435c49106f..4252ed57dc 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -46,6 +46,25 @@ Recording::Recording() mStackTimers(new AccumulatorBuffer()) {} +Recording::Recording( const Recording& other ) +{ + llassert(other.mCountsFloat.get() != NULL); + mSamplingTimer = other.mSamplingTimer; + mElapsedSeconds = other.mElapsedSeconds; + mCountsFloat = other.mCountsFloat; + mMeasurementsFloat = other.mMeasurementsFloat; + mCounts = other.mCounts; + mMeasurements = other.mMeasurements; + mStackTimers = other.mStackTimers; + + LLStopWatchControlsMixin::initTo(other.getPlayState()); + if (other.isStarted()) + { + handleStart(); + } +} + + Recording::~Recording() {} diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 31901b599c..fc96631ce0 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -106,23 +106,7 @@ namespace LLTrace public: Recording(); - Recording(const Recording& other) - { - mSamplingTimer = other.mSamplingTimer; - mElapsedSeconds = other.mElapsedSeconds; - mCountsFloat = other.mCountsFloat; - mMeasurementsFloat = other.mMeasurementsFloat; - mCounts = other.mCounts; - mMeasurements = other.mMeasurements; - mStackTimers = other.mStackTimers; - - LLStopWatchControlsMixin::initTo(other.getPlayState()); - if (other.isStarted()) - { - handleStart(); - } - - } + Recording(const Recording& other); ~Recording(); void makePrimary(); diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 98e4de32fa..4519905707 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -51,6 +51,11 @@ struct LLUnitType : public BASE_UNIT return static_cast(*this); } + operator storage_t () const + { + return value(); + } + storage_t value() const { return convertToDerived(mBaseValue); @@ -102,6 +107,11 @@ struct LLUnitType return static_cast(*this); } + operator storage_t () const + { + return value(); + } + storage_t value() const { return mBaseValue; } template @@ -110,7 +120,6 @@ struct LLUnitType return CONVERTED_TYPE(*this).value(); } - static storage_t convertToBase(storage_t derived_value) { return (storage_t)derived_value; @@ -150,99 +159,77 @@ protected: storage_t mBaseValue; }; -// -// operator + -// template -DERIVED_UNIT operator + (typename LLUnitType::storage_t first, LLUnitType second) +struct LLUnitTypeWrapper +: public LLUnitType { - return DERIVED_UNIT(first + second.value()); -} + typedef LLUnitType unit_t; + LLUnitTypeWrapper(const unit_t& other) + : unit_t(other) + {} +}; -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) +// +// operator + +// +template +DERIVED_UNIT operator + (typename LLUnitType::storage_t first, LLUnitType second) { - return DERIVED_UNIT(first.value() + second.value()); + return DERIVED_UNIT(first + LLUnitType(second).value()); } + // // operator - // -template +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()); + return DERIVED_UNIT(first - LLUnitType(second).value()); } // // operator * // template -DERIVED_UNIT operator * (typename LLUnitType::storage_t first, LLUnitType second) +DERIVED_UNIT operator * (STORAGE_TYPE first, LLUnitType second) { return DERIVED_UNIT(first * second.value()); } template -DERIVED_UNIT operator * (LLUnitType first, typename LLUnitType::storage_t second) +DERIVED_UNIT operator * (LLUnitType first, STORAGE_TYPE second) { return DERIVED_UNIT(first.value() * second); } + // // operator / // template -DERIVED_UNIT operator / (typename LLUnitType::storage_t first, LLUnitType second) +DERIVED_UNIT operator / (STORAGE_TYPE first, LLUnitTypeWrapper second) { - return DERIVED_UNIT(first * second.value()); + return DERIVED_UNIT(first / second.value()); } template -DERIVED_UNIT operator / (LLUnitType first, typename LLUnitType::storage_t second) +DERIVED_UNIT operator / (LLUnitTypeWrapper first, STORAGE_TYPE second) { - return DERIVED_UNIT(first.value() * second); + return DERIVED_UNIT(first.value() / second); } // // operator < // -template +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 <= // @@ -252,17 +239,6 @@ bool operator <= (typename LLUnitType::st 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 > @@ -273,17 +249,6 @@ bool operator > (typename LLUnitType::sto 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 >= // @@ -293,18 +258,6 @@ bool operator >= (typename LLUnitType::st 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 == // @@ -314,18 +267,6 @@ bool operator == (typename LLUnitType::st 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 != // @@ -335,18 +276,6 @@ bool operator != (typename LLUnitType::st 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 > \ -- cgit v1.2.3 From 0bb0bd514b235948c1a21c81ab0e8ab6223b1990 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 8 Nov 2012 23:42:18 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct Finished making LLUnit implicitly convertible to/from scalar integer values cleaned up test code --- indra/llcommon/lldate.cpp | 4 +- indra/llcommon/lldate.h | 4 +- indra/llcommon/lldefs.h | 3 + indra/llcommon/llerrorlegacy.h | 7 + indra/llcommon/lltimer.cpp | 15 +- indra/llcommon/lltimer.h | 16 +- indra/llcommon/lltrace.h | 54 +++-- indra/llcommon/lltracerecording.h | 2 +- indra/llcommon/llunit.h | 404 +++++++++++++++++--------------------- 9 files changed, 239 insertions(+), 270 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp index d8b3dfe6c6..5569b4102d 100644 --- a/indra/llcommon/lldate.cpp +++ b/indra/llcommon/lldate.cpp @@ -54,8 +54,8 @@ LLDate::LLDate(const LLDate& date) : mSecondsSinceEpoch(date.mSecondsSinceEpoch) {} -LLDate::LLDate(LLUnit::Seconds seconds_since_epoch) : - mSecondsSinceEpoch(seconds_since_epoch) +LLDate::LLDate(LLUnit seconds_since_epoch) : + mSecondsSinceEpoch(seconds_since_epoch.value()) {} LLDate::LLDate(const std::string& iso8601_date) diff --git a/indra/llcommon/lldate.h b/indra/llcommon/lldate.h index 0500b1dcd8..b62a846147 100644 --- a/indra/llcommon/lldate.h +++ b/indra/llcommon/lldate.h @@ -57,9 +57,9 @@ public: /** * @brief Construct a date from a seconds since epoch value. * - * @pararm seconds_since_epoch The number of seconds since UTC epoch. + * @param seconds_since_epoch The number of seconds since UTC epoch. */ - LLDate(LLUnit::Seconds seconds_since_epoch); + LLDate(LLUnit seconds_since_epoch); /** * @brief Construct a date from a string representation diff --git a/indra/llcommon/lldefs.h b/indra/llcommon/lldefs.h index 5a4b8325f4..d57b9dccff 100644 --- a/indra/llcommon/lldefs.h +++ b/indra/llcommon/lldefs.h @@ -244,5 +244,8 @@ inline void llswap(LLDATATYPE& lhs, LLDATATYPE& rhs) rhs = tmp; } +#define LL_GLUE_IMPL(x, y) x##y +#define LL_GLUE_TOKENS(x, y) LL_GLUE_IMPL(x, y) + #endif // LL_LLDEFS_H diff --git a/indra/llcommon/llerrorlegacy.h b/indra/llcommon/llerrorlegacy.h index 37cee579cd..58cc2899af 100644 --- a/indra/llcommon/llerrorlegacy.h +++ b/indra/llcommon/llerrorlegacy.h @@ -29,6 +29,7 @@ #define LL_LLERRORLEGACY_H #include "llpreprocessor.h" +#include /* LEGACY -- DO NOT USE THIS STUFF ANYMORE @@ -111,6 +112,12 @@ const int LL_ERR_PRICE_MISMATCH = -23018; #define llverify(func) do {if (func) {}} while(0) #endif +#ifdef LL_WINDOWS +#define llstatic_assert(func, msg) static_assert(func, msg) +#else +#define llstatic_assert(func, msg) BOOST_STATIC_ASSERT(func) +#endif + // handy compile-time assert - enforce those template parameters! #define cassert(expn) typedef char __C_ASSERT__[(expn)?1:-1] /* Flawfinder: ignore */ //XXX: used in two places in llcommon/llskipmap.h diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 05f6b789e4..23cebf4336 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -287,15 +287,14 @@ LLTimer::~LLTimer() } // static -LLUnit::Microseconds LLTimer::getTotalTime() +LLUnit LLTimer::getTotalTime() { - LLUnit::Seconds sec = LLUnit::Milliseconds(2000) + LLUnit::Hours(1.f / 360.f); // simply call into the implementation function. return totalTime(); } // static -LLUnit::Seconds LLTimer::getTotalSeconds() +LLUnit LLTimer::getTotalSeconds() { return U64_to_F64(getTotalTime()) * USEC_TO_SEC_F64; } @@ -344,23 +343,23 @@ U64 getElapsedTimeAndUpdate(U64& lastClockCount) } -LLUnit::Seconds LLTimer::getElapsedTimeF64() const +LLUnit LLTimer::getElapsedTimeF64() const { U64 last = mLastClockCount; return (F64)getElapsedTimeAndUpdate(last) * gClockFrequencyInv; } -LLUnit::Seconds LLTimer::getElapsedTimeF32() const +LLUnit LLTimer::getElapsedTimeF32() const { return (F32)getElapsedTimeF64(); } -LLUnit::Seconds LLTimer::getElapsedTimeAndResetF64() +LLUnit LLTimer::getElapsedTimeAndResetF64() { return (F64)getElapsedTimeAndUpdate(mLastClockCount) * gClockFrequencyInv; } -LLUnit::Seconds LLTimer::getElapsedTimeAndResetF32() +LLUnit LLTimer::getElapsedTimeAndResetF32() { return (F32)getElapsedTimeAndResetF64(); } @@ -373,7 +372,7 @@ void LLTimer::setTimerExpirySec(F32 expiration) + (U64)((F32)(expiration * gClockFrequency)); } -LLUnit::Seconds LLTimer::getRemainingTimeF32() const +LLUnit LLTimer::getRemainingTimeF32() const { U64 cur_ticks = get_clock_count(); if (cur_ticks > mExpirationTicks) diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index e0a880a346..5cb2b18111 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -67,16 +67,16 @@ public: // Return a high precision number of seconds since the start of // this application instance. - static LLUnit::Seconds getElapsedSeconds() + static LLUnit getElapsedSeconds() { return sTimer->getElapsedTimeF64(); } // Return a high precision usec since epoch - static LLUnit::Microseconds getTotalTime(); + static LLUnit getTotalTime(); // Return a high precision seconds since epoch - static LLUnit::Seconds getTotalSeconds(); + static LLUnit getTotalSeconds(); // MANIPULATORS @@ -87,16 +87,16 @@ public: void setTimerExpirySec(F32 expiration); BOOL checkExpirationAndReset(F32 expiration); BOOL hasExpired() const; - LLUnit::Seconds getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset - LLUnit::Seconds getElapsedTimeAndResetF64(); + LLUnit getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset + LLUnit getElapsedTimeAndResetF64(); - LLUnit::Seconds getRemainingTimeF32() const; + LLUnit getRemainingTimeF32() const; static BOOL knownBadTimer(); // ACCESSORS - LLUnit::Seconds getElapsedTimeF32() const; // Returns elapsed time in seconds - LLUnit::Seconds getElapsedTimeF64() const; // Returns elapsed time in seconds + LLUnit getElapsedTimeF32() const; // Returns elapsed time in seconds + LLUnit getElapsedTimeF64() const; // Returns elapsed time in seconds bool getStarted() const { return mStarted; } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index e2530a8a24..d289ea9a88 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -38,37 +38,35 @@ #include -#define LL_TOKEN_PASTE_ACTUAL(x, y) x##y -#define LL_TOKEN_PASTE(x, y) LL_TOKEN_PASTE_ACTUAL(x, y) -#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder LL_TOKEN_PASTE(block_time_recorder, __COUNTER__)(block_timer); +#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder LL_GLUE_TOKENS(block_time_recorder, __COUNTER__)(block_timer); 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; + typedef LLUnit Bytes; + typedef LLUnit Kilobytes; + typedef LLUnit Megabytes; + typedef LLUnit Gigabytes; + typedef LLUnit Bits; + typedef LLUnit Kilobits; + typedef LLUnit Megabits; + typedef LLUnit Gigabits; + + typedef LLUnit Seconds; + typedef LLUnit Milliseconds; + typedef LLUnit Minutes; + typedef LLUnit Hours; + typedef LLUnit Days; + typedef LLUnit Weeks; + typedef LLUnit Milliseconds; + typedef LLUnit Microseconds; + typedef LLUnit Nanoseconds; + + typedef LLUnit Meters; + typedef LLUnit Kilometers; + typedef LLUnit Centimeters; + typedef LLUnit Millimeters; void init(); void cleanup(); @@ -438,7 +436,7 @@ namespace LLTrace void sample(UNIT_T value) { T converted_value; - converted_value.assignFrom(value); + converted_value = value; getPrimaryAccumulator().sample((storage_t)converted_value.value()); } }; @@ -478,7 +476,7 @@ namespace LLTrace void add(UNIT_T value) { T converted_value; - converted_value.assignFrom(value); + converted_value = value; getPrimaryAccumulator().add((storage_t)converted_value.value()); } }; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index fc96631ce0..ca9950b78d 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -197,7 +197,7 @@ namespace LLTrace U32 getSampleCount(const TraceType >& stat) const; U32 getSampleCount(const TraceType >& stat) const; - LLUnit::Seconds getDuration() const { return mElapsedSeconds; } + LLUnit getDuration() const { return mElapsedSeconds; } private: friend class ThreadRecorder; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 4519905707..0dcafbe26e 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -30,326 +30,288 @@ #include "stdtypes.h" #include "llpreprocessor.h" -template -struct LLUnitType : public BASE_UNIT +namespace LLUnits { - typedef DERIVED_UNIT unit_t; - - typedef typename STORAGE_TYPE storage_t; - typedef void is_unit_tag_t; - - LLUnitType() - {} - - LLUnitType(storage_t value) - : BASE_UNIT(convertToBase(value)) - {} - - // implicit downcast - operator unit_t& () - { - return static_cast(*this); - } - - operator storage_t () const - { - return value(); - } - - storage_t value() const - { - return convertToDerived(mBaseValue); - } - - template - storage_t as() const - { - return CONVERTED_TYPE(*this).value(); - } - -protected: - static storage_t convertToBase(storage_t derived_value) - { - return (storage_t)((F32)derived_value * unit_t::conversionToBaseFactor()); - } - - static storage_t convertToDerived(storage_t base_value) +template +struct ConversionFactor +{ + static F64 get() { - return (storage_t)((F32)base_value / unit_t::conversionToBaseFactor()); + llstatic_assert(sizeof(DERIVED_UNITS_TAG) == 0, "Cannot convert between types."); } +}; +template +struct ConversionFactor +{ + static F64 get() { return 1.0; } }; +} -template -struct LLUnitType +template +struct LLUnit { - typedef T unit_t; - typedef STORAGE_TYPE storage_t; + typedef LLUnit self_t; + typedef typename STORAGE_TYPE storage_t; typedef void is_unit_tag_t; - LLUnitType() - : mBaseValue() + LLUnit(storage_t value = storage_t()) + : mValue(value) {} - LLUnitType(storage_t value) - : mBaseValue(value) + template + LLUnit(LLUnit other) + : mValue(convert(other)) {} - unit_t& operator=(storage_t value) + LLUnit(self_t& other) + : mValue(other.mValue) + {} + + self_t& operator = (storage_t value) { - setBaseValue(value); + mValue = value; return *this; } - //implicit downcast - operator unit_t& () + template + self_t& operator = (LLUnit other) { - return static_cast(*this); + mValue = convert(other); + return *this; } - operator storage_t () const + operator storage_t() const { return value(); } - storage_t value() const { return mBaseValue; } - - template - storage_t as() const + storage_t value() const { - return CONVERTED_TYPE(*this).value(); + return mValue; } - static storage_t convertToBase(storage_t derived_value) + void operator += (storage_t value) { - return (storage_t)derived_value; + mValue += value; } - static storage_t convertToDerived(storage_t base_value) + template + void operator += (LLUnit other) { - return (storage_t)base_value; + mValue += convert(other); } - void operator += (const unit_t other) + void operator -= (storage_t value) { - mBaseValue += other.mBaseValue; + mValue -= value; } - void operator -= (const unit_t other) + template + void operator -= (LLUnit other) { - mBaseValue -= other.mBaseValue; + mValue -= convert(other); } void operator *= (storage_t multiplicand) { - mBaseValue *= multiplicand; + mValue *= multiplicand; + } + + template + void operator *= (LLUnit multiplicand) + { + llstatic_assert(sizeof(OTHER_UNIT) == false, "Multiplication of unit types not supported."); } void operator /= (storage_t divisor) { - mBaseValue /= divisor; + mValue /= divisor; } -protected: - void setBaseValue(storage_t value) + template + void operator /= (LLUnit divisor) { - mBaseValue = value; + llstatic_assert(sizeof(OTHER_UNIT) == false, "Division of unit types not supported."); } - storage_t mBaseValue; -}; + template + static storage_t convert(LLUnit v) + { + return (storage_t)(v.value() + * LLUnits::ConversionFactor::get() + * LLUnits::ConversionFactor::get()); + } -template -struct LLUnitTypeWrapper -: public LLUnitType -{ - typedef LLUnitType unit_t; - LLUnitTypeWrapper(const unit_t& other) - : unit_t(other) - {} -}; +protected: + storage_t mValue; +}; // // operator + // -template -DERIVED_UNIT operator + (typename LLUnitType::storage_t first, LLUnitType second) +template +LLUnit operator + (LLUnit first, LLUnit second) { - return DERIVED_UNIT(first + LLUnitType(second).value()); + LLUnit result(first); + result += second; + return result; } +template +LLUnit operator + (LLUnit first, SCALAR_TYPE second) +{ + LLUnit result(first); + result += second; + return result; +} -// -// operator - -// -template -DERIVED_UNIT operator - (typename LLUnitType::storage_t first, LLUnitType second) +template +LLUnit operator + (SCALAR_TYPE first, LLUnit second) { - return DERIVED_UNIT(first - LLUnitType(second).value()); + LLUnit result(first); + result += second; + return result; } // -// operator * +// operator - // -template -DERIVED_UNIT operator * (STORAGE_TYPE first, LLUnitType second) +template +LLUnit operator - (LLUnit first, LLUnit second) { - return DERIVED_UNIT(first * second.value()); + LLUnit result(first); + result -= second; + return result; } -template -DERIVED_UNIT operator * (LLUnitType first, STORAGE_TYPE second) + +template +LLUnit operator - (LLUnit first, SCALAR_TYPE second) { - return DERIVED_UNIT(first.value() * second); + LLUnit result(first); + result -= second; + return result; } +template +LLUnit operator - (SCALAR_TYPE first, LLUnit second) +{ + LLUnit result(first); + result -= second; + return result; +} // -// operator / +// operator * // -template -DERIVED_UNIT operator / (STORAGE_TYPE first, LLUnitTypeWrapper second) +template +LLUnit operator * (SCALAR_TYPE first, LLUnit second) { - return DERIVED_UNIT(first / second.value()); + return LLUnit(first * second.value()); } -template -DERIVED_UNIT operator / (LLUnitTypeWrapper first, STORAGE_TYPE second) +template +LLUnit operator * (LLUnit first, SCALAR_TYPE second) { - return DERIVED_UNIT(first.value() / second); + return LLUnit(first.value() * second); } -// -// operator < -// -template - -bool operator < (typename LLUnitType::storage_t first, LLUnitType second) +template +void operator * (LLUnit, LLUnit) { - return first < second.value(); + llstatic_assert(sizeof(STORAGE_TYPE1) == false, "Multiplication of unit types results in new unit type - not supported."); } // -// operator <= +// operator / // -template -bool operator <= (typename LLUnitType::storage_t first, LLUnitType second) +template +SCALAR_TYPE operator / (SCALAR_TYPE first, LLUnit second) { - return first <= second.value(); + return SCALAR_TYPE(first / second.value()); } - -// -// operator > -// -template -bool operator > (typename LLUnitType::storage_t first, LLUnitType second) +template +LLUnit operator / (LLUnit first, SCALAR_TYPE second) { - return first > second.value(); + return LLUnit(first.value() / second); } -// -// operator >= -// -template -bool operator >= (typename LLUnitType::storage_t first, LLUnitType second) +template +void operator / (LLUnit, LLUnit) { - return first >= second.value(); + llstatic_assert(sizeof(STORAGE_TYPE1) == false, "Multiplication of unit types results in new unit type - not supported."); } -// -// operator == -// -template -bool operator == (typename LLUnitType::storage_t first, LLUnitType second) -{ - return first == second.value(); +#define COMPARISON_OPERATORS(op) \ +template \ +bool operator op (SCALAR_TYPE first, LLUnit second) \ +{ \ + return first op second.value(); \ +} \ + \ +template \ +bool operator op (LLUnit first, SCALAR_TYPE second) \ +{ \ + return first.value() op second; \ +} \ + \ +template \ +bool operator op (LLUnit first, LLUnit second) \ +{ \ + return first.value() op first.convert(second); \ } -// -// operator != -// -template -bool operator != (typename LLUnitType::storage_t first, LLUnitType second) +COMPARISON_OPERATORS(<) +COMPARISON_OPERATORS(<=) +COMPARISON_OPERATORS(>) +COMPARISON_OPERATORS(>=) +COMPARISON_OPERATORS(==) +COMPARISON_OPERATORS(!=) + +namespace LLUnits { - return first != second.value(); +#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor)\ +struct unit_name \ +{ \ + typedef base_unit_name base_unit_t; \ +}; \ +template<> \ +struct ConversionFactor \ +{ \ + static F64 get() { return (conversion_factor); } \ +}; \ + \ +template<> \ +struct ConversionFactor \ +{ \ + static F64 get() { return 1.0 / (conversion_factor); } \ } -#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) \ - { \ - assignFrom(source); \ - } \ - \ - template \ - void assignFrom(LLUnitType, SOURCE_TYPE> source) \ - { \ - setBaseValue((storage_t)source.unit_name::unit_t::value()); \ - } \ - \ - }; \ - -#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) \ - { \ - assignFrom(source); \ - } \ - \ - template \ - void assignFrom(LLUnitType, SOURCE_TYPE> source) \ - { \ - setBaseValue((storage_t)source.base_unit::unit_t::value()); \ - } \ - \ - static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ - \ - }; \ - -namespace LLUnit -{ - LL_DECLARE_BASE_UNIT(Bytes); - LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); - LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); - LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); - LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.f / 8.f)); - LL_DECLARE_DERIVED_UNIT(Bytes, Kilobits, (1024 / 8)); - LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); - LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); - - LL_DECLARE_BASE_UNIT(Seconds); - LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); - LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); - LL_DECLARE_DERIVED_UNIT(Seconds, Days, 60 * 60 * 24); - LL_DECLARE_DERIVED_UNIT(Seconds, Weeks, 60 * 60 * 24 * 7); - LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.f / 1000.f)); - LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.f / (1000000.f))); - LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.f / (1000000000.f))); - - LL_DECLARE_BASE_UNIT(Meters); - LL_DECLARE_DERIVED_UNIT(Meters, Kilometers, 1000); - LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, 1 / 100); - LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, 1 / 1000); +struct Bytes { typedef Bytes base_unit_t; }; +LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); +LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); +LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); +LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.0 / 8.0)); +LL_DECLARE_DERIVED_UNIT(Bytes, Kilobits, (1024 / 8)); +LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); +LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); + +struct Seconds { typedef Seconds base_unit_t; }; +LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); +LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); +LL_DECLARE_DERIVED_UNIT(Seconds, Days, 60 * 60 * 24); +LL_DECLARE_DERIVED_UNIT(Seconds, Weeks, 60 * 60 * 24 * 7); +LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.0 / 1000.0)); +LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.0 / (1000000.0))); +LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.0 / (1000000000.0))); + +struct Meters { typedef Meters base_unit_t; }; +LL_DECLARE_DERIVED_UNIT(Meters, Kilometers, 1000); +LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, (1.0 / 100)); +LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, (1.0 / 1000)); } #endif // LL_LLUNIT_H -- cgit v1.2.3 From a3e3e8b4ccd96e98da73acf1c584bbfa5a8b2b56 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 12 Nov 2012 19:08:14 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system simplified llfasttimer code down to 2 classes llunit unit conversion now done in floating point or 64 bit integer precision, depending on source type --- indra/llcommon/llfasttimer.cpp | 270 ++++++++++++-------------------------- indra/llcommon/llfasttimer.h | 121 ++++++----------- indra/llcommon/llprocessor.cpp | 2 +- indra/llcommon/llprocessor.h | 4 +- indra/llcommon/lltrace.cpp | 1 + indra/llcommon/lltrace.h | 39 ++---- indra/llcommon/lltracerecording.h | 18 +-- indra/llcommon/llunit.h | 127 +++++++++++++----- 8 files changed, 245 insertions(+), 337 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 4f67004773..c4839fed77 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -32,6 +32,7 @@ #include "llsingleton.h" #include "lltreeiterators.h" #include "llsdserialize.h" +#include "llunit.h" #include @@ -73,13 +74,13 @@ U64 LLFastTimer::sClockResolution = 1000000; // Microsecond resolution // FIXME: move these declarations to the relevant modules // helper functions -typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; +typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; -static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(LLFastTimer::NamedTimer& id) +static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(LLFastTimer::DeclareTimer& id) { return timer_tree_bottom_up_iterator_t(&id, - boost::bind(boost::mem_fn(&LLFastTimer::NamedTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&LLFastTimer::NamedTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::beginChildren), _1), + boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::endChildren), _1)); } static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() @@ -87,14 +88,14 @@ static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() return timer_tree_bottom_up_iterator_t(); } -typedef LLTreeDFSIter timer_tree_dfs_iterator_t; +typedef LLTreeDFSIter timer_tree_dfs_iterator_t; -static timer_tree_dfs_iterator_t begin_timer_tree(LLFastTimer::NamedTimer& id) +static timer_tree_dfs_iterator_t begin_timer_tree(LLFastTimer::DeclareTimer& id) { return timer_tree_dfs_iterator_t(&id, - boost::bind(boost::mem_fn(&LLFastTimer::NamedTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&LLFastTimer::NamedTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::beginChildren), _1), + boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::endChildren), _1)); } static timer_tree_dfs_iterator_t end_timer_tree() @@ -102,75 +103,12 @@ static timer_tree_dfs_iterator_t end_timer_tree() return timer_tree_dfs_iterator_t(); } -// factory class that creates NamedTimers via static DeclareTimer objects -class NamedTimerFactory : public LLSingleton +LLFastTimer::DeclareTimer& LLFastTimer::DeclareTimer::getRootTimer() { -public: - NamedTimerFactory() - : mTimerRoot(NULL) - {} - - /*virtual */ void initSingleton() - { - mTimerRoot = new LLFastTimer::NamedTimer("root"); - mRootFrameState.setNamedTimer(mTimerRoot); - mTimerRoot->setFrameState(&mRootFrameState); - mTimerRoot->mParent = mTimerRoot; - mTimerRoot->setCollapsed(false); - mRootFrameState.mParent = &mRootFrameState; - } - - ~NamedTimerFactory() - { - std::for_each(mTimers.begin(), mTimers.end(), DeletePairedPointer()); - - delete mTimerRoot; - } - - LLFastTimer::NamedTimer& createNamedTimer(const std::string& name, LLFastTimer::FrameState* state) - { - LLFastTimer::NamedTimer* timer = new LLFastTimer::NamedTimer(name); - timer->setFrameState(state); - timer->setParent(mTimerRoot); - mTimers.insert(std::make_pair(name, timer)); - - return *timer; - } - - LLFastTimer::NamedTimer* getTimerByName(const std::string& name) - { - timer_map_t::iterator found_it = mTimers.find(name); - if (found_it != mTimers.end()) - { - return found_it->second; - } - return NULL; - } - - LLFastTimer::NamedTimer* getRootTimer() { return mTimerRoot; } - - typedef std::multimap timer_map_t; - timer_map_t::iterator beginTimers() { return mTimers.begin(); } - timer_map_t::iterator endTimers() { return mTimers.end(); } - S32 timerCount() { return mTimers.size(); } - -private: - timer_map_t mTimers; - - LLFastTimer::NamedTimer* mTimerRoot; - LLFastTimer::FrameState mRootFrameState; -}; - -LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open ) -: mTimer(NamedTimerFactory::instance().createNamedTimer(name, &mFrameState)) -{ - mTimer.setCollapsed(!open); + static DeclareTimer root_timer("root", true, NULL); + return root_timer; } -LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name) -: mTimer(NamedTimerFactory::instance().createNamedTimer(name, &mFrameState)) -{ -} //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) @@ -183,7 +121,7 @@ U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz - static U64 sCPUClockFrequency = U64(LLProcessorInfo().getCPUFrequency()*1000000.0); + static LLUnit sCPUClockFrequency = LLProcessorInfo().getCPUFrequency(); // we drop the low-order byte in our timers, so report a lower frequency #else @@ -206,49 +144,44 @@ LLFastTimer::FrameState::FrameState() : mActiveCount(0), mCalls(0), mSelfTimeCounter(0), - mParent(NULL), mLastCaller(NULL), mMoveUpTree(false) {} -LLFastTimer::NamedTimer::NamedTimer(const std::string& name) +LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open, DeclareTimer* parent) : mName(name), mCollapsed(true), mParent(NULL), mTreeTimeCounter(0), mCountAverage(0), mCallAverage(0), - mNeedsSorting(false), - mFrameState(NULL) + mNeedsSorting(false) { + setCollapsed(!open); + + if (parent) + { + setParent(parent); + } + else + { + mParent = this; + } + mCountHistory = new U32[HISTORY_NUM]; memset(mCountHistory, 0, sizeof(U32) * HISTORY_NUM); mCallHistory = new U32[HISTORY_NUM]; memset(mCallHistory, 0, sizeof(U32) * HISTORY_NUM); } -LLFastTimer::NamedTimer::~NamedTimer() +LLFastTimer::DeclareTimer::~DeclareTimer() { delete[] mCountHistory; delete[] mCallHistory; } -std::string LLFastTimer::NamedTimer::getToolTip(S32 history_idx) -{ - F64 ms_multiplier = 1000.0 / (F64)LLFastTimer::countsPerSecond(); - if (history_idx < 0) - { - // by default, show average number of call - return llformat("%s (%d ms, %d calls)", getName().c_str(), (S32)(getCountAverage() * ms_multiplier), (S32)getCallAverage()); - } - else - { - return llformat("%s (%d ms, %d calls)", getName().c_str(), (S32)(getHistoricalCount(history_idx) * ms_multiplier), (S32)getHistoricalCalls(history_idx)); - } -} - -void LLFastTimer::NamedTimer::setParent(NamedTimer* parent) +void LLFastTimer::DeclareTimer::setParent(DeclareTimer* parent) { llassert_always(parent != this); llassert_always(parent != NULL); @@ -264,8 +197,8 @@ void LLFastTimer::NamedTimer::setParent(NamedTimer* parent) // subtract average timing from previous parent mParent->mCountAverage -= mCountAverage; - std::vector& children = mParent->getChildren(); - std::vector::iterator found_it = std::find(children.begin(), children.end(), this); + std::vector& children = mParent->getChildren(); + std::vector::iterator found_it = std::find(children.begin(), children.end(), this); if (found_it != children.end()) { children.erase(found_it); @@ -275,16 +208,15 @@ void LLFastTimer::NamedTimer::setParent(NamedTimer* parent) mParent = parent; if (parent) { - getFrameState().mParent = &parent->getFrameState(); parent->getChildren().push_back(this); parent->mNeedsSorting = true; } } -S32 LLFastTimer::NamedTimer::getDepth() +S32 LLFastTimer::DeclareTimer::getDepth() { S32 depth = 0; - NamedTimer* timerp = mParent; + DeclareTimer* timerp = mParent; while(timerp) { depth++; @@ -295,7 +227,7 @@ S32 LLFastTimer::NamedTimer::getDepth() } // static -void LLFastTimer::NamedTimer::processTimes() +void LLFastTimer::DeclareTimer::processTimes() { if (sCurFrameIndex < 0) return; @@ -306,14 +238,14 @@ void LLFastTimer::NamedTimer::processTimes() // sort child timers by name struct SortTimerByName { - bool operator()(const LLFastTimer::NamedTimer* i1, const LLFastTimer::NamedTimer* i2) + bool operator()(const LLFastTimer::DeclareTimer* i1, const LLFastTimer::DeclareTimer* i2) { return i1->getName() < i2->getName(); } }; //static -void LLFastTimer::NamedTimer::buildHierarchy() +void LLFastTimer::DeclareTimer::buildHierarchy() { if (sCurFrameIndex < 0 ) return; @@ -321,16 +253,16 @@ void LLFastTimer::NamedTimer::buildHierarchy() { for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - NamedTimer& timer = *it; - if (&timer == NamedTimerFactory::instance().getRootTimer()) continue; + DeclareTimer& timer = *it; + if (&timer == &DeclareTimer::getRootTimer()) continue; // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.getFrameState().mLastCaller && timer.mParent == NamedTimerFactory::instance().getRootTimer()) + if (timer.mLastCaller && timer.mParent == &DeclareTimer::getRootTimer()) { - timer.setParent(timer.getFrameState().mLastCaller->mTimer); + timer.setParent(timer.mLastCaller); // no need to push up tree on first use, flag can be set spuriously - timer.getFrameState().mMoveUpTree = false; + timer.mMoveUpTree = false; } } } @@ -338,22 +270,22 @@ void LLFastTimer::NamedTimer::buildHierarchy() // bump timers up tree if they've been flagged as being in the wrong place // do this in a bottom up order to promote descendants first before promoting ancestors // this preserves partial order derived from current frame's observations - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(*NamedTimerFactory::instance().getRootTimer()); + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(DeclareTimer::getRootTimer()); it != end_timer_tree_bottom_up(); ++it) { - NamedTimer* timerp = *it; + DeclareTimer* timerp = *it; // skip root timer - if (timerp == NamedTimerFactory::instance().getRootTimer()) continue; + if (timerp == &DeclareTimer::getRootTimer()) continue; - if (timerp->getFrameState().mMoveUpTree) + if (timerp->mMoveUpTree) { // since ancestors have already been visited, reparenting won't affect tree traversal //step up tree, bringing our descendants with us LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; timerp->setParent(timerp->getParent()->getParent()); - timerp->getFrameState().mMoveUpTree = false; + timerp->mMoveUpTree = false; // don't bubble up any ancestors until descendants are done bubbling up it.skipAncestors(); @@ -361,11 +293,11 @@ void LLFastTimer::NamedTimer::buildHierarchy() } // sort timers by time last called, so call graph makes sense - for(timer_tree_dfs_iterator_t it = begin_timer_tree(*NamedTimerFactory::instance().getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(DeclareTimer::getRootTimer()); it != end_timer_tree(); ++it) { - NamedTimer* timerp = (*it); + DeclareTimer* timerp = (*it); if (timerp->mNeedsSorting) { std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); @@ -375,7 +307,7 @@ void LLFastTimer::NamedTimer::buildHierarchy() } //static -void LLFastTimer::NamedTimer::accumulateTimings() +void LLFastTimer::DeclareTimer::accumulateTimings() { U32 cur_time = getCPUClockCount32(); @@ -388,8 +320,8 @@ void LLFastTimer::NamedTimer::accumulateTimings() U32 cumulative_time_delta = cur_time - cur_timer->mStartTime; U32 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; - cur_data->mFrameState->mSelfTimeCounter += self_time_delta; - cur_data->mFrameState->mTotalTimeCounter += cumulative_time_delta; + cur_data->mTimerData->mSelfTimeCounter += self_time_delta; + cur_data->mTimerData->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; @@ -400,12 +332,12 @@ void LLFastTimer::NamedTimer::accumulateTimings() } // traverse tree in DFS post order, or bottom up - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(*NamedTimerFactory::instance().getRootTimer()); + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(DeclareTimer::getRootTimer()); it != end_timer_tree_bottom_up(); ++it) { - NamedTimer* timerp = (*it); - timerp->mTreeTimeCounter = timerp->getFrameState().mSelfTimeCounter; + DeclareTimer* timerp = (*it); + timerp->mTreeTimeCounter = timerp->mSelfTimeCounter; for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) { timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; @@ -418,15 +350,15 @@ void LLFastTimer::NamedTimer::accumulateTimings() int hidx = cur_frame % HISTORY_NUM; timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; - timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); - timerp->mCallHistory[hidx] = timerp->getFrameState().mCalls; - timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + timerp->getFrameState().mCalls) / (cur_frame+1); + timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); + timerp->mCallHistory[hidx] = timerp->mCalls; + timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + timerp->mCalls) / (cur_frame+1); } } } // static -void LLFastTimer::NamedTimer::resetFrame() +void LLFastTimer::DeclareTimer::resetFrame() { if (sLog) { //output current frame counts to performance log @@ -435,11 +367,11 @@ void LLFastTimer::NamedTimer::resetFrame() if (call_count % 100 == 0) { LL_DEBUGS("FastTimers") << "countsPerSecond (32 bit): " << countsPerSecond() << LL_ENDL; - LL_DEBUGS("FastTimers") << "get_clock_count (64 bit): " << get_clock_count() << llendl; + LL_DEBUGS("FastTimers") << "get_clock_count (64 bit): " << get_clock_count() << LL_ENDL; LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; - LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64())/((F64)LLProcessorInfo().getCPUFrequency()*1000000.0) << LL_ENDL; + LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64()) / (LLUnit(LLProcessorInfo().getCPUFrequency())) << LL_ENDL; } call_count++; @@ -451,14 +383,13 @@ void LLFastTimer::NamedTimer::resetFrame() { for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - NamedTimer& timer = *it; - FrameState& info = timer.getFrameState(); - sd[timer.getName()]["Time"] = (LLSD::Real) (info.mSelfTimeCounter*iclock_freq); - sd[timer.getName()]["Calls"] = (LLSD::Integer) info.mCalls; + DeclareTimer& timer = *it; + sd[timer.getName()]["Time"] = (LLSD::Real) (timer.mSelfTimeCounter*iclock_freq); + sd[timer.getName()]["Calls"] = (LLSD::Integer) timer.mCalls; // computing total time here because getting the root timer's getCountHistory // doesn't work correctly on the first frame - total_time = total_time + info.mSelfTimeCounter * iclock_freq; + total_time = total_time + timer.mSelfTimeCounter * iclock_freq; } } @@ -474,23 +405,16 @@ void LLFastTimer::NamedTimer::resetFrame() // reset for next frame for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - NamedTimer& timer = *it; - - FrameState& info = timer.getFrameState(); - info.mSelfTimeCounter = 0; - info.mCalls = 0; - info.mLastCaller = NULL; - info.mMoveUpTree = false; - // update parent pointer in timer state struct - if (timer.mParent) - { - info.mParent = &timer.mParent->getFrameState(); - } + DeclareTimer& timer = *it; + timer.mSelfTimeCounter = 0; + timer.mCalls = 0; + timer.mLastCaller = NULL; + timer.mMoveUpTree = false; } } //static -void LLFastTimer::NamedTimer::reset() +void LLFastTimer::DeclareTimer::reset() { resetFrame(); // reset frame data @@ -514,10 +438,10 @@ void LLFastTimer::NamedTimer::reset() { for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - NamedTimer& timer = *it; - if (&timer != NamedTimerFactory::instance().getRootTimer()) + DeclareTimer& timer = *it; + if (&timer != &DeclareTimer::getRootTimer()) { - timer.setParent(NamedTimerFactory::instance().getRootTimer()); + timer.setParent(&DeclareTimer::getRootTimer()); } timer.mCountAverage = 0; @@ -531,34 +455,29 @@ void LLFastTimer::NamedTimer::reset() sCurFrameIndex = 0; } -U32 LLFastTimer::NamedTimer::getHistoricalCount(S32 history_index) const +U32 LLFastTimer::DeclareTimer::getHistoricalCount(S32 history_index) const { - S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::NamedTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::DeclareTimer::HISTORY_NUM; return mCountHistory[history_idx]; } -U32 LLFastTimer::NamedTimer::getHistoricalCalls(S32 history_index ) const +U32 LLFastTimer::DeclareTimer::getHistoricalCalls(S32 history_index ) const { - S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::NamedTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::DeclareTimer::HISTORY_NUM; return mCallHistory[history_idx]; } -LLFastTimer::FrameState& LLFastTimer::NamedTimer::getFrameState() const -{ - return *mFrameState; -} - -std::vector::const_iterator LLFastTimer::NamedTimer::beginChildren() +std::vector::const_iterator LLFastTimer::DeclareTimer::beginChildren() { return mChildren.begin(); } -std::vector::const_iterator LLFastTimer::NamedTimer::endChildren() +std::vector::const_iterator LLFastTimer::DeclareTimer::endChildren() { return mChildren.end(); } -std::vector& LLFastTimer::NamedTimer::getChildren() +std::vector& LLFastTimer::DeclareTimer::getChildren() { return mChildren; } @@ -575,12 +494,12 @@ void LLFastTimer::nextFrame() if (!sPauseHistory) { - NamedTimer::processTimes(); + DeclareTimer::processTimes(); sLastFrameIndex = sCurFrameIndex++; } // get ready for next frame - NamedTimer::resetFrame(); + DeclareTimer::resetFrame(); sLastFrameTime = frame_time; } @@ -588,17 +507,17 @@ void LLFastTimer::nextFrame() void LLFastTimer::dumpCurTimes() { // accumulate timings, etc. - NamedTimer::processTimes(); + DeclareTimer::processTimes(); F64 clock_freq = (F64)countsPerSecond(); F64 iclock_freq = 1000.0 / clock_freq; // clock_ticks -> milliseconds // walk over timers in depth order and output timings - for(timer_tree_dfs_iterator_t it = begin_timer_tree(*NamedTimerFactory::instance().getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(DeclareTimer::getRootTimer()); it != end_timer_tree(); ++it) { - NamedTimer* timerp = (*it); + DeclareTimer* timerp = (*it); F64 total_time_ms = ((F64)timerp->getHistoricalCount(0) * iclock_freq); // Don't bother with really brief times, keep output concise if (total_time_ms < 0.1) continue; @@ -621,7 +540,7 @@ void LLFastTimer::dumpCurTimes() //static void LLFastTimer::reset() { - NamedTimer::reset(); + DeclareTimer::reset(); } @@ -637,22 +556,3 @@ void LLFastTimer::writeLog(std::ostream& os) } } -//static -const LLFastTimer::NamedTimer* LLFastTimer::getTimerByName(const std::string& name) -{ - return NamedTimerFactory::instance().getTimerByName(name); -} - -//LLFastTimer::LLFastTimer(LLFastTimer::FrameState* state) -//: mFrameState(state) -//{ -// U32 start_time = getCPUClockCount32(); -// mStartTime = start_time; -// mFrameState->mActiveCount++; -// LLFastTimer::sCurTimerData.mCurTimer = this; -// LLFastTimer::sCurTimerData.mFrameState = mFrameState; -// LLFastTimer::sCurTimerData.mChildTime = 0; -// mLastTimerData = LLFastTimer::sCurTimerData; -//} - - diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 4660fad5e3..31872e4e65 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -30,7 +30,6 @@ #include "llinstancetracker.h" #define FAST_TIMER_ON 1 -#define DEBUG_FAST_TIMER_THREADS 1 class LLMutex; @@ -45,64 +44,53 @@ LL_COMMON_API void assert_main_thread(); class LL_COMMON_API LLFastTimer { public: - class NamedTimer; - + class DeclareTimer; struct LL_COMMON_API FrameState { FrameState(); - void setNamedTimer(class NamedTimer* timerp) { mTimer = timerp; } U32 mSelfTimeCounter; U32 mTotalTimeCounter; U32 mCalls; - FrameState* mParent; // info for caller timer - FrameState* mLastCaller; // used to bootstrap tree construction - class NamedTimer* mTimer; + DeclareTimer* mLastCaller; // used to bootstrap tree construction U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame }; // stores a "named" timer instance to be reused via multiple LLFastTimer stack instances - class LL_COMMON_API NamedTimer - : public LLInstanceTracker + class LL_COMMON_API DeclareTimer + : public LLInstanceTracker { - friend class DeclareTimer; public: - ~NamedTimer(); + DeclareTimer(const std::string& name, bool open = false, DeclareTimer* parent = &getRootTimer()); + ~DeclareTimer(); enum { HISTORY_NUM = 300 }; const std::string& getName() const { return mName; } - NamedTimer* getParent() const { return mParent; } - void setParent(NamedTimer* parent); + DeclareTimer* getParent() const { return mParent; } + void setParent(DeclareTimer* parent); S32 getDepth(); - std::string getToolTip(S32 history_index = -1); - typedef std::vector::const_iterator child_const_iter; + typedef std::vector::const_iterator child_const_iter; child_const_iter beginChildren(); child_const_iter endChildren(); - std::vector& getChildren(); + std::vector& getChildren(); - void setCollapsed(bool collapsed) { mCollapsed = collapsed; } - bool getCollapsed() const { return mCollapsed; } + void setCollapsed(bool collapsed) { mCollapsed = collapsed; } + bool getCollapsed() const { return mCollapsed; } U32 getCountAverage() const { return mCountAverage; } - U32 getCallAverage() const { return mCallAverage; } + U32 getCallAverage() const { return mCallAverage; } U32 getHistoricalCount(S32 history_index = 0) const; U32 getHistoricalCalls(S32 history_index = 0) const; - void setFrameState(FrameState* state) { mFrameState = state; state->setNamedTimer(this); } - FrameState& getFrameState() const; + static DeclareTimer& getRootTimer(); private: friend class LLFastTimer; - friend class NamedTimerFactory; - // - // methods - // - NamedTimer(const std::string& name); // recursive call to gather total time from children static void accumulateTimings(); @@ -117,82 +105,62 @@ public: // // members // - FrameState* mFrameState; + U32 mSelfTimeCounter; + U32 mTotalTimeCounter; + U32 mCalls; + DeclareTimer* mLastCaller; // used to bootstrap tree construction + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - std::string mName; + std::string mName; - // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete - U32 mTreeTimeCounter; + // sum of recored self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete + U32 mTreeTimeCounter; - U32 mCountAverage; - U32 mCallAverage; + U32 mCountAverage; + U32 mCallAverage; - U32* mCountHistory; - U32* mCallHistory; + U32* mCountHistory; + U32* mCallHistory; // tree structure - NamedTimer* mParent; // NamedTimer of caller(parent) - std::vector mChildren; + DeclareTimer* mParent; // DeclareTimer of caller(parent) + std::vector mChildren; bool mCollapsed; // don't show children bool mNeedsSorting; // sort children whenever child added }; - // used to statically declare a new named timer - class LL_COMMON_API DeclareTimer - : public LLInstanceTracker - { - friend class LLFastTimer; - public: - DeclareTimer(const std::string& name, bool open); - DeclareTimer(const std::string& name); - - NamedTimer& getNamedTimer() { return mTimer; } - - private: - FrameState mFrameState; - NamedTimer& mTimer; - }; - public: - //LLFastTimer(LLFastTimer::FrameState* state); - LL_FORCE_INLINE LLFastTimer(LLFastTimer::DeclareTimer& timer) { #if FAST_TIMER_ON - LLFastTimer::FrameState* frame_state = &timer.mFrameState; mStartTime = getCPUClockCount32(); - frame_state->mActiveCount++; - frame_state->mCalls++; + timer.mActiveCount++; + timer.mCalls++; // keep current parent as long as it is active when we are - frame_state->mMoveUpTree |= (frame_state->mParent->mActiveCount == 0); + timer.mMoveUpTree |= (timer.mParent->mActiveCount == 0); LLFastTimer::CurTimerData* cur_timer_data = &LLFastTimer::sCurTimerData; mLastTimerData = *cur_timer_data; cur_timer_data->mCurTimer = this; - cur_timer_data->mFrameState = frame_state; + cur_timer_data->mTimerData = &timer; cur_timer_data->mChildTime = 0; -#endif -#if DEBUG_FAST_TIMER_THREADS -#if !LL_RELEASE - assert_main_thread(); -#endif #endif } LL_FORCE_INLINE ~LLFastTimer() { #if FAST_TIMER_ON - LLFastTimer::FrameState* frame_state = LLFastTimer::sCurTimerData.mFrameState; U32 total_time = getCPUClockCount32() - mStartTime; - - frame_state->mSelfTimeCounter += total_time - LLFastTimer::sCurTimerData.mChildTime; - frame_state->mTotalTimeCounter += total_time; - frame_state->mActiveCount--; + DeclareTimer* timer_data = LLFastTimer::sCurTimerData.mTimerData; + timer_data->mSelfTimeCounter += total_time - LLFastTimer::sCurTimerData.mChildTime; + timer_data->mTotalTimeCounter += total_time; + timer_data->mActiveCount--; // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - frame_state->mLastCaller = mLastTimerData.mFrameState; + timer_data->mLastCaller = mLastTimerData.mTimerData; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; @@ -225,12 +193,11 @@ public: static S32 getCurFrameIndex() { return sCurFrameIndex; } static void writeLog(std::ostream& os); - static const NamedTimer* getTimerByName(const std::string& name); struct CurTimerData { LLFastTimer* mCurTimer; - FrameState* mFrameState; + DeclareTimer* mTimerData; U32 mChildTime; }; static CurTimerData sCurTimerData; @@ -374,15 +341,13 @@ private: #endif - static U64 sClockResolution; - - static S32 sCurFrameIndex; - static S32 sLastFrameIndex; - static U64 sLastFrameTime; + static U64 sClockResolution; + static S32 sCurFrameIndex; + static S32 sLastFrameIndex; + static U64 sLastFrameTime; U32 mStartTime; LLFastTimer::CurTimerData mLastTimerData; - }; typedef class LLFastTimer LLFastTimer; diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index fd8f603d21..87a5930c14 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -877,7 +877,7 @@ LLProcessorInfo::LLProcessorInfo() : mImpl(NULL) LLProcessorInfo::~LLProcessorInfo() {} -F64 LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } +LLUnit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } bool LLProcessorInfo::hasSSE() const { return mImpl->hasSSE(); } bool LLProcessorInfo::hasSSE2() const { return mImpl->hasSSE2(); } bool LLProcessorInfo::hasAltivec() const { return mImpl->hasAltivec(); } diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h index 6364d3c8bb..2a21a5c115 100644 --- a/indra/llcommon/llprocessor.h +++ b/indra/llcommon/llprocessor.h @@ -27,6 +27,8 @@ #ifndef LLPROCESSOR_H #define LLPROCESSOR_H +#include "llunit.h" + class LLProcessorInfoImpl; class LL_COMMON_API LLProcessorInfo @@ -35,7 +37,7 @@ public: LLProcessorInfo(); ~LLProcessorInfo(); - F64 getCPUFrequency() const; + LLUnit getCPUFrequency() const; bool hasSSE() const; bool hasSSE2() const; bool hasAltivec() const; diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index d5911ece25..3f605f2c74 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -42,6 +42,7 @@ void init() void cleanup() { delete gMasterThreadRecorder; + LLUnitStrict seconds; gMasterThreadRecorder = NULL; } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index d289ea9a88..549e407822 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -57,8 +57,6 @@ namespace LLTrace typedef LLUnit Milliseconds; typedef LLUnit Minutes; typedef LLUnit Hours; - typedef LLUnit Days; - typedef LLUnit Weeks; typedef LLUnit Milliseconds; typedef LLUnit Microseconds; typedef LLUnit Nanoseconds; @@ -226,27 +224,6 @@ namespace LLTrace size_t mAccumulatorIndex; }; - - template - struct StorageType - { - typedef T type_t; - }; - - template - struct StorageType - { - typedef typename StorageType::type_t type_t; - }; - - template<> struct StorageType { typedef F64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template<> struct StorageType { typedef S64 type_t; }; - template class LL_COMMON_API MeasurementAccumulator { @@ -406,10 +383,10 @@ namespace LLTrace template class LL_COMMON_API Measurement - : public TraceType::type_t> > + : public TraceType::type_t> > { public: - typedef typename StorageType::type_t storage_t; + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; Measurement(const char* name, const char* description = NULL) : TraceType(name, description) @@ -423,10 +400,10 @@ namespace LLTrace template class LL_COMMON_API Measurement - : public TraceType::type_t> > + : public TraceType::type_t> > { public: - typedef typename StorageType::type_t storage_t; + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; Measurement(const char* name, const char* description = NULL) : TraceType(name, description) @@ -446,10 +423,10 @@ namespace LLTrace template class LL_COMMON_API Count - : public TraceType::type_t> > + : public TraceType::type_t> > { public: - typedef typename StorageType::type_t storage_t; + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; Count(const char* name, const char* description = NULL) : TraceType(name) @@ -463,10 +440,10 @@ namespace LLTrace template class LL_COMMON_API Count - : public TraceType::type_t> > + : public TraceType::type_t> > { public: - typedef typename StorageType::type_t storage_t; + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; Count(const char* name, const char* description = NULL) : TraceType(name) diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index ca9950b78d..16b80fd1d8 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -122,7 +122,7 @@ namespace LLTrace template T getSum(const Count& stat) const { - return (T)getSum(static_cast::type_t> >&> (stat)); + return (T)getSum(static_cast::type_t> >&> (stat)); } F64 getPerSec(const TraceType >& stat) const; @@ -130,7 +130,7 @@ namespace LLTrace template T getPerSec(const Count& stat) const { - return (T)getPerSec(static_cast::type_t> >&> (stat)); + return (T)getPerSec(static_cast::type_t> >&> (stat)); } U32 getSampleCount(const TraceType >& stat) const; @@ -143,7 +143,7 @@ namespace LLTrace template T getSum(const Measurement& stat) const { - return (T)getSum(static_cast::type_t> >&> (stat)); + return (T)getSum(static_cast::type_t> >&> (stat)); } F64 getPerSec(const TraceType >& stat) const; @@ -151,7 +151,7 @@ namespace LLTrace template T getPerSec(const Measurement& stat) const { - return (T)getPerSec(static_cast::type_t> >&> (stat)); + return (T)getPerSec(static_cast::type_t> >&> (stat)); } F64 getMin(const TraceType >& stat) const; @@ -159,7 +159,7 @@ namespace LLTrace template T getMin(const Measurement& stat) const { - return (T)getMin(static_cast::type_t> >&> (stat)); + return (T)getMin(static_cast::type_t> >&> (stat)); } F64 getMax(const TraceType >& stat) const; @@ -167,7 +167,7 @@ namespace LLTrace template T getMax(const Measurement& stat) const { - return (T)getMax(static_cast::type_t> >&> (stat)); + return (T)getMax(static_cast::type_t> >&> (stat)); } F64 getMean(const TraceType >& stat) const; @@ -175,7 +175,7 @@ namespace LLTrace template T getMean(Measurement& stat) const { - return (T)getMean(static_cast::type_t> >&> (stat)); + return (T)getMean(static_cast::type_t> >&> (stat)); } F64 getStandardDeviation(const TraceType >& stat) const; @@ -183,7 +183,7 @@ namespace LLTrace template T getStandardDeviation(const Measurement& stat) const { - return (T)getMean(static_cast::type_t> >&> (stat)); + return (T)getMean(static_cast::type_t> >&> (stat)); } F64 getLastValue(const TraceType >& stat) const; @@ -191,7 +191,7 @@ namespace LLTrace template T getLastValue(const Measurement& stat) const { - return (T)getLastValue(static_cast::type_t> >&> (stat)); + return (T)getLastValue(static_cast::type_t> >&> (stat)); } U32 getSampleCount(const TraceType >& stat) const; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 0dcafbe26e..54ba1d67db 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -32,19 +32,44 @@ namespace LLUnits { -template + +template +struct HighestPrecisionType +{ + typedef T type_t; +}; + +template +struct HighestPrecisionType +{ + typedef typename HighestPrecisionType::type_t type_t; +}; + +template<> struct HighestPrecisionType { typedef F64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; +template<> struct HighestPrecisionType { typedef S64 type_t; }; + +template struct ConversionFactor { - static F64 get() + static typename HighestPrecisionType::type_t get() { + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template llstatic_assert(sizeof(DERIVED_UNITS_TAG) == 0, "Cannot convert between types."); } }; -template -struct ConversionFactor +template +struct ConversionFactor { - static F64 get() { return 1.0; } + static typename HighestPrecisionType::type_t get() + { + return 1; + } }; } @@ -91,6 +116,11 @@ struct LLUnit return mValue; } + template LLUnit as() + { + return LLUnit(*this); + } + void operator += (storage_t value) { mValue += value; @@ -121,7 +151,8 @@ struct LLUnit template void operator *= (LLUnit multiplicand) { - llstatic_assert(sizeof(OTHER_UNIT) == false, "Multiplication of unit types not supported."); + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(OTHER_UNIT) == 0, "Multiplication of unit types not supported."); } void operator /= (storage_t divisor) @@ -132,15 +163,16 @@ struct LLUnit template void operator /= (LLUnit divisor) { - llstatic_assert(sizeof(OTHER_UNIT) == false, "Division of unit types not supported."); + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(OTHER_UNIT) == 0, "Division of unit types not supported."); } - template - static storage_t convert(LLUnit v) + template + static storage_t convert(LLUnit v) { return (storage_t)(v.value() - * LLUnits::ConversionFactor::get() - * LLUnits::ConversionFactor::get()); + * LLUnits::ConversionFactor::get() + * LLUnits::ConversionFactor::get()); } protected: @@ -148,6 +180,32 @@ protected: storage_t mValue; }; +template +struct LLUnitStrict : public LLUnit +{ + typedef LLUnitStrict self_t; + + explicit LLUnitStrict(storage_t value = storage_t()) + : LLUnit(value) + {} + + template + LLUnitStrict(LLUnit other) + : LLUnit(convert(other)) + {} + + LLUnitStrict(self_t& other) + : LLUnit(other) + {} + + +private: + operator storage_t() const + { + return value(); + } +}; + // // operator + // @@ -221,7 +279,8 @@ LLUnit operator * (LLUnit firs template void operator * (LLUnit, LLUnit) { - llstatic_assert(sizeof(STORAGE_TYPE1) == false, "Multiplication of unit types results in new unit type - not supported."); + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); } // @@ -242,7 +301,8 @@ LLUnit operator / (LLUnit firs template void operator / (LLUnit, LLUnit) { - llstatic_assert(sizeof(STORAGE_TYPE1) == false, "Multiplication of unit types results in new unit type - not supported."); + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); } #define COMPARISON_OPERATORS(op) \ @@ -273,21 +333,21 @@ COMPARISON_OPERATORS(!=) namespace LLUnits { -#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor)\ -struct unit_name \ -{ \ - typedef base_unit_name base_unit_t; \ -}; \ -template<> \ -struct ConversionFactor \ -{ \ - static F64 get() { return (conversion_factor); } \ -}; \ - \ -template<> \ -struct ConversionFactor \ -{ \ - static F64 get() { return 1.0 / (conversion_factor); } \ +#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor) \ +struct unit_name \ +{ \ + typedef base_unit_name base_unit_t; \ +}; \ +template \ +struct ConversionFactor \ +{ \ + static typename HighestPrecisionType::type_t get() { return typename HighestPrecisionType::type_t(conversion_factor); } \ +}; \ + \ +template \ +struct ConversionFactor \ +{ \ + static typename HighestPrecisionType::type_t get() { return typename HighestPrecisionType::type_t(1.0 / (conversion_factor)); } \ } struct Bytes { typedef Bytes base_unit_t; }; @@ -302,16 +362,19 @@ LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); struct Seconds { typedef Seconds base_unit_t; }; LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); -LL_DECLARE_DERIVED_UNIT(Seconds, Days, 60 * 60 * 24); -LL_DECLARE_DERIVED_UNIT(Seconds, Weeks, 60 * 60 * 24 * 7); LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.0 / 1000.0)); LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.0 / (1000000.0))); LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.0 / (1000000000.0))); struct Meters { typedef Meters base_unit_t; }; LL_DECLARE_DERIVED_UNIT(Meters, Kilometers, 1000); -LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, (1.0 / 100)); -LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, (1.0 / 1000)); +LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, (1.0 / 100.0)); +LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, (1.0 / 1000.0)); + +struct Hertz { typedef Hertz base_unit_t; }; +LL_DECLARE_DERIVED_UNIT(Hertz, Kilohertz, 1000); +LL_DECLARE_DERIVED_UNIT(Hertz, Megahertz, 1000 * 1000); +LL_DECLARE_DERIVED_UNIT(Hertz, Gigahertz, 1000 * 1000 * 1000); } #endif // LL_LLUNIT_H -- cgit v1.2.3 From c76ed72c609b80b08df6cebd68274c9da6d3de2c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 12 Nov 2012 19:12:20 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system removed remnants of LLFastTimer::FrameState --- indra/llcommon/llfasttimer.cpp | 16 ++++++---------- indra/llcommon/llfasttimer.h | 16 ---------------- 2 files changed, 6 insertions(+), 26 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index c4839fed77..66452fd02a 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -140,15 +140,6 @@ U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer } #endif -LLFastTimer::FrameState::FrameState() -: mActiveCount(0), - mCalls(0), - mSelfTimeCounter(0), - mLastCaller(NULL), - mMoveUpTree(false) -{} - - LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open, DeclareTimer* parent) : mName(name), mCollapsed(true), @@ -156,7 +147,12 @@ LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open, Decl mTreeTimeCounter(0), mCountAverage(0), mCallAverage(0), - mNeedsSorting(false) + mNeedsSorting(false), + mActiveCount(0), + mCalls(0), + mSelfTimeCounter(0), + mLastCaller(NULL), + mMoveUpTree(false) { setCollapsed(!open); diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 31872e4e65..40c2af34e8 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -38,25 +38,9 @@ class LLMutex; #define LL_FASTTIMER_USE_RDTSC 1 - -LL_COMMON_API void assert_main_thread(); - class LL_COMMON_API LLFastTimer { public: - class DeclareTimer; - struct LL_COMMON_API FrameState - { - FrameState(); - - U32 mSelfTimeCounter; - U32 mTotalTimeCounter; - U32 mCalls; - DeclareTimer* mLastCaller; // used to bootstrap tree construction - U16 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - }; - // stores a "named" timer instance to be reused via multiple LLFastTimer stack instances class LL_COMMON_API DeclareTimer : public LLInstanceTracker -- cgit v1.2.3 From 67ec47e6da389661934ed2ddfa55ca58455fa7e5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 13 Nov 2012 17:10:10 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system moving fast timers into lltrace namespace and accumulation system --- indra/llcommon/llfasttimer.cpp | 186 ++++++++++++++------------ indra/llcommon/llfasttimer.h | 268 ++++++++++++++++++++------------------ indra/llcommon/lltrace.cpp | 7 +- indra/llcommon/lltrace.h | 194 +++------------------------ indra/llcommon/lltracerecording.h | 18 +-- indra/llcommon/llunit.h | 84 ++++++------ 6 files changed, 322 insertions(+), 435 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 66452fd02a..cced0bdfa9 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -33,8 +33,10 @@ #include "lltreeiterators.h" #include "llsdserialize.h" #include "llunit.h" +#include "llsd.h" #include +#include #if LL_WINDOWS @@ -50,37 +52,40 @@ #error "architecture not supported" #endif +namespace LLTrace +{ + ////////////////////////////////////////////////////////////////////////////// // statics -S32 LLFastTimer::sCurFrameIndex = -1; -S32 LLFastTimer::sLastFrameIndex = -1; -U64 LLFastTimer::sLastFrameTime = LLFastTimer::getCPUClockCount64(); -bool LLFastTimer::sPauseHistory = 0; -bool LLFastTimer::sResetHistory = 0; -LLFastTimer::CurTimerData LLFastTimer::sCurTimerData; -BOOL LLFastTimer::sLog = FALSE; -std::string LLFastTimer::sLogName = ""; -BOOL LLFastTimer::sMetricLog = FALSE; -LLMutex* LLFastTimer::sLogLock = NULL; -std::queue LLFastTimer::sLogQueue; +S32 Time::sCurFrameIndex = -1; +S32 Time::sLastFrameIndex = -1; +U64 Time::sLastFrameTime = Time::getCPUClockCount64(); +bool Time::sPauseHistory = 0; +bool Time::sResetHistory = 0; +LLThreadLocalPointer Time::sCurTimerData; +bool Time::sLog = FALSE; +std::string Time::sLogName = ""; +bool Time::sMetricLog = FALSE; +static LLMutex* sLogLock = NULL; +static std::queue sLogQueue; #if LL_LINUX || LL_SOLARIS -U64 LLFastTimer::sClockResolution = 1000000000; // Nanosecond resolution +U64 Time::sClockResolution = 1000000000; // Nanosecond resolution #else -U64 LLFastTimer::sClockResolution = 1000000; // Microsecond resolution +U64 Time::sClockResolution = 1000000; // Microsecond resolution #endif // FIXME: move these declarations to the relevant modules // helper functions -typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; +typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; -static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(LLFastTimer::DeclareTimer& id) +static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(BlockTimer& id) { return timer_tree_bottom_up_iterator_t(&id, - boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&BlockTimer::beginChildren), _1), + boost::bind(boost::mem_fn(&BlockTimer::endChildren), _1)); } static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() @@ -88,14 +93,14 @@ static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() return timer_tree_bottom_up_iterator_t(); } -typedef LLTreeDFSIter timer_tree_dfs_iterator_t; +typedef LLTreeDFSIter timer_tree_dfs_iterator_t; -static timer_tree_dfs_iterator_t begin_timer_tree(LLFastTimer::DeclareTimer& id) +static timer_tree_dfs_iterator_t begin_timer_tree(BlockTimer& id) { return timer_tree_dfs_iterator_t(&id, - boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&LLFastTimer::DeclareTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&BlockTimer::beginChildren), _1), + boost::bind(boost::mem_fn(&BlockTimer::endChildren), _1)); } static timer_tree_dfs_iterator_t end_timer_tree() @@ -103,21 +108,21 @@ static timer_tree_dfs_iterator_t end_timer_tree() return timer_tree_dfs_iterator_t(); } -LLFastTimer::DeclareTimer& LLFastTimer::DeclareTimer::getRootTimer() +BlockTimer& BlockTimer::getRootTimer() { - static DeclareTimer root_timer("root", true, NULL); + static BlockTimer root_timer("root", true, NULL); return root_timer; } //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer +U64 Time::countsPerSecond() // counts per second for the *32-bit* timer { return sClockResolution >> 8; } #else // windows or x86-mac or x86-linux or x86-solaris -U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer +U64 Time::countsPerSecond() // counts per second for the *32-bit* timer { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz @@ -140,19 +145,14 @@ U64 LLFastTimer::countsPerSecond() // counts per second for the *32-bit* timer } #endif -LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open, DeclareTimer* parent) -: mName(name), +BlockTimer::BlockTimer(const char* name, bool open, BlockTimer* parent) +: TraceType(name), mCollapsed(true), mParent(NULL), mTreeTimeCounter(0), mCountAverage(0), mCallAverage(0), - mNeedsSorting(false), - mActiveCount(0), - mCalls(0), - mSelfTimeCounter(0), - mLastCaller(NULL), - mMoveUpTree(false) + mNeedsSorting(false) { setCollapsed(!open); @@ -171,13 +171,13 @@ LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name, bool open, Decl memset(mCallHistory, 0, sizeof(U32) * HISTORY_NUM); } -LLFastTimer::DeclareTimer::~DeclareTimer() +BlockTimer::~BlockTimer() { delete[] mCountHistory; delete[] mCallHistory; } -void LLFastTimer::DeclareTimer::setParent(DeclareTimer* parent) +void BlockTimer::setParent(BlockTimer* parent) { llassert_always(parent != this); llassert_always(parent != NULL); @@ -193,8 +193,8 @@ void LLFastTimer::DeclareTimer::setParent(DeclareTimer* parent) // subtract average timing from previous parent mParent->mCountAverage -= mCountAverage; - std::vector& children = mParent->getChildren(); - std::vector::iterator found_it = std::find(children.begin(), children.end(), this); + std::vector& children = mParent->getChildren(); + std::vector::iterator found_it = std::find(children.begin(), children.end(), this); if (found_it != children.end()) { children.erase(found_it); @@ -209,10 +209,10 @@ void LLFastTimer::DeclareTimer::setParent(DeclareTimer* parent) } } -S32 LLFastTimer::DeclareTimer::getDepth() +S32 BlockTimer::getDepth() { S32 depth = 0; - DeclareTimer* timerp = mParent; + BlockTimer* timerp = mParent; while(timerp) { depth++; @@ -223,9 +223,9 @@ S32 LLFastTimer::DeclareTimer::getDepth() } // static -void LLFastTimer::DeclareTimer::processTimes() +void BlockTimer::processTimes() { - if (sCurFrameIndex < 0) return; + if (Time::getCurFrameIndex() < 0) return; buildHierarchy(); accumulateTimings(); @@ -234,27 +234,27 @@ void LLFastTimer::DeclareTimer::processTimes() // sort child timers by name struct SortTimerByName { - bool operator()(const LLFastTimer::DeclareTimer* i1, const LLFastTimer::DeclareTimer* i2) + bool operator()(const BlockTimer* i1, const BlockTimer* i2) { return i1->getName() < i2->getName(); } }; //static -void LLFastTimer::DeclareTimer::buildHierarchy() +void BlockTimer::buildHierarchy() { - if (sCurFrameIndex < 0 ) return; + if (Time::getCurFrameIndex() < 0 ) return; // set up initial tree { - for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; ++it) { - DeclareTimer& timer = *it; - if (&timer == &DeclareTimer::getRootTimer()) continue; + BlockTimer& timer = *it; + if (&timer == &BlockTimer::getRootTimer()) continue; // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.mLastCaller && timer.mParent == &DeclareTimer::getRootTimer()) + if (timer.mLastCaller && timer.mParent == &BlockTimer::getRootTimer()) { timer.setParent(timer.mLastCaller); // no need to push up tree on first use, flag can be set spuriously @@ -266,13 +266,13 @@ void LLFastTimer::DeclareTimer::buildHierarchy() // bump timers up tree if they've been flagged as being in the wrong place // do this in a bottom up order to promote descendants first before promoting ancestors // this preserves partial order derived from current frame's observations - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(DeclareTimer::getRootTimer()); + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(BlockTimer::getRootTimer()); it != end_timer_tree_bottom_up(); ++it) { - DeclareTimer* timerp = *it; + BlockTimer* timerp = *it; // skip root timer - if (timerp == &DeclareTimer::getRootTimer()) continue; + if (timerp == &BlockTimer::getRootTimer()) continue; if (timerp->mMoveUpTree) { @@ -289,11 +289,11 @@ void LLFastTimer::DeclareTimer::buildHierarchy() } // sort timers by time last called, so call graph makes sense - for(timer_tree_dfs_iterator_t it = begin_timer_tree(DeclareTimer::getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(BlockTimer::getRootTimer()); it != end_timer_tree(); ++it) { - DeclareTimer* timerp = (*it); + BlockTimer* timerp = (*it); if (timerp->mNeedsSorting) { std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); @@ -303,12 +303,12 @@ void LLFastTimer::DeclareTimer::buildHierarchy() } //static -void LLFastTimer::DeclareTimer::accumulateTimings() +void BlockTimer::accumulateTimings() { U32 cur_time = getCPUClockCount32(); // walk up stack of active timers and accumulate current time while leaving timing structures active - LLFastTimer* cur_timer = sCurTimerData.mCurTimer; + Time* cur_timer = sCurTimerData.mCurTimer; // root defined by parent pointing to self CurTimerData* cur_data = &sCurTimerData; while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) @@ -328,11 +328,11 @@ void LLFastTimer::DeclareTimer::accumulateTimings() } // traverse tree in DFS post order, or bottom up - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(DeclareTimer::getRootTimer()); + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(BlockTimer::getRootTimer()); it != end_timer_tree_bottom_up(); ++it) { - DeclareTimer* timerp = (*it); + BlockTimer* timerp = (*it); timerp->mTreeTimeCounter = timerp->mSelfTimeCounter; for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) { @@ -354,7 +354,7 @@ void LLFastTimer::DeclareTimer::accumulateTimings() } // static -void LLFastTimer::DeclareTimer::resetFrame() +void BlockTimer::resetFrame() { if (sLog) { //output current frame counts to performance log @@ -379,7 +379,7 @@ void LLFastTimer::DeclareTimer::resetFrame() { for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - DeclareTimer& timer = *it; + BlockTimer& timer = *it; sd[timer.getName()]["Time"] = (LLSD::Real) (timer.mSelfTimeCounter*iclock_freq); sd[timer.getName()]["Calls"] = (LLSD::Integer) timer.mCalls; @@ -401,7 +401,7 @@ void LLFastTimer::DeclareTimer::resetFrame() // reset for next frame for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - DeclareTimer& timer = *it; + BlockTimer& timer = *it; timer.mSelfTimeCounter = 0; timer.mCalls = 0; timer.mLastCaller = NULL; @@ -410,7 +410,7 @@ void LLFastTimer::DeclareTimer::resetFrame() } //static -void LLFastTimer::DeclareTimer::reset() +void BlockTimer::reset() { resetFrame(); // reset frame data @@ -420,7 +420,7 @@ void LLFastTimer::DeclareTimer::reset() // root defined by parent pointing to self CurTimerData* cur_data = &sCurTimerData; - LLFastTimer* cur_timer = cur_data->mCurTimer; + Time* cur_timer = cur_data->mCurTimer; while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { cur_timer->mStartTime = cur_time; @@ -434,10 +434,10 @@ void LLFastTimer::DeclareTimer::reset() { for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) { - DeclareTimer& timer = *it; - if (&timer != &DeclareTimer::getRootTimer()) + BlockTimer& timer = *it; + if (&timer != &BlockTimer::getRootTimer()) { - timer.setParent(&DeclareTimer::getRootTimer()); + timer.setParent(&BlockTimer::getRootTimer()); } timer.mCountAverage = 0; @@ -451,35 +451,35 @@ void LLFastTimer::DeclareTimer::reset() sCurFrameIndex = 0; } -U32 LLFastTimer::DeclareTimer::getHistoricalCount(S32 history_index) const +U32 BlockTimer::getHistoricalCount(S32 history_index) const { - S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::DeclareTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % BlockTimer::HISTORY_NUM; return mCountHistory[history_idx]; } -U32 LLFastTimer::DeclareTimer::getHistoricalCalls(S32 history_index ) const +U32 BlockTimer::getHistoricalCalls(S32 history_index ) const { - S32 history_idx = (getLastFrameIndex() + history_index) % LLFastTimer::DeclareTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % BlockTimer::HISTORY_NUM; return mCallHistory[history_idx]; } -std::vector::const_iterator LLFastTimer::DeclareTimer::beginChildren() +std::vector::const_iterator BlockTimer::beginChildren() { return mChildren.begin(); } -std::vector::const_iterator LLFastTimer::DeclareTimer::endChildren() +std::vector::const_iterator BlockTimer::endChildren() { return mChildren.end(); } -std::vector& LLFastTimer::DeclareTimer::getChildren() +std::vector& BlockTimer::getChildren() { return mChildren; } //static -void LLFastTimer::nextFrame() +void Time::nextFrame() { countsPerSecond(); // good place to calculate clock frequency U64 frame_time = getCPUClockCount64(); @@ -490,30 +490,30 @@ void LLFastTimer::nextFrame() if (!sPauseHistory) { - DeclareTimer::processTimes(); + BlockTimer::processTimes(); sLastFrameIndex = sCurFrameIndex++; } // get ready for next frame - DeclareTimer::resetFrame(); + BlockTimer::resetFrame(); sLastFrameTime = frame_time; } //static -void LLFastTimer::dumpCurTimes() +void Time::dumpCurTimes() { // accumulate timings, etc. - DeclareTimer::processTimes(); + BlockTimer::processTimes(); F64 clock_freq = (F64)countsPerSecond(); F64 iclock_freq = 1000.0 / clock_freq; // clock_ticks -> milliseconds // walk over timers in depth order and output timings - for(timer_tree_dfs_iterator_t it = begin_timer_tree(DeclareTimer::getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(BlockTimer::getRootTimer()); it != end_timer_tree(); ++it) { - DeclareTimer* timerp = (*it); + BlockTimer* timerp = (*it); F64 total_time_ms = ((F64)timerp->getHistoricalCount(0) * iclock_freq); // Don't bother with really brief times, keep output concise if (total_time_ms < 0.1) continue; @@ -534,14 +534,14 @@ void LLFastTimer::dumpCurTimes() } //static -void LLFastTimer::reset() +void Time::reset() { - DeclareTimer::reset(); + BlockTimer::reset(); } //static -void LLFastTimer::writeLog(std::ostream& os) +void Time::writeLog(std::ostream& os) { while (!sLogQueue.empty()) { @@ -552,3 +552,25 @@ void LLFastTimer::writeLog(std::ostream& os) } } + +void LLTrace::TimerAccumulator::addSamples( const LLTrace::TimerAccumulator& other ) +{ + mSelfTimeCounter += other.mSelfTimeCounter; + mTotalTimeCounter += other.mTotalTimeCounter; + mCalls += other.mCalls; + if (!mLastCaller) + { + mLastCaller = other.mLastCaller; + } + + //mActiveCount stays the same; + mMoveUpTree |= other.mMoveUpTree; +} + +void LLTrace::TimerAccumulator::reset( const LLTrace::TimerAccumulator* other ) +{ + mTotalTimeCounter = 0; + mSelfTimeCounter = 0; + mCalls = 0; +} +} diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 40c2af34e8..f5e6d874a2 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -33,131 +33,26 @@ class LLMutex; -#include -#include "llsd.h" +#include "lltrace.h" #define LL_FASTTIMER_USE_RDTSC 1 -class LL_COMMON_API LLFastTimer +namespace LLTrace { -public: - // stores a "named" timer instance to be reused via multiple LLFastTimer stack instances - class LL_COMMON_API DeclareTimer - : public LLInstanceTracker - { - public: - DeclareTimer(const std::string& name, bool open = false, DeclareTimer* parent = &getRootTimer()); - ~DeclareTimer(); - - enum { HISTORY_NUM = 300 }; - - const std::string& getName() const { return mName; } - DeclareTimer* getParent() const { return mParent; } - void setParent(DeclareTimer* parent); - S32 getDepth(); - - typedef std::vector::const_iterator child_const_iter; - child_const_iter beginChildren(); - child_const_iter endChildren(); - std::vector& getChildren(); - - void setCollapsed(bool collapsed) { mCollapsed = collapsed; } - bool getCollapsed() const { return mCollapsed; } - - U32 getCountAverage() const { return mCountAverage; } - U32 getCallAverage() const { return mCallAverage; } - - U32 getHistoricalCount(S32 history_index = 0) const; - U32 getHistoricalCalls(S32 history_index = 0) const; - - static DeclareTimer& getRootTimer(); - - private: - friend class LLFastTimer; - - // recursive call to gather total time from children - static void accumulateTimings(); - - // updates cumulative times and hierarchy, - // can be called multiple times in a frame, at any point - static void processTimes(); - - static void buildHierarchy(); - static void resetFrame(); - static void reset(); - - // - // members - // - U32 mSelfTimeCounter; - U32 mTotalTimeCounter; - U32 mCalls; - DeclareTimer* mLastCaller; // used to bootstrap tree construction - U16 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - - std::string mName; - - // sum of recored self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete - U32 mTreeTimeCounter; - - U32 mCountAverage; - U32 mCallAverage; - - U32* mCountHistory; - U32* mCallHistory; - - // tree structure - DeclareTimer* mParent; // DeclareTimer of caller(parent) - std::vector mChildren; - bool mCollapsed; // don't show children - bool mNeedsSorting; // sort children whenever child added - }; +class Time +{ public: - LL_FORCE_INLINE LLFastTimer(LLFastTimer::DeclareTimer& timer) - { -#if FAST_TIMER_ON - mStartTime = getCPUClockCount32(); - - timer.mActiveCount++; - timer.mCalls++; - // keep current parent as long as it is active when we are - timer.mMoveUpTree |= (timer.mParent->mActiveCount == 0); - - LLFastTimer::CurTimerData* cur_timer_data = &LLFastTimer::sCurTimerData; - mLastTimerData = *cur_timer_data; - cur_timer_data->mCurTimer = this; - cur_timer_data->mTimerData = &timer; - cur_timer_data->mChildTime = 0; -#endif - } - - LL_FORCE_INLINE ~LLFastTimer() - { -#if FAST_TIMER_ON - U32 total_time = getCPUClockCount32() - mStartTime; - DeclareTimer* timer_data = LLFastTimer::sCurTimerData.mTimerData; - timer_data->mSelfTimeCounter += total_time - LLFastTimer::sCurTimerData.mChildTime; - timer_data->mTotalTimeCounter += total_time; - timer_data->mActiveCount--; - - // store last caller to bootstrap tree creation - // do this in the destructor in case of recursion to get topmost caller - timer_data->mLastCaller = mLastTimerData.mTimerData; - - // we are only tracking self time, so subtract our total time delta from parents - mLastTimerData.mChildTime += total_time; + typedef Time self_t; + typedef class BlockTimer DeclareTimer; - LLFastTimer::sCurTimerData = mLastTimerData; -#endif - } +public: + Time(BlockTimer& timer); + ~Time(); public: - static LLMutex* sLogLock; - static std::queue sLogQueue; - static BOOL sLog; - static BOOL sMetricLog; + static bool sLog; + static bool sMetricLog; static std::string sLogName; static bool sPauseHistory; static bool sResetHistory; @@ -180,11 +75,11 @@ public: struct CurTimerData { - LLFastTimer* mCurTimer; - DeclareTimer* mTimerData; - U32 mChildTime; + Time* mCurTimer; + BlockTimer* mTimerData; + U64 mChildTime; }; - static CurTimerData sCurTimerData; + static LLThreadLocalPointer sCurTimerData; private: @@ -211,14 +106,14 @@ private: //#undef _interlockedbittestandset //#undef _interlockedbittestandreset - //inline U32 LLFastTimer::getCPUClockCount32() + //inline U32 Time::getCPUClockCount32() //{ // U64 time_stamp = __rdtsc(); // return (U32)(time_stamp >> 8); //} // //// return full timer value, *not* shifted by 8 bits - //inline U64 LLFastTimer::getCPUClockCount64() + //inline U64 Time::getCPUClockCount64() //{ // return __rdtsc(); //} @@ -258,7 +153,7 @@ private: } #else - //LL_COMMON_API U64 get_clock_count(); // in lltimer.cpp + //U64 get_clock_count(); // in lltimer.cpp // These use QueryPerformanceCounter, which is arguably fine and also works on AMD architectures. static U32 getCPUClockCount32() { @@ -330,10 +225,131 @@ private: static S32 sLastFrameIndex; static U64 sLastFrameTime; - U32 mStartTime; - LLFastTimer::CurTimerData mLastTimerData; + U64 mStartTime; + Time::CurTimerData mLastTimerData; +}; + +struct TimerAccumulator +{ + void addSamples(const TimerAccumulator& other); + void reset(const TimerAccumulator* other); + + // + // members + // + U64 mSelfTimeCounter, + mTotalTimeCounter; + U32 mCalls; + BlockTimer* mLastCaller; // used to bootstrap tree construction + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame +}; + +// stores a "named" timer instance to be reused via multiple Time stack instances +class BlockTimer +: public TraceType, + public LLInstanceTracker +{ +public: + BlockTimer(const char* name, bool open = false, BlockTimer* parent = &getRootTimer()); + ~BlockTimer(); + + enum { HISTORY_NUM = 300 }; + + BlockTimer* getParent() const { return mParent; } + void setParent(BlockTimer* parent); + S32 getDepth(); + + typedef std::vector::const_iterator child_const_iter; + child_const_iter beginChildren(); + child_const_iter endChildren(); + std::vector& getChildren(); + + void setCollapsed(bool collapsed) { mCollapsed = collapsed; } + bool getCollapsed() const { return mCollapsed; } + + U32 getCountAverage() const { return mCountAverage; } + U32 getCallAverage() const { return mCallAverage; } + + U32 getHistoricalCount(S32 history_index = 0) const; + U32 getHistoricalCalls(S32 history_index = 0) const; + + static BlockTimer& getRootTimer(); + +private: + friend class Time; + + // recursive call to gather total time from children + static void accumulateTimings(); + + // updates cumulative times and hierarchy, + // can be called multiple times in a frame, at any point + static void processTimes(); + + static void buildHierarchy(); + static void resetFrame(); + static void reset(); + + // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete + U32 mTreeTimeCounter; + + U32 mCountAverage; + U32 mCallAverage; + + U32* mCountHistory; + U32* mCallHistory; + + // tree structure + BlockTimer* mParent; // BlockTimer of caller(parent) + std::vector mChildren; + bool mCollapsed; // don't show children + bool mNeedsSorting; // sort children whenever child added }; -typedef class LLFastTimer LLFastTimer; +LL_FORCE_INLINE Time::Time(BlockTimer& timer) +{ +#if FAST_TIMER_ON + mStartTime = getCPUClockCount64(); + + TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); + accumulator.mActiveCount++; + accumulator.mCalls++; + // keep current parent as long as it is active when we are + accumulator.mMoveUpTree |= (timer.mParent->getPrimaryAccumulator().mActiveCount == 0); + + CurTimerData* cur_timer_data = Time::sCurTimerData.get(); + // store top of stack + mLastTimerData = *cur_timer_data; + // push new information + cur_timer_data->mCurTimer = this; + cur_timer_data->mTimerData = &timer; + cur_timer_data->mChildTime = 0; +#endif +} + +LL_FORCE_INLINE Time::~Time() +{ +#if FAST_TIMER_ON + U64 total_time = getCPUClockCount64() - mStartTime; + CurTimerData* cur_timer_data = Time::sCurTimerData.get(); + TimerAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; + accumulator.mTotalTimeCounter += total_time; + accumulator.mActiveCount--; + + // store last caller to bootstrap tree creation + // do this in the destructor in case of recursion to get topmost caller + accumulator.mLastCaller = mLastTimerData.mTimerData; + + // we are only tracking self time, so subtract our total time delta from parents + mLastTimerData.mChildTime += total_time; + + *sCurTimerData = mLastTimerData; +#endif +} + +} + +typedef LLTrace::Time LLFastTimer; #endif // LL_LLFASTTIMER_H diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 3f605f2c74..afb175c398 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -28,6 +28,7 @@ #include "lltrace.h" #include "lltracerecording.h" #include "lltracethreadrecorder.h" +#include "llfasttimer.h" namespace LLTrace { @@ -37,13 +38,15 @@ static MasterThreadRecorder* gMasterThreadRecorder = NULL; void init() { gMasterThreadRecorder = new MasterThreadRecorder(); + Time::sCurTimerData = new Time::CurTimerData(); } void cleanup() { delete gMasterThreadRecorder; - LLUnitStrict seconds; gMasterThreadRecorder = NULL; + delete Time::sCurTimerData.get(); + Time::sCurTimerData = NULL; } MasterThreadRecorder& getMasterThreadRecorder() @@ -59,6 +62,4 @@ LLThreadLocalPointer& get_thread_recorder() } -BlockTimer::Recorder::StackEntry BlockTimer::sCurRecorder; - } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 549e407822..fb9dca5e84 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -32,7 +32,6 @@ #include "llmemory.h" #include "llrefcount.h" -//#include "lltracethreadrecorder.h" #include "llunit.h" #include "llapr.h" @@ -61,8 +60,8 @@ namespace LLTrace typedef LLUnit Microseconds; typedef LLUnit Nanoseconds; - typedef LLUnit Meters; - typedef LLUnit Kilometers; + typedef LLUnit Meters; + typedef LLUnit Kilometers; typedef LLUnit Centimeters; typedef LLUnit Millimeters; @@ -71,11 +70,11 @@ namespace LLTrace LLThreadLocalPointer& get_thread_recorder(); - class LL_COMMON_API MasterThreadRecorder& getMasterThreadRecorder(); + class MasterThreadRecorder& getMasterThreadRecorder(); // one per thread per type template - class LL_COMMON_API AccumulatorBuffer : public LLRefCount + class AccumulatorBuffer : public LLRefCount { static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; private: @@ -199,7 +198,7 @@ namespace LLTrace template LLThreadLocalPointer AccumulatorBuffer::sPrimaryStorage; template - class LL_COMMON_API TraceType + class TraceType : public LLInstanceTracker, std::string> { public: @@ -218,6 +217,9 @@ namespace LLTrace size_t getIndex() const { return mAccumulatorIndex; } + std::string& getName() { return mName; } + const std::string& getName() const { return mName; } + protected: std::string mName; std::string mDescription; @@ -225,7 +227,7 @@ namespace LLTrace }; template - class LL_COMMON_API MeasurementAccumulator + class MeasurementAccumulator { public: typedef T value_t; @@ -339,7 +341,7 @@ namespace LLTrace }; template - class LL_COMMON_API CountAccumulator + class CountAccumulator { public: typedef CountAccumulator self_t; @@ -378,11 +380,8 @@ namespace LLTrace U32 mNumSamples; }; - typedef TraceType > measurement_common_float_t; - typedef TraceType > measurement_common_int_t; - - template - class LL_COMMON_API Measurement + template + class Measurement : public TraceType::type_t> > { public: @@ -392,37 +391,16 @@ namespace LLTrace : TraceType(name, description) {} - void sample(T value) - { - getPrimaryAccumulator().sample((storage_t)value); - } - }; - - template - class LL_COMMON_API Measurement - : public TraceType::type_t> > - { - public: - typedef typename LLUnits::HighestPrecisionType::type_t storage_t; - - Measurement(const char* name, const char* description = NULL) - : TraceType(name, description) - {} - template void sample(UNIT_T value) { - T converted_value; - converted_value = value; - getPrimaryAccumulator().sample((storage_t)converted_value.value()); + T converted_value(value); + getPrimaryAccumulator().sample((storage_t)converted_value); } }; - typedef TraceType > count_common_float_t; - typedef TraceType > count_common_int_t; - - template - class LL_COMMON_API Count + template + class Count : public TraceType::type_t> > { public: @@ -432,148 +410,12 @@ namespace LLTrace : TraceType(name) {} - void add(T value) - { - getPrimaryAccumulator().add((storage_t)value); - } - }; - - template - class LL_COMMON_API Count - : public TraceType::type_t> > - { - public: - typedef typename LLUnits::HighestPrecisionType::type_t storage_t; - - Count(const char* name, const char* description = NULL) - : TraceType(name) - {} - template void add(UNIT_T value) { - T converted_value; - converted_value = value; - getPrimaryAccumulator().add((storage_t)converted_value.value()); - } - }; - - class LL_COMMON_API TimerAccumulator - { - public: - typedef TimerAccumulator self_t; - - U32 mTotalTimeCounter, - mChildTimeCounter, - mCalls; - - TimerAccumulator* mParent; // info for caller timer - TimerAccumulator* mLastCaller; // used to bootstrap tree construction - const class BlockTimer* mTimer; // points to block timer associated with this storage - U8 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - std::vector mChildren; // currently assumed child timers - - void addSamples(const TimerAccumulator& other) - { - mTotalTimeCounter += other.mTotalTimeCounter; - mChildTimeCounter += other.mChildTimeCounter; - mCalls += other.mCalls; - } - - void reset(const self_t* other) - { - mTotalTimeCounter = 0; - mChildTimeCounter = 0; - mCalls = 0; + T converted_value(value); + getPrimaryAccumulator().add((storage_t)converted_value); } - - }; - - class LL_COMMON_API BlockTimer : public TraceType - { - public: - BlockTimer(const char* name) - : TraceType(name) - {} - - struct Recorder - { - struct StackEntry - { - Recorder* mRecorder; - TimerAccumulator* mAccumulator; - U32 mChildTime; - }; - - LL_FORCE_INLINE Recorder(BlockTimer& block_timer) - : mLastRecorder(sCurRecorder) - { - mStartTime = getCPUClockCount32(); - TimerAccumulator* accumulator = &block_timer.getPrimaryAccumulator(); // get per-thread accumulator - accumulator->mActiveCount++; - accumulator->mCalls++; - accumulator->mMoveUpTree |= (accumulator->mParent->mActiveCount == 0); - - // push new timer on stack - sCurRecorder.mRecorder = this; - sCurRecorder.mAccumulator = accumulator; - sCurRecorder.mChildTime = 0; - } - - LL_FORCE_INLINE ~Recorder() - { - U32 total_time = getCPUClockCount32() - mStartTime; - - TimerAccumulator* accumulator = sCurRecorder.mAccumulator; - accumulator->mTotalTimeCounter += total_time; - accumulator->mChildTimeCounter += sCurRecorder.mChildTime; - accumulator->mActiveCount--; - - accumulator->mLastCaller = mLastRecorder.mAccumulator; - mLastRecorder.mChildTime += total_time; - - // pop stack - sCurRecorder = mLastRecorder; - } - - StackEntry mLastRecorder; - U32 mStartTime; - }; - - private: - static U32 getCPUClockCount32() - { - U32 ret_val; - __asm - { - _emit 0x0f - _emit 0x31 - shr eax,8 - shl edx,24 - or eax, edx - mov dword ptr [ret_val], eax - } - return ret_val; - } - - // return full timer value, *not* shifted by 8 bits - static U64 getCPUClockCount64() - { - U64 ret_val; - __asm - { - _emit 0x0f - _emit 0x31 - mov eax,eax - mov edx,edx - mov dword ptr [ret_val+4], edx - mov dword ptr [ret_val], eax - } - return ret_val; - } - - static Recorder::StackEntry sCurRecorder; }; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 16b80fd1d8..4dcadfdf29 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -120,7 +120,7 @@ namespace LLTrace F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; template - T getSum(const Count& stat) const + T getSum(const Count& stat) const { return (T)getSum(static_cast::type_t> >&> (stat)); } @@ -128,7 +128,7 @@ namespace LLTrace F64 getPerSec(const TraceType >& stat) const; F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const Count& stat) const + T getPerSec(const Count& stat) const { return (T)getPerSec(static_cast::type_t> >&> (stat)); } @@ -141,7 +141,7 @@ namespace LLTrace F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; template - T getSum(const Measurement& stat) const + T getSum(const Measurement& stat) const { return (T)getSum(static_cast::type_t> >&> (stat)); } @@ -149,7 +149,7 @@ namespace LLTrace F64 getPerSec(const TraceType >& stat) const; F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const Measurement& stat) const + T getPerSec(const Measurement& stat) const { return (T)getPerSec(static_cast::type_t> >&> (stat)); } @@ -157,7 +157,7 @@ namespace LLTrace F64 getMin(const TraceType >& stat) const; S64 getMin(const TraceType >& stat) const; template - T getMin(const Measurement& stat) const + T getMin(const Measurement& stat) const { return (T)getMin(static_cast::type_t> >&> (stat)); } @@ -165,7 +165,7 @@ namespace LLTrace F64 getMax(const TraceType >& stat) const; S64 getMax(const TraceType >& stat) const; template - T getMax(const Measurement& stat) const + T getMax(const Measurement& stat) const { return (T)getMax(static_cast::type_t> >&> (stat)); } @@ -173,7 +173,7 @@ namespace LLTrace F64 getMean(const TraceType >& stat) const; F64 getMean(const TraceType >& stat) const; template - T getMean(Measurement& stat) const + T getMean(Measurement& stat) const { return (T)getMean(static_cast::type_t> >&> (stat)); } @@ -181,7 +181,7 @@ namespace LLTrace F64 getStandardDeviation(const TraceType >& stat) const; F64 getStandardDeviation(const TraceType >& stat) const; template - T getStandardDeviation(const Measurement& stat) const + T getStandardDeviation(const Measurement& stat) const { return (T)getMean(static_cast::type_t> >&> (stat)); } @@ -189,7 +189,7 @@ namespace LLTrace F64 getLastValue(const TraceType >& stat) const; S64 getLastValue(const TraceType >& stat) const; template - T getLastValue(const Measurement& stat) const + T getLastValue(const Measurement& stat) const { return (T)getLastValue(static_cast::type_t> >&> (stat)); } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 54ba1d67db..4ac2197c11 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -209,26 +209,26 @@ private: // // operator + // -template -LLUnit operator + (LLUnit first, LLUnit second) +template +LLUnit operator + (LLUnit first, LLUnit second) { - LLUnit result(first); + LLUnit result(first); result += second; return result; } -template -LLUnit operator + (LLUnit first, SCALAR_TYPE second) +template +LLUnit operator + (LLUnit first, SCALAR_TYPE second) { - LLUnit result(first); + LLUnit result(first); result += second; return result; } -template -LLUnit operator + (SCALAR_TYPE first, LLUnit second) +template +LLUnit operator + (SCALAR_TYPE first, LLUnit second) { - LLUnit result(first); + LLUnit result(first); result += second; return result; } @@ -236,27 +236,27 @@ LLUnit operator + (SCALAR_TYPE first, LLUnit -LLUnit operator - (LLUnit first, LLUnit second) +template +LLUnit operator - (LLUnit first, LLUnit second) { - LLUnit result(first); + LLUnit result(first); result -= second; return result; } -template -LLUnit operator - (LLUnit first, SCALAR_TYPE second) +template +LLUnit operator - (LLUnit first, SCALAR_TYPE second) { - LLUnit result(first); + LLUnit result(first); result -= second; return result; } -template -LLUnit operator - (SCALAR_TYPE first, LLUnit second) +template +LLUnit operator - (SCALAR_TYPE first, LLUnit second) { - LLUnit result(first); + LLUnit result(first); result -= second; return result; } @@ -264,20 +264,20 @@ LLUnit operator - (SCALAR_TYPE first, LLUnit -LLUnit operator * (SCALAR_TYPE first, LLUnit second) +template +LLUnit operator * (SCALAR_TYPE first, LLUnit second) { - return LLUnit(first * second.value()); + return LLUnit(first * second.value()); } -template -LLUnit operator * (LLUnit first, SCALAR_TYPE second) +template +LLUnit operator * (LLUnit first, SCALAR_TYPE second) { - return LLUnit(first.value() * second); + return LLUnit(first.value() * second); } -template -void operator * (LLUnit, LLUnit) +template +void operator * (LLUnit, LLUnit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); @@ -286,40 +286,40 @@ void operator * (LLUnit, LLUnit -SCALAR_TYPE operator / (SCALAR_TYPE first, LLUnit second) +template +SCALAR_TYPE operator / (SCALAR_TYPE first, LLUnit second) { return SCALAR_TYPE(first / second.value()); } -template -LLUnit operator / (LLUnit first, SCALAR_TYPE second) +template +LLUnit operator / (LLUnit first, SCALAR_TYPE second) { - return LLUnit(first.value() / second); + return LLUnit(first.value() / second); } -template -void operator / (LLUnit, LLUnit) +template +void operator / (LLUnit, LLUnit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); } #define COMPARISON_OPERATORS(op) \ -template \ -bool operator op (SCALAR_TYPE first, LLUnit second) \ +template \ +bool operator op (SCALAR_TYPE first, LLUnit second) \ { \ return first op second.value(); \ } \ \ -template \ -bool operator op (LLUnit first, SCALAR_TYPE second) \ +template \ +bool operator op (LLUnit first, SCALAR_TYPE second) \ { \ return first.value() op second; \ } \ \ -template \ -bool operator op (LLUnit first, LLUnit second) \ +template \ +bool operator op (LLUnit first, LLUnit second) \ { \ return first.value() op first.convert(second); \ } @@ -333,6 +333,12 @@ COMPARISON_OPERATORS(!=) namespace LLUnits { +template +struct HighestPrecisionType > +{ + typedef typename HighestPrecisionType::type_t type_t; +}; + #define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor) \ struct unit_name \ { \ -- cgit v1.2.3 From 9d77e030d9a0d23cebce616631677459eec1612c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 14 Nov 2012 23:52:27 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system cleaning up build moved most includes of windows.h to llwin32headers.h to disable min/max macros, etc streamlined Time class and consolidated functionality in BlockTimer class llfasttimer is no longer included via llstring.h, so had to add it manually in several places --- indra/llcommon/llapr.h | 12 +- indra/llcommon/lldate.cpp | 1 + indra/llcommon/llfasttimer.cpp | 120 ++++++++++--------- indra/llcommon/llfasttimer.h | 165 ++++++++++++--------------- indra/llcommon/llfile.cpp | 2 +- indra/llcommon/llfindlocale.cpp | 2 +- indra/llcommon/llinitparam.cpp | 1 + indra/llcommon/llinitparam.h | 1 + indra/llcommon/llmemory.cpp | 1 - indra/llcommon/llmetricperformancetester.cpp | 6 +- indra/llcommon/llmortician.h | 1 + indra/llcommon/llprocess.h | 3 +- indra/llcommon/llprocessor.cpp | 4 +- indra/llcommon/llsdparam.h | 1 + indra/llcommon/llstacktrace.cpp | 2 +- indra/llcommon/llstring.cpp | 5 +- indra/llcommon/llstring.h | 3 +- indra/llcommon/llsys.cpp | 5 +- indra/llcommon/lltimer.cpp | 6 +- indra/llcommon/lltrace.cpp | 6 +- indra/llcommon/lltrace.h | 22 +++- indra/llcommon/lltracerecording.h | 8 +- indra/llcommon/lltracethreadrecorder.cpp | 1 + indra/llcommon/llunit.h | 9 +- indra/llcommon/lluuid.cpp | 4 +- indra/llcommon/llwin32headers.h | 38 ++++++ indra/llcommon/llwin32headerslean.h | 37 ++++++ 27 files changed, 266 insertions(+), 200 deletions(-) create mode 100644 indra/llcommon/llwin32headers.h create mode 100644 indra/llcommon/llwin32headerslean.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 510725ffc6..c77d96c1c9 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -32,16 +32,6 @@ #if LL_LINUX || LL_SOLARIS #include // Need PATH_MAX in APR headers... #endif -#if LL_WINDOWS - // Limit Windows API to small and manageable set. - // If you get undefined symbols, find the appropriate - // Windows header file and include that in your .cpp file. - #define WIN32_LEAN_AND_MEAN - #include - #include - #undef min - #undef max -#endif #include @@ -340,7 +330,7 @@ public: LLThreadLocalPointer(const LLThreadLocalPointer& other) - : LLThreadLocalPointerBase(other) + : LLThreadLocalPointerBase(other) { set(other.get()); } diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp index 5569b4102d..2efe39e158 100644 --- a/indra/llcommon/lldate.cpp +++ b/indra/llcommon/lldate.cpp @@ -39,6 +39,7 @@ #include "lltimer.h" #include "llstring.h" +#include "llfasttimer.h" static const F64 DATE_EPOCH = 0.0; diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index cced0bdfa9..d007f76e5f 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -58,22 +58,22 @@ namespace LLTrace ////////////////////////////////////////////////////////////////////////////// // statics -S32 Time::sCurFrameIndex = -1; -S32 Time::sLastFrameIndex = -1; -U64 Time::sLastFrameTime = Time::getCPUClockCount64(); -bool Time::sPauseHistory = 0; -bool Time::sResetHistory = 0; -LLThreadLocalPointer Time::sCurTimerData; -bool Time::sLog = FALSE; -std::string Time::sLogName = ""; -bool Time::sMetricLog = FALSE; +S32 BlockTimer::sCurFrameIndex = -1; +S32 BlockTimer::sLastFrameIndex = -1; +U64 BlockTimer::sLastFrameTime = BlockTimer::getCPUClockCount64(); +bool BlockTimer::sPauseHistory = 0; +bool BlockTimer::sResetHistory = 0; +LLThreadLocalPointer BlockTimer::sCurTimerData; +bool BlockTimer::sLog = false; +std::string BlockTimer::sLogName = ""; +bool BlockTimer::sMetricLog = false; static LLMutex* sLogLock = NULL; static std::queue sLogQueue; #if LL_LINUX || LL_SOLARIS -U64 Time::sClockResolution = 1000000000; // Nanosecond resolution +U64 BlockTimer::sClockResolution = 1000000000; // Nanosecond resolution #else -U64 Time::sClockResolution = 1000000; // Microsecond resolution +U64 BlockTimer::sClockResolution = 1000000; // Microsecond resolution #endif // FIXME: move these declarations to the relevant modules @@ -114,15 +114,22 @@ BlockTimer& BlockTimer::getRootTimer() return root_timer; } +void BlockTimer::pushLog(LLSD log) +{ + LLMutexLock lock(sLogLock); + + sLogQueue.push(log); +} + //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -U64 Time::countsPerSecond() // counts per second for the *32-bit* timer +U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer { return sClockResolution >> 8; } #else // windows or x86-mac or x86-linux or x86-solaris -U64 Time::countsPerSecond() // counts per second for the *32-bit* timer +U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz @@ -225,7 +232,7 @@ S32 BlockTimer::getDepth() // static void BlockTimer::processTimes() { - if (Time::getCurFrameIndex() < 0) return; + if (getCurFrameIndex() < 0) return; buildHierarchy(); accumulateTimings(); @@ -243,7 +250,7 @@ struct SortTimerByName //static void BlockTimer::buildHierarchy() { - if (Time::getCurFrameIndex() < 0 ) return; + if (getCurFrameIndex() < 0 ) return; // set up initial tree { @@ -254,11 +261,11 @@ void BlockTimer::buildHierarchy() // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.mLastCaller && timer.mParent == &BlockTimer::getRootTimer()) + if (timer.getPrimaryAccumulator().mLastCaller && timer.mParent == &BlockTimer::getRootTimer()) { - timer.setParent(timer.mLastCaller); + timer.setParent(timer.getPrimaryAccumulator().mLastCaller); // no need to push up tree on first use, flag can be set spuriously - timer.mMoveUpTree = false; + timer.getPrimaryAccumulator().mMoveUpTree = false; } } } @@ -274,14 +281,14 @@ void BlockTimer::buildHierarchy() // skip root timer if (timerp == &BlockTimer::getRootTimer()) continue; - if (timerp->mMoveUpTree) + if (timerp->getPrimaryAccumulator().mMoveUpTree) { - // since ancestors have already been visited, reparenting won't affect tree traversal + // since ancestors have already been visited, re-parenting won't affect tree traversal //step up tree, bringing our descendants with us LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; timerp->setParent(timerp->getParent()->getParent()); - timerp->mMoveUpTree = false; + timerp->getPrimaryAccumulator().mMoveUpTree = false; // don't bubble up any ancestors until descendants are done bubbling up it.skipAncestors(); @@ -308,21 +315,23 @@ void BlockTimer::accumulateTimings() U32 cur_time = getCPUClockCount32(); // walk up stack of active timers and accumulate current time while leaving timing structures active - Time* cur_timer = sCurTimerData.mCurTimer; + Time* cur_timer = sCurTimerData->mCurTimer; // root defined by parent pointing to self - CurTimerData* cur_data = &sCurTimerData; + CurTimerData* cur_data = sCurTimerData.get(); + TimerAccumulator& accumulator = sCurTimerData->mTimerData->getPrimaryAccumulator(); while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { U32 cumulative_time_delta = cur_time - cur_timer->mStartTime; U32 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; - cur_data->mTimerData->mSelfTimeCounter += self_time_delta; - cur_data->mTimerData->mTotalTimeCounter += cumulative_time_delta; + accumulator.mSelfTimeCounter += self_time_delta; + accumulator.mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; cur_data = &cur_timer->mLastTimerData; cur_data->mChildTime += cumulative_time_delta; + accumulator = cur_data->mTimerData->getPrimaryAccumulator(); cur_timer = cur_timer->mLastTimerData.mCurTimer; } @@ -333,13 +342,14 @@ void BlockTimer::accumulateTimings() ++it) { BlockTimer* timerp = (*it); - timerp->mTreeTimeCounter = timerp->mSelfTimeCounter; + TimerAccumulator& accumulator = timerp->getPrimaryAccumulator(); + timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) { timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; } - S32 cur_frame = sCurFrameIndex; + S32 cur_frame = getCurFrameIndex(); if (cur_frame >= 0) { // update timer history @@ -347,8 +357,8 @@ void BlockTimer::accumulateTimings() timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); - timerp->mCallHistory[hidx] = timerp->mCalls; - timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + timerp->mCalls) / (cur_frame+1); + timerp->mCallHistory[hidx] = accumulator.mCalls; + timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + accumulator.mCalls) / (cur_frame+1); } } } @@ -377,15 +387,19 @@ void BlockTimer::resetFrame() LLSD sd; { - for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) { BlockTimer& timer = *it; - sd[timer.getName()]["Time"] = (LLSD::Real) (timer.mSelfTimeCounter*iclock_freq); - sd[timer.getName()]["Calls"] = (LLSD::Integer) timer.mCalls; + TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); + sd[timer.getName()]["Time"] = (LLSD::Real) (accumulator.mSelfTimeCounter*iclock_freq); + sd[timer.getName()]["Calls"] = (LLSD::Integer) accumulator.mCalls; // computing total time here because getting the root timer's getCountHistory // doesn't work correctly on the first frame - total_time = total_time + timer.mSelfTimeCounter * iclock_freq; + total_time = total_time + accumulator.mSelfTimeCounter * iclock_freq; } } @@ -399,13 +413,17 @@ void BlockTimer::resetFrame() } // reset for next frame - for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) { BlockTimer& timer = *it; - timer.mSelfTimeCounter = 0; - timer.mCalls = 0; - timer.mLastCaller = NULL; - timer.mMoveUpTree = false; + TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); + accumulator.mSelfTimeCounter = 0; + accumulator.mCalls = 0; + accumulator.mLastCaller = NULL; + accumulator.mMoveUpTree = false; } } @@ -419,7 +437,7 @@ void BlockTimer::reset() U32 cur_time = getCPUClockCount32(); // root defined by parent pointing to self - CurTimerData* cur_data = &sCurTimerData; + CurTimerData* cur_data = sCurTimerData.get(); Time* cur_timer = cur_data->mCurTimer; while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { @@ -432,7 +450,10 @@ void BlockTimer::reset() // reset all history { - for (instance_iter it = beginInstances(), end_it = endInstances(); it != end_it; ++it) + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) { BlockTimer& timer = *it; if (&timer != &BlockTimer::getRootTimer()) @@ -453,13 +474,13 @@ void BlockTimer::reset() U32 BlockTimer::getHistoricalCount(S32 history_index) const { - S32 history_idx = (getLastFrameIndex() + history_index) % BlockTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % HISTORY_NUM; return mCountHistory[history_idx]; } U32 BlockTimer::getHistoricalCalls(S32 history_index ) const { - S32 history_idx = (getLastFrameIndex() + history_index) % BlockTimer::HISTORY_NUM; + S32 history_idx = (getLastFrameIndex() + history_index) % HISTORY_NUM; return mCallHistory[history_idx]; } @@ -479,10 +500,10 @@ std::vector& BlockTimer::getChildren() } //static -void Time::nextFrame() +void BlockTimer::nextFrame() { - countsPerSecond(); // good place to calculate clock frequency - U64 frame_time = getCPUClockCount64(); + BlockTimer::countsPerSecond(); // good place to calculate clock frequency + U64 frame_time = BlockTimer::getCPUClockCount64(); if ((frame_time - sLastFrameTime) >> 8 > 0xffffffff) { llinfos << "Slow frame, fast timers inaccurate" << llendl; @@ -505,7 +526,7 @@ void Time::dumpCurTimes() // accumulate timings, etc. BlockTimer::processTimes(); - F64 clock_freq = (F64)countsPerSecond(); + F64 clock_freq = (F64)BlockTimer::countsPerSecond(); F64 iclock_freq = 1000.0 / clock_freq; // clock_ticks -> milliseconds // walk over timers in depth order and output timings @@ -533,13 +554,6 @@ void Time::dumpCurTimes() } } -//static -void Time::reset() -{ - BlockTimer::reset(); -} - - //static void Time::writeLog(std::ostream& os) { diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index f5e6d874a2..69a6773b12 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -28,60 +28,77 @@ #define LL_FASTTIMER_H #include "llinstancetracker.h" +#include "lltrace.h" #define FAST_TIMER_ON 1 +#define LL_FASTTIMER_USE_RDTSC 1 class LLMutex; -#include "lltrace.h" - -#define LL_FASTTIMER_USE_RDTSC 1 - namespace LLTrace { +struct CurTimerData +{ + class Time* mCurTimer; + class BlockTimer* mTimerData; + U64 mChildTime; +}; class Time { public: + friend class BlockTimer; typedef Time self_t; typedef class BlockTimer DeclareTimer; -public: Time(BlockTimer& timer); ~Time(); public: - static bool sLog; - static bool sMetricLog; - static std::string sLogName; - static bool sPauseHistory; - static bool sResetHistory; - - // call this once a frame to reset timers - static void nextFrame(); - // dumps current cumulative frame stats to log // call nextFrame() to reset timers static void dumpCurTimes(); - // call this to reset timer hierarchy, averages, etc. - static void reset(); + static void writeLog(std::ostream& os); - static U64 countsPerSecond(); - static S32 getLastFrameIndex() { return sLastFrameIndex; } - static S32 getCurFrameIndex() { return sCurFrameIndex; } +private: - static void writeLog(std::ostream& os); + U64 mStartTime; + CurTimerData mLastTimerData; +}; - struct CurTimerData - { - Time* mCurTimer; - BlockTimer* mTimerData; - U64 mChildTime; - }; - static LLThreadLocalPointer sCurTimerData; +// stores a "named" timer instance to be reused via multiple Time stack instances +class BlockTimer +: public TraceType, + public LLInstanceTracker +{ +public: + BlockTimer(const char* name, bool open = false, BlockTimer* parent = &getRootTimer()); + ~BlockTimer(); -private: + enum { HISTORY_NUM = 300 }; + + BlockTimer* getParent() const { return mParent; } + void setParent(BlockTimer* parent); + S32 getDepth(); + + typedef std::vector::const_iterator child_const_iter; + child_const_iter beginChildren(); + child_const_iter endChildren(); + std::vector& getChildren(); + + void setCollapsed(bool collapsed) { mCollapsed = collapsed; } + bool getCollapsed() const { return mCollapsed; } + + U32 getCountAverage() const { return mCountAverage; } + U32 getCallAverage() const { return mCallAverage; } + + U32 getHistoricalCount(S32 history_index = 0) const; + U32 getHistoricalCalls(S32 history_index = 0) const; + + static BlockTimer& getRootTimer(); + static void pushLog(LLSD sd); + friend class Time; ////////////////////////////////////////////////////////////////////////////// @@ -106,14 +123,14 @@ private: //#undef _interlockedbittestandset //#undef _interlockedbittestandreset - //inline U32 Time::getCPUClockCount32() + //inline U32 BlockTimer::getCPUClockCount32() //{ // U64 time_stamp = __rdtsc(); // return (U32)(time_stamp >> 8); //} // //// return full timer value, *not* shifted by 8 bits - //inline U64 Time::getCPUClockCount64() + //inline U64 BlockTimer::getCPUClockCount64() //{ // return __rdtsc(); //} @@ -220,64 +237,7 @@ private: #endif - static U64 sClockResolution; - static S32 sCurFrameIndex; - static S32 sLastFrameIndex; - static U64 sLastFrameTime; - - U64 mStartTime; - Time::CurTimerData mLastTimerData; -}; - -struct TimerAccumulator -{ - void addSamples(const TimerAccumulator& other); - void reset(const TimerAccumulator* other); - - // - // members - // - U64 mSelfTimeCounter, - mTotalTimeCounter; - U32 mCalls; - BlockTimer* mLastCaller; // used to bootstrap tree construction - U16 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame -}; - -// stores a "named" timer instance to be reused via multiple Time stack instances -class BlockTimer -: public TraceType, - public LLInstanceTracker -{ -public: - BlockTimer(const char* name, bool open = false, BlockTimer* parent = &getRootTimer()); - ~BlockTimer(); - - enum { HISTORY_NUM = 300 }; - - BlockTimer* getParent() const { return mParent; } - void setParent(BlockTimer* parent); - S32 getDepth(); - - typedef std::vector::const_iterator child_const_iter; - child_const_iter beginChildren(); - child_const_iter endChildren(); - std::vector& getChildren(); - - void setCollapsed(bool collapsed) { mCollapsed = collapsed; } - bool getCollapsed() const { return mCollapsed; } - - U32 getCountAverage() const { return mCountAverage; } - U32 getCallAverage() const { return mCallAverage; } - - U32 getHistoricalCount(S32 history_index = 0) const; - U32 getHistoricalCalls(S32 history_index = 0) const; - - static BlockTimer& getRootTimer(); - -private: - friend class Time; + static U64 countsPerSecond(); // recursive call to gather total time from children static void accumulateTimings(); @@ -289,6 +249,12 @@ private: static void buildHierarchy(); static void resetFrame(); static void reset(); + // call this once a frame to reset timers + static void nextFrame(); + static S32 getLastFrameIndex() { return sLastFrameIndex; } + static S32 getCurFrameIndex() { return sCurFrameIndex; } + + // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete U32 mTreeTimeCounter; @@ -304,12 +270,25 @@ private: std::vector mChildren; bool mCollapsed; // don't show children bool mNeedsSorting; // sort children whenever child added + + // statics + static std::string sLogName; + static bool sMetricLog; + static bool sLog; + static LLThreadLocalPointer sCurTimerData; + static U64 sClockResolution; + static S32 sCurFrameIndex; + static S32 sLastFrameIndex; + static U64 sLastFrameTime; + static bool sPauseHistory; + static bool sResetHistory; + }; LL_FORCE_INLINE Time::Time(BlockTimer& timer) { #if FAST_TIMER_ON - mStartTime = getCPUClockCount64(); + mStartTime = BlockTimer::getCPUClockCount64(); TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); accumulator.mActiveCount++; @@ -317,7 +296,7 @@ LL_FORCE_INLINE Time::Time(BlockTimer& timer) // keep current parent as long as it is active when we are accumulator.mMoveUpTree |= (timer.mParent->getPrimaryAccumulator().mActiveCount == 0); - CurTimerData* cur_timer_data = Time::sCurTimerData.get(); + CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); // store top of stack mLastTimerData = *cur_timer_data; // push new information @@ -330,8 +309,8 @@ LL_FORCE_INLINE Time::Time(BlockTimer& timer) LL_FORCE_INLINE Time::~Time() { #if FAST_TIMER_ON - U64 total_time = getCPUClockCount64() - mStartTime; - CurTimerData* cur_timer_data = Time::sCurTimerData.get(); + U64 total_time = BlockTimer::getCPUClockCount64() - mStartTime; + CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); TimerAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator.mTotalTimeCounter += total_time; @@ -344,7 +323,7 @@ LL_FORCE_INLINE Time::~Time() // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; - *sCurTimerData = mLastTimerData; + *BlockTimer::sCurTimerData = mLastTimerData; #endif } diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index c51d042a3d..5917d7a420 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -28,7 +28,7 @@ */ #if LL_WINDOWS -#include +#include "llwin32headerslean.h" #include // Windows errno #else #include diff --git a/indra/llcommon/llfindlocale.cpp b/indra/llcommon/llfindlocale.cpp index cd7c0c7c09..f019bd0c64 100644 --- a/indra/llcommon/llfindlocale.cpp +++ b/indra/llcommon/llfindlocale.cpp @@ -33,7 +33,7 @@ #include #ifdef WIN32 -#include +#include "llwin32headers.h" #include #endif diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp index 32d4eec607..d72e10d2fa 100644 --- a/indra/llcommon/llinitparam.cpp +++ b/indra/llcommon/llinitparam.cpp @@ -28,6 +28,7 @@ #include "linden_common.h" #include "llinitparam.h" +#include "llformat.h" namespace LLInitParam diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h index 3d4e4331c0..502f93cbb8 100644 --- a/indra/llcommon/llinitparam.h +++ b/indra/llcommon/llinitparam.h @@ -29,6 +29,7 @@ #define LL_LLPARAM_H #include +#include #include #include #include diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp index afaf366668..7c4ab6cf98 100644 --- a/indra/llcommon/llmemory.cpp +++ b/indra/llcommon/llmemory.cpp @@ -32,7 +32,6 @@ //#endif #if defined(LL_WINDOWS) -//# include # include #elif defined(LL_DARWIN) # include diff --git a/indra/llcommon/llmetricperformancetester.cpp b/indra/llcommon/llmetricperformancetester.cpp index a1b0a684c5..43d98be47b 100644 --- a/indra/llcommon/llmetricperformancetester.cpp +++ b/indra/llcommon/llmetricperformancetester.cpp @@ -31,6 +31,7 @@ #include "llsdserialize.h" #include "lltreeiterators.h" #include "llmetricperformancetester.h" +#include "llfasttimer.h" //---------------------------------------------------------------------------------------------- // LLMetricPerformanceTesterBasic : static methods and testers management @@ -90,7 +91,7 @@ LLMetricPerformanceTesterBasic* LLMetricPerformanceTesterBasic::getTester(std::s // Return TRUE if this metric is requested or if the general default "catch all" metric is requested BOOL LLMetricPerformanceTesterBasic::isMetricLogRequested(std::string name) { - return (LLFastTimer::sMetricLog && ((LLFastTimer::sLogName == name) || (LLFastTimer::sLogName == DEFAULT_METRIC_NAME))); + return (LLTrace::BlockTimer::sMetricLog && ((LLTrace::BlockTimer::sLogName == name) || (LLTrace::BlockTimer::sLogName == DEFAULT_METRIC_NAME))); } /*static*/ @@ -193,8 +194,7 @@ void LLMetricPerformanceTesterBasic::preOutputTestResults(LLSD* sd) void LLMetricPerformanceTesterBasic::postOutputTestResults(LLSD* sd) { - LLMutexLock lock(LLFastTimer::sLogLock); - LLFastTimer::sLogQueue.push((*sd)); + LLTrace::BlockTimer::pushLog(*sd); } void LLMetricPerformanceTesterBasic::outputTestResults() diff --git a/indra/llcommon/llmortician.h b/indra/llcommon/llmortician.h index 319955ef93..9517e2db5e 100644 --- a/indra/llcommon/llmortician.h +++ b/indra/llcommon/llmortician.h @@ -28,6 +28,7 @@ #define LLMORTICIAN_H #include "stdtypes.h" +#include class LL_COMMON_API LLMortician { diff --git a/indra/llcommon/llprocess.h b/indra/llcommon/llprocess.h index d711ce2f74..2fe084afcd 100644 --- a/indra/llcommon/llprocess.h +++ b/indra/llcommon/llprocess.h @@ -38,8 +38,7 @@ #include #if LL_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include // HANDLE (eye roll) +#include "llwin32headerslean.h" // for HANDLE #elif LL_LINUX #if defined(Status) #undef Status diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 87a5930c14..6fe53396ca 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -32,9 +32,7 @@ //#include #if LL_WINDOWS -# define WIN32_LEAN_AND_MEAN -# include -# include +# include "llwin32headerslean.h" # define _interlockedbittestandset _renamed_interlockedbittestandset # define _interlockedbittestandreset _renamed_interlockedbittestandreset # include diff --git a/indra/llcommon/llsdparam.h b/indra/llcommon/llsdparam.h index 1181c2d433..7cfc265c62 100644 --- a/indra/llcommon/llsdparam.h +++ b/indra/llcommon/llsdparam.h @@ -30,6 +30,7 @@ #include "llinitparam.h" #include "boost/function.hpp" +#include "llfasttimer.h" struct LL_COMMON_API LLParamSDParserUtilities { diff --git a/indra/llcommon/llstacktrace.cpp b/indra/llcommon/llstacktrace.cpp index ccd7ef91c2..e0e9056380 100644 --- a/indra/llcommon/llstacktrace.cpp +++ b/indra/llcommon/llstacktrace.cpp @@ -32,7 +32,7 @@ #include #include -#include "windows.h" +#include "llwin32headerslean.h" #include "Dbghelp.h" typedef USHORT NTAPI RtlCaptureStackBackTrace_Function( diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index fa0eb9f72c..9600928ad5 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -28,11 +28,10 @@ #include "llstring.h" #include "llerror.h" +#include "llfasttimer.h" #if LL_WINDOWS -#define WIN32_LEAN_AND_MEAN -#include -#include +#include "llwin32headerslean.h" #include // for WideCharToMultiByte #endif diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index 119efc7957..9d81ac25dd 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -31,8 +31,9 @@ #include #include #include +#include #include "llsd.h" -#include "llfasttimer.h" +#include "llformat.h" #if LL_LINUX || LL_SOLARIS #include diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index 6073bcd0a6..00b72ce1d8 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -42,6 +42,7 @@ #include "llprocessor.h" #include "llerrorcontrol.h" #include "llevents.h" +#include "llformat.h" #include "lltimer.h" #include "llsdserialize.h" #include "llsdutil.h" @@ -58,9 +59,7 @@ using namespace llsd; #if LL_WINDOWS -# define WIN32_LEAN_AND_MEAN -# include -# include +# include "llwin32headerslean.h" # include // GetPerformanceInfo() et al. #elif LL_DARWIN # include diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 23cebf4336..26063beff0 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -31,11 +31,9 @@ #include "u64.h" #if LL_WINDOWS -# define WIN32_LEAN_AND_MEAN -# include -# include +# include "llwin32headerslean.h" #elif LL_LINUX || LL_SOLARIS || LL_DARWIN -# include +# include # include #else # error "architecture not supported" diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index afb175c398..9346aa7a45 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -38,15 +38,15 @@ static MasterThreadRecorder* gMasterThreadRecorder = NULL; void init() { gMasterThreadRecorder = new MasterThreadRecorder(); - Time::sCurTimerData = new Time::CurTimerData(); + BlockTimer::sCurTimerData = new CurTimerData(); } void cleanup() { delete gMasterThreadRecorder; gMasterThreadRecorder = NULL; - delete Time::sCurTimerData.get(); - Time::sCurTimerData = NULL; + delete BlockTimer::sCurTimerData.get(); + BlockTimer::sCurTimerData = NULL; } MasterThreadRecorder& getMasterThreadRecorder() diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index fb9dca5e84..61fed6e7b8 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -235,8 +235,8 @@ namespace LLTrace MeasurementAccumulator() : mSum(0), - mMin(std::numeric_limits::max()), - mMax(std::numeric_limits::min()), + mMin((std::numeric_limits::max)()), + mMax((std::numeric_limits::min)()), mMean(0), mVarianceSum(0), mNumSamples(0), @@ -380,6 +380,24 @@ namespace LLTrace U32 mNumSamples; }; + class TimerAccumulator + { + public: + void addSamples(const TimerAccumulator& other); + void reset(const TimerAccumulator* other); + + // + // members + // + U64 mSelfTimeCounter, + mTotalTimeCounter; + U32 mCalls; + class BlockTimer* mLastCaller; // used to bootstrap tree construction + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame + }; + + template class Measurement : public TraceType::type_t> > diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 4dcadfdf29..efc54d240f 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -273,7 +273,7 @@ namespace LLTrace template typename T getPeriodMin(const TraceType >& stat) const { - T min_val = std::numeric_limits::max(); + T min_val = (std::numeric_limits::max)(); for (S32 i = 0; i < mNumPeriods; i++) { min_val = llmin(min_val, mRecordingPeriods[i].getSum(stat)); @@ -284,7 +284,7 @@ namespace LLTrace template F64 getPeriodMinPerSec(const TraceType >& stat) const { - F64 min_val = std::numeric_limits::max(); + F64 min_val = (std::numeric_limits::max)(); for (S32 i = 0; i < mNumPeriods; i++) { min_val = llmin(min_val, mRecordingPeriods[i].getPerSec(stat)); @@ -295,7 +295,7 @@ namespace LLTrace template T getPeriodMax(const TraceType >& stat) const { - T max_val = std::numeric_limits::min(); + T max_val = (std::numeric_limits::min)(); for (S32 i = 0; i < mNumPeriods; i++) { max_val = llmax(max_val, mRecordingPeriods[i].getSum(stat)); @@ -306,7 +306,7 @@ namespace LLTrace template F64 getPeriodMaxPerSec(const TraceType >& stat) const { - F64 max_val = std::numeric_limits::min(); + F64 max_val = (std::numeric_limits::min)(); for (S32 i = 0; i < mNumPeriods; i++) { max_val = llmax(max_val, mRecordingPeriods[i].getPerSec(stat)); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 5a6ff14f97..0f111aab59 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -26,6 +26,7 @@ #include "linden_common.h" #include "lltracethreadrecorder.h" +#include "llfasttimer.h" namespace LLTrace { diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 4ac2197c11..1fe492fdce 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -33,18 +33,12 @@ namespace LLUnits { -template +template struct HighestPrecisionType { typedef T type_t; }; -template -struct HighestPrecisionType -{ - typedef typename HighestPrecisionType::type_t type_t; -}; - template<> struct HighestPrecisionType { typedef F64 type_t; }; template<> struct HighestPrecisionType { typedef S64 type_t; }; template<> struct HighestPrecisionType { typedef S64 type_t; }; @@ -78,7 +72,6 @@ struct LLUnit { typedef LLUnit self_t; typedef typename STORAGE_TYPE storage_t; - typedef void is_unit_tag_t; LLUnit(storage_t value = storage_t()) : mValue(value) diff --git a/indra/llcommon/lluuid.cpp b/indra/llcommon/lluuid.cpp index db8c9c85ab..83ed987d30 100644 --- a/indra/llcommon/lluuid.cpp +++ b/indra/llcommon/lluuid.cpp @@ -27,9 +27,7 @@ // We can't use WIN32_LEAN_AND_MEAN here, needs lots of includes. #if LL_WINDOWS -#undef WIN32_LEAN_AND_MEAN -#include -#include +#include "llwin32headers.h" // ugh, this is ugly. We need to straighten out our linking for this library #pragma comment(lib, "IPHLPAPI.lib") #include diff --git a/indra/llcommon/llwin32headers.h b/indra/llcommon/llwin32headers.h new file mode 100644 index 0000000000..80fd2e1768 --- /dev/null +++ b/indra/llcommon/llwin32headers.h @@ -0,0 +1,38 @@ +/** + * @file llwindows.h + * @brief sanitized include of windows header files + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLWINDOWS_H +#define LL_LLWINDOWS_H + +#ifdef LL_WINDOWS +#define NOMINMAX +#undef WIN32_LEAN_AND_MEAN +#include +#include +#undef NOMINMAX +#endif + +#endif diff --git a/indra/llcommon/llwin32headerslean.h b/indra/llcommon/llwin32headerslean.h new file mode 100644 index 0000000000..ab6e9c09e2 --- /dev/null +++ b/indra/llcommon/llwin32headerslean.h @@ -0,0 +1,37 @@ +/** + * @file llwindows.h + * @brief sanitized include of windows header files + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLWINDOWS_H +#define LL_LLWINDOWS_H + +#ifdef LL_WINDOWS +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif + +#endif -- cgit v1.2.3 From c136b432140f892a56d4996d5ed77e903ff0b32d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 15 Nov 2012 19:46:09 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system eliminated min and max macros from windows.h got rest of viewer to compile against llfasttimer changes --- indra/llcommon/llapr.h | 1 + indra/llcommon/llfasttimer.cpp | 5 +++++ indra/llcommon/llfasttimer.h | 3 ++- indra/llcommon/llthread.h | 2 ++ indra/llcommon/lltrace.cpp | 1 - indra/llcommon/llwin32headers.h | 2 -- indra/llcommon/llwin32headerslean.h | 1 - 7 files changed, 10 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index c77d96c1c9..d9fe257e86 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -40,6 +40,7 @@ #include "apr_getopt.h" #include "apr_signal.h" #include "apr_atomic.h" + #include "llstring.h" #include "llinstancetracker.h" diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index d007f76e5f..4ecca12832 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -121,6 +121,11 @@ void BlockTimer::pushLog(LLSD log) sLogQueue.push(log); } +void BlockTimer::setLogLock(LLMutex* lock) +{ + sLogLock = lock; +} + //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 69a6773b12..af9b360e01 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -98,6 +98,7 @@ public: static BlockTimer& getRootTimer(); static void pushLog(LLSD sd); + static void setLogLock(LLMutex* mutex); friend class Time; @@ -329,6 +330,6 @@ LL_FORCE_INLINE Time::~Time() } -typedef LLTrace::Time LLFastTimer; +typedef LLTrace::Time LLFastTimer; #endif // LL_LLFASTTIMER_H diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 82ab5f47d2..93c752754d 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -32,6 +32,8 @@ #include "apr_thread_cond.h" #include "llmutex.h" +LL_COMMON_API void assert_main_thread(); + class LL_COMMON_API LLThread { private: diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 9346aa7a45..9bf9ae6c8e 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -59,7 +59,6 @@ LLThreadLocalPointer& get_thread_recorder() { static LLThreadLocalPointer s_thread_recorder; return s_thread_recorder; - } } diff --git a/indra/llcommon/llwin32headers.h b/indra/llcommon/llwin32headers.h index 80fd2e1768..9c89b6b280 100644 --- a/indra/llcommon/llwin32headers.h +++ b/indra/llcommon/llwin32headers.h @@ -28,11 +28,9 @@ #define LL_LLWINDOWS_H #ifdef LL_WINDOWS -#define NOMINMAX #undef WIN32_LEAN_AND_MEAN #include #include -#undef NOMINMAX #endif #endif diff --git a/indra/llcommon/llwin32headerslean.h b/indra/llcommon/llwin32headerslean.h index ab6e9c09e2..d3fb90d4b1 100644 --- a/indra/llcommon/llwin32headerslean.h +++ b/indra/llcommon/llwin32headerslean.h @@ -28,7 +28,6 @@ #define LL_LLWINDOWS_H #ifdef LL_WINDOWS -#define NOMINMAX #define WIN32_LEAN_AND_MEAN #include #include -- cgit v1.2.3 From 6db6cb39f41e921e75970d1570a74cf35d353a35 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 16 Nov 2012 23:02:53 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system got new fast timer code to compile and run --- indra/llcommon/llfasttimer.cpp | 13 ++++++++++++- indra/llcommon/lltrace.cpp | 12 +++++++++--- indra/llcommon/lltrace.h | 6 ++++++ indra/llcommon/lltracethreadrecorder.cpp | 4 ++++ 4 files changed, 31 insertions(+), 4 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 4ecca12832..e1549b4bff 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -336,7 +336,10 @@ void BlockTimer::accumulateTimings() cur_data = &cur_timer->mLastTimerData; cur_data->mChildTime += cumulative_time_delta; - accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + if (cur_data->mTimerData) + { + accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + } cur_timer = cur_timer->mLastTimerData.mCurTimer; } @@ -572,6 +575,14 @@ void Time::writeLog(std::ostream& os) } +LLTrace::TimerAccumulator::TimerAccumulator() : mSelfTimeCounter(0), + mTotalTimeCounter(0), + mCalls(0), + mLastCaller(NULL), + mActiveCount(0), + mMoveUpTree(false) +{} + void LLTrace::TimerAccumulator::addSamples( const LLTrace::TimerAccumulator& other ) { mSelfTimeCounter += other.mSelfTimeCounter; diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 9bf9ae6c8e..e11e39a1a2 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -30,6 +30,8 @@ #include "lltracethreadrecorder.h" #include "llfasttimer.h" +static bool sInitialized; + namespace LLTrace { @@ -38,15 +40,18 @@ static MasterThreadRecorder* gMasterThreadRecorder = NULL; void init() { gMasterThreadRecorder = new MasterThreadRecorder(); - BlockTimer::sCurTimerData = new CurTimerData(); + sInitialized = true; +} + +bool isInitialized() +{ + return sInitialized; } void cleanup() { delete gMasterThreadRecorder; gMasterThreadRecorder = NULL; - delete BlockTimer::sCurTimerData.get(); - BlockTimer::sCurTimerData = NULL; } MasterThreadRecorder& getMasterThreadRecorder() @@ -62,3 +67,4 @@ LLThreadLocalPointer& get_thread_recorder() } } + diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 61fed6e7b8..61d14569cd 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -67,6 +67,7 @@ namespace LLTrace void init(); void cleanup(); + bool isInitialized(); LLThreadLocalPointer& get_thread_recorder(); @@ -162,6 +163,10 @@ namespace LLTrace // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned size_t reserveSlot() { + if (LLTrace::isInitialized()) + { + llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; + } size_t next_slot = mNextStorageSlot++; if (next_slot >= mStorageSize) { @@ -383,6 +388,7 @@ namespace LLTrace class TimerAccumulator { public: + TimerAccumulator(); void addSamples(const TimerAccumulator& other); void reset(const TimerAccumulator* other); diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 0f111aab59..c2fefe2957 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -40,6 +40,8 @@ ThreadRecorder::ThreadRecorder() { get_thread_recorder() = this; mFullRecording.start(); + + BlockTimer::sCurTimerData = new CurTimerData(); } ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) @@ -52,6 +54,8 @@ ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) ThreadRecorder::~ThreadRecorder() { get_thread_recorder() = NULL; + delete BlockTimer::sCurTimerData.get(); + BlockTimer::sCurTimerData = NULL; } void ThreadRecorder::activate( Recording* recording ) -- cgit v1.2.3 From 5d51175cd79b15cf036cd7e6bd646a1a0777eb7f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 20 Nov 2012 15:55:04 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixes to merge --- indra/llcommon/llmemory.h | 2 +- indra/llcommon/llmutex.cpp | 49 +------------- indra/llcommon/llmutex.h | 67 ------------------- indra/llcommon/llthread.cpp | 153 +------------------------------------------- indra/llcommon/llthread.h | 2 +- indra/llcommon/llunit.h | 40 +++++++----- 6 files changed, 29 insertions(+), 284 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 3744e68956..e725bdd9fa 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -26,7 +26,7 @@ #ifndef LLMEMORY_H #define LLMEMORY_H -#include "llmemtype.h" +#include "linden_common.h" class LLMutex ; diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp index 2ce14b3a2e..e6beb9e680 100644 --- a/indra/llcommon/llmutex.cpp +++ b/indra/llcommon/llmutex.cpp @@ -86,7 +86,7 @@ void LLMutex::lock() #if LL_DARWIN mLockingThread = LLThread::currentID(); #else - mLockingThread = LLThread::sThreadIndex; + mLockingThread = LLThread::sThreadID; #endif } @@ -129,7 +129,7 @@ bool LLMutex::isSelfLocked() #if LL_DARWIN return mLockingThread == LLThread::currentID(); #else - return mLockingThread == LLThread::sThreadIndex; + return mLockingThread == LLThread::sThreadID; #endif } @@ -181,49 +181,4 @@ void LLCondition::broadcast() } -//============================================================================ - -//---------------------------------------------------------------------------- - -//static -LLMutex* LLThreadSafeRefCount::sMutex = 0; - -//static -void LLThreadSafeRefCount::initThreadSafeRefCount() -{ - if (!sMutex) - { - sMutex = new LLMutex(0); - } -} - -//static -void LLThreadSafeRefCount::cleanupThreadSafeRefCount() -{ - delete sMutex; - sMutex = NULL; -} - - -//---------------------------------------------------------------------------- - -LLThreadSafeRefCount::LLThreadSafeRefCount() : -mRef(0) -{ -} - -LLThreadSafeRefCount::~LLThreadSafeRefCount() -{ - if (mRef != 0) - { - llerrs << "deleting non-zero reference" << llendl; - } -} - -//============================================================================ - -LLResponder::~LLResponder() -{ -} - //============================================================================ diff --git a/indra/llcommon/llmutex.h b/indra/llcommon/llmutex.h index bd0a59b577..cbde4c47a9 100644 --- a/indra/llcommon/llmutex.h +++ b/indra/llcommon/llmutex.h @@ -98,71 +98,4 @@ private: LLMutex* mMutex; }; - -//============================================================================ - -// 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; - -private: - LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented - LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented - -protected: - virtual ~LLThreadSafeRefCount(); // use unref() - -public: - LLThreadSafeRefCount(); - - 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; -}; - - -//============================================================================ - -// Simple responder for self destructing callbacks -// Pure virtual class -class LL_COMMON_API LLResponder : public LLThreadSafeRefCount -{ -protected: - virtual ~LLResponder(); -public: - virtual void completed(bool success) = 0; -}; - - #endif // LL_LLTHREAD_H diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 1c86eb4f06..8ce739bf23 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -62,7 +62,7 @@ #if LL_DARWIN // statically allocated thread local storage not supported in Darwin executable formats #elif LL_WINDOWS -U32 __declspec(thread) LLThread::sThreadIndex = 0; +U32 __declspec(thread) LLThread::sThreadID = 0; #elif LL_LINUX U32 __thread LLThread::sThreadID = 0; #endif @@ -96,7 +96,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap LLTrace::ThreadRecorder* thread_recorder = new LLTrace::SlaveThreadRecorder(); #if !LL_DARWIN - sThreadIndex = threadp->mID; + sThreadID = threadp->mID; #endif // Run the user supplied function @@ -327,155 +327,6 @@ void LLThread::wakeLocked() //============================================================================ -LLMutex::LLMutex(apr_pool_t *poolp) : - mAPRMutexp(NULL), mCount(0), mLockingThread(NO_THREAD) -{ - //if (poolp) - //{ - // mIsLocalPool = FALSE; - // mAPRPoolp = poolp; - //} - //else - { - mIsLocalPool = TRUE; - apr_pool_create(&mAPRPoolp, NULL); // Create a subpool for this thread - } - apr_thread_mutex_create(&mAPRMutexp, APR_THREAD_MUTEX_UNNESTED, mAPRPoolp); -} - - -LLMutex::~LLMutex() -{ -#if MUTEX_DEBUG - //bad assertion, the subclass LLSignal might be "locked", and that's OK - //llassert_always(!isLocked()); // better not be locked! -#endif - apr_thread_mutex_destroy(mAPRMutexp); - mAPRMutexp = NULL; - if (mIsLocalPool) - { - apr_pool_destroy(mAPRPoolp); - } -} - - -void LLMutex::lock() -{ - if(isSelfLocked()) - { //redundant lock - mCount++; - return; - } - - apr_thread_mutex_lock(mAPRMutexp); - -#if MUTEX_DEBUG - // Have to have the lock before we can access the debug info - U32 id = LLThread::currentID(); - if (mIsLocked[id] != FALSE) - llerrs << "Already locked in Thread: " << id << llendl; - mIsLocked[id] = TRUE; -#endif - -#if LL_DARWIN - mLockingThread = LLThread::currentID(); -#else - mLockingThread = sThreadID; -#endif -} - -void LLMutex::unlock() -{ - if (mCount > 0) - { //not the root unlock - mCount--; - return; - } - -#if MUTEX_DEBUG - // Access the debug info while we have the lock - U32 id = LLThread::currentID(); - if (mIsLocked[id] != TRUE) - llerrs << "Not locked in Thread: " << id << llendl; - mIsLocked[id] = FALSE; -#endif - - mLockingThread = NO_THREAD; - apr_thread_mutex_unlock(mAPRMutexp); -} - -bool LLMutex::isLocked() -{ - apr_status_t status = apr_thread_mutex_trylock(mAPRMutexp); - if (APR_STATUS_IS_EBUSY(status)) - { - return true; - } - else - { - apr_thread_mutex_unlock(mAPRMutexp); - return false; - } -} - -bool LLMutex::isSelfLocked() -{ -#if LL_DARWIN - return mLockingThread == LLThread::currentID(); -#else - return mLockingThread == sThreadID; -#endif -} - -U32 LLMutex::lockingThread() const -{ - return mLockingThread; -} - -//============================================================================ - -LLCondition::LLCondition(apr_pool_t *poolp) : - LLMutex(poolp) -{ - // base class (LLMutex) has already ensured that mAPRPoolp is set up. - - apr_thread_cond_create(&mAPRCondp, mAPRPoolp); -} - - -LLCondition::~LLCondition() -{ - apr_thread_cond_destroy(mAPRCondp); - mAPRCondp = NULL; -} - - -void LLCondition::wait() -{ - if (!isLocked()) - { //mAPRMutexp MUST be locked before calling apr_thread_cond_wait - apr_thread_mutex_lock(mAPRMutexp); -#if MUTEX_DEBUG - // avoid asserts on destruction in non-release builds - U32 id = LLThread::currentID(); - mIsLocked[id] = TRUE; -#endif - } - apr_thread_cond_wait(mAPRCondp, mAPRMutexp); -} - -void LLCondition::signal() -{ - apr_thread_cond_signal(mAPRCondp); -} - -void LLCondition::broadcast() -{ - apr_thread_cond_broadcast(mAPRCondp); -} - -//============================================================================ - //---------------------------------------------------------------------------- //static diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 94b6b6d682..75222c83f9 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -42,7 +42,7 @@ private: #if LL_DARWIN // statically allocated thread local storage not supported in Darwin executable formats #elif LL_WINDOWS - static U32 __declspec(thread) LLThread::sThreadIndex; + static U32 __declspec(thread) LLThread::sThreadID; #elif LL_LINUX static U32 __thread LLThread::sThreadID ; #endif diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 1fe492fdce..53570779fc 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -109,9 +109,9 @@ struct LLUnit return mValue; } - template LLUnit as() + template LLUnit as() { - return LLUnit(*this); + return LLUnit(*this); } void operator += (storage_t value) @@ -332,21 +332,27 @@ struct HighestPrecisionType > typedef typename HighestPrecisionType::type_t type_t; }; -#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor) \ -struct unit_name \ -{ \ - typedef base_unit_name base_unit_t; \ -}; \ -template \ -struct ConversionFactor \ -{ \ - static typename HighestPrecisionType::type_t get() { return typename HighestPrecisionType::type_t(conversion_factor); } \ -}; \ - \ -template \ -struct ConversionFactor \ -{ \ - static typename HighestPrecisionType::type_t get() { return typename HighestPrecisionType::type_t(1.0 / (conversion_factor)); } \ +#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor) \ +struct unit_name \ +{ \ + typedef base_unit_name base_unit_t; \ +}; \ +template \ +struct ConversionFactor \ +{ \ + static typename HighestPrecisionType::type_t get() \ + { \ + return typename HighestPrecisionType::type_t(conversion_factor); \ + } \ +}; \ + \ +template \ +struct ConversionFactor \ +{ \ + static typename HighestPrecisionType::type_t get() \ + { \ + return typename HighestPrecisionType::type_t(1.0 / (conversion_factor)); \ + } \ } struct Bytes { typedef Bytes base_unit_t; }; -- cgit v1.2.3 From 1c894c05c10ef37be6507ee4bc4e9173506adfb6 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Nov 2012 17:26:12 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system hunting down bad values and crashes --- indra/llcommon/llfasttimer.cpp | 24 ++++++++++++++---------- indra/llcommon/llfasttimer.h | 8 ++++---- indra/llcommon/lltrace.h | 1 + indra/llcommon/lltracerecording.cpp | 5 ++++- indra/llcommon/lltracethreadrecorder.cpp | 4 ++++ 5 files changed, 27 insertions(+), 15 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e1549b4bff..16dd21332c 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -177,8 +177,8 @@ BlockTimer::BlockTimer(const char* name, bool open, BlockTimer* parent) mParent = this; } - mCountHistory = new U32[HISTORY_NUM]; - memset(mCountHistory, 0, sizeof(U32) * HISTORY_NUM); + mCountHistory = new U64[HISTORY_NUM]; + memset(mCountHistory, 0, sizeof(U64) * HISTORY_NUM); mCallHistory = new U32[HISTORY_NUM]; memset(mCallHistory, 0, sizeof(U32) * HISTORY_NUM); } @@ -266,9 +266,12 @@ void BlockTimer::buildHierarchy() // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.getPrimaryAccumulator().mLastCaller && timer.mParent == &BlockTimer::getRootTimer()) + if (timer.mParent == &BlockTimer::getRootTimer()) { - timer.setParent(timer.getPrimaryAccumulator().mLastCaller); + if (timer.getPrimaryAccumulator().mLastCaller) + { + timer.setParent(timer.getPrimaryAccumulator().mLastCaller); + } // no need to push up tree on first use, flag can be set spuriously timer.getPrimaryAccumulator().mMoveUpTree = false; } @@ -317,7 +320,7 @@ void BlockTimer::buildHierarchy() //static void BlockTimer::accumulateTimings() { - U32 cur_time = getCPUClockCount32(); + U64 cur_time = getCPUClockCount64(); // walk up stack of active timers and accumulate current time while leaving timing structures active Time* cur_timer = sCurTimerData->mCurTimer; @@ -326,8 +329,8 @@ void BlockTimer::accumulateTimings() TimerAccumulator& accumulator = sCurTimerData->mTimerData->getPrimaryAccumulator(); while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { - U32 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U32 self_time_delta = cumulative_time_delta - cur_data->mChildTime; + U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; + U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; accumulator.mSelfTimeCounter += self_time_delta; accumulator.mTotalTimeCounter += cumulative_time_delta; @@ -429,6 +432,7 @@ void BlockTimer::resetFrame() BlockTimer& timer = *it; TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); accumulator.mSelfTimeCounter = 0; + accumulator.mTotalTimeCounter = 0; accumulator.mCalls = 0; accumulator.mLastCaller = NULL; accumulator.mMoveUpTree = false; @@ -442,7 +446,7 @@ void BlockTimer::reset() // walk up stack of active timers and reset start times to current time // effectively zeroing out any accumulated time - U32 cur_time = getCPUClockCount32(); + U64 cur_time = getCPUClockCount64(); // root defined by parent pointing to self CurTimerData* cur_data = sCurTimerData.get(); @@ -471,7 +475,7 @@ void BlockTimer::reset() timer.mCountAverage = 0; timer.mCallAverage = 0; - memset(timer.mCountHistory, 0, sizeof(U32) * HISTORY_NUM); + memset(timer.mCountHistory, 0, sizeof(U64) * HISTORY_NUM); memset(timer.mCallHistory, 0, sizeof(U32) * HISTORY_NUM); } } @@ -480,7 +484,7 @@ void BlockTimer::reset() sCurFrameIndex = 0; } -U32 BlockTimer::getHistoricalCount(S32 history_index) const +U64 BlockTimer::getHistoricalCount(S32 history_index) const { S32 history_idx = (getLastFrameIndex() + history_index) % HISTORY_NUM; return mCountHistory[history_idx]; diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index af9b360e01..cfe2cf5371 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -93,7 +93,7 @@ public: U32 getCountAverage() const { return mCountAverage; } U32 getCallAverage() const { return mCallAverage; } - U32 getHistoricalCount(S32 history_index = 0) const; + U64 getHistoricalCount(S32 history_index = 0) const; U32 getHistoricalCalls(S32 history_index = 0) const; static BlockTimer& getRootTimer(); @@ -258,12 +258,12 @@ public: // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete - U32 mTreeTimeCounter; + U64 mTreeTimeCounter; - U32 mCountAverage; + U64 mCountAverage; U32 mCallAverage; - U32* mCountHistory; + U64* mCountHistory; U32* mCallHistory; // tree structure diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 61d14569cd..11651ef953 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -107,6 +107,7 @@ namespace LLTrace //TODO pick another primary? sPrimaryStorage = NULL; } + delete[] mStorage; } LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 4252ed57dc..e7ed55e8ae 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -66,7 +66,10 @@ Recording::Recording( const Recording& other ) Recording::~Recording() -{} +{ + stop(); + llassert(isStopped()); +} void Recording::update() { diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index c2fefe2957..faaab4c8e7 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -53,6 +53,10 @@ ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) ThreadRecorder::~ThreadRecorder() { + while(mActiveRecordings.size()) + { + mActiveRecordings.front().mTargetRecording->stop(); + } get_thread_recorder() = NULL; delete BlockTimer::sCurTimerData.get(); BlockTimer::sCurTimerData = NULL; -- cgit v1.2.3 From 93aca485ba08a82a6bd3a2fc31deca18af0d1478 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Nov 2012 20:17:37 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed precision of fast timer counts --- indra/llcommon/llfasttimer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e1549b4bff..9701a41dc5 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -317,7 +317,7 @@ void BlockTimer::buildHierarchy() //static void BlockTimer::accumulateTimings() { - U32 cur_time = getCPUClockCount32(); + U64 cur_time = getCPUClockCount64(); // walk up stack of active timers and accumulate current time while leaving timing structures active Time* cur_timer = sCurTimerData->mCurTimer; @@ -389,7 +389,7 @@ void BlockTimer::resetFrame() } call_count++; - F64 iclock_freq = 1000.0 / countsPerSecond(); // good place to calculate clock frequency + F64 iclock_freq = 1000.0 / get_clock_count(); // good place to calculate clock frequency F64 total_time = 0; LLSD sd; @@ -442,7 +442,7 @@ void BlockTimer::reset() // walk up stack of active timers and reset start times to current time // effectively zeroing out any accumulated time - U32 cur_time = getCPUClockCount32(); + U64 cur_time = getCPUClockCount64(); // root defined by parent pointing to self CurTimerData* cur_data = sCurTimerData.get(); @@ -510,7 +510,7 @@ std::vector& BlockTimer::getChildren() //static void BlockTimer::nextFrame() { - BlockTimer::countsPerSecond(); // good place to calculate clock frequency + get_clock_count(); // good place to calculate clock frequency U64 frame_time = BlockTimer::getCPUClockCount64(); if ((frame_time - sLastFrameTime) >> 8 > 0xffffffff) { @@ -534,7 +534,7 @@ void Time::dumpCurTimes() // accumulate timings, etc. BlockTimer::processTimes(); - F64 clock_freq = (F64)BlockTimer::countsPerSecond(); + F64 clock_freq = (F64)get_clock_count(); F64 iclock_freq = 1000.0 / clock_freq; // clock_ticks -> milliseconds // walk over timers in depth order and output timings -- cgit v1.2.3 From 02d503bf8f8890c6d4b57dd09a1fde2973715b75 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 29 Nov 2012 00:43:25 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system moved runtime timer tree topology information to separate array instead of recording stack --- indra/llcommon/llfasttimer.cpp | 85 +++++++++++++++++--------------- indra/llcommon/llfasttimer.h | 34 +++++++------ indra/llcommon/lltrace.h | 13 ++++- indra/llcommon/lltracethreadrecorder.cpp | 20 +++++--- indra/llcommon/lltracethreadrecorder.h | 4 +- 5 files changed, 91 insertions(+), 65 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e88a5a9ed1..1b3498cce3 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -58,24 +58,27 @@ namespace LLTrace ////////////////////////////////////////////////////////////////////////////// // statics -S32 BlockTimer::sCurFrameIndex = -1; -S32 BlockTimer::sLastFrameIndex = -1; -U64 BlockTimer::sLastFrameTime = BlockTimer::getCPUClockCount64(); -bool BlockTimer::sPauseHistory = 0; -bool BlockTimer::sResetHistory = 0; -LLThreadLocalPointer BlockTimer::sCurTimerData; -bool BlockTimer::sLog = false; -std::string BlockTimer::sLogName = ""; -bool BlockTimer::sMetricLog = false; -static LLMutex* sLogLock = NULL; -static std::queue sLogQueue; +S32 BlockTimer::sCurFrameIndex = -1; +S32 BlockTimer::sLastFrameIndex = -1; +U64 BlockTimer::sLastFrameTime = BlockTimer::getCPUClockCount64(); +bool BlockTimer::sPauseHistory = 0; +bool BlockTimer::sResetHistory = 0; +bool BlockTimer::sLog = false; +std::string BlockTimer::sLogName = ""; +bool BlockTimer::sMetricLog = false; #if LL_LINUX || LL_SOLARIS -U64 BlockTimer::sClockResolution = 1000000000; // Nanosecond resolution +U64 BlockTimer::sClockResolution = 1000000000; // Nanosecond resolution #else -U64 BlockTimer::sClockResolution = 1000000; // Microsecond resolution +U64 BlockTimer::sClockResolution = 1000000; // Microsecond resolution #endif +LLThreadLocalPointer BlockTimer::sCurTimerData; + +static LLMutex* sLogLock = NULL; +static std::queue sLogQueue; + + // FIXME: move these declarations to the relevant modules // helper functions @@ -108,6 +111,7 @@ static timer_tree_dfs_iterator_t end_timer_tree() return timer_tree_dfs_iterator_t(); } + BlockTimer& BlockTimer::getRootTimer() { static BlockTimer root_timer("root", true, NULL); @@ -142,7 +146,7 @@ U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer // we drop the low-order byte in our timers, so report a lower frequency #else - // If we're not using RDTSC, each fasttimer tick is just a performance counter tick. + // If we're not using RDTSC, each fast timer tick is just a performance counter tick. // Not redefining the clock frequency itself (in llprocessor.cpp/calculate_cpu_frequency()) // since that would change displayed MHz stats for CPUs static bool firstcall = true; @@ -268,17 +272,19 @@ void BlockTimer::buildHierarchy() // when this timer was called if (timer.mParent == &BlockTimer::getRootTimer()) { - if (timer.getPrimaryAccumulator().mLastCaller) - { - timer.setParent(timer.getPrimaryAccumulator().mLastCaller); + TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + + if (tree_node.mLastCaller) + { + timer.setParent(tree_node.mLastCaller); } // no need to push up tree on first use, flag can be set spuriously - timer.getPrimaryAccumulator().mMoveUpTree = false; + tree_node.mMoveUpTree = false; } } } - // bump timers up tree if they've been flagged as being in the wrong place + // bump timers up tree if they have been flagged as being in the wrong place // do this in a bottom up order to promote descendants first before promoting ancestors // this preserves partial order derived from current frame's observations for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(BlockTimer::getRootTimer()); @@ -288,15 +294,16 @@ void BlockTimer::buildHierarchy() BlockTimer* timerp = *it; // skip root timer if (timerp == &BlockTimer::getRootTimer()) continue; + TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timerp->getIndex()]; - if (timerp->getPrimaryAccumulator().mMoveUpTree) + if (tree_node.mMoveUpTree) { // since ancestors have already been visited, re-parenting won't affect tree traversal //step up tree, bringing our descendants with us LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; timerp->setParent(timerp->getParent()->getParent()); - timerp->getPrimaryAccumulator().mMoveUpTree = false; + tree_node.mMoveUpTree = false; // don't bubble up any ancestors until descendants are done bubbling up it.skipAncestors(); @@ -322,11 +329,11 @@ void BlockTimer::accumulateTimings() { U64 cur_time = getCPUClockCount64(); - // walk up stack of active timers and accumulate current time while leaving timing structures active - Time* cur_timer = sCurTimerData->mCurTimer; // root defined by parent pointing to self CurTimerData* cur_data = sCurTimerData.get(); - TimerAccumulator& accumulator = sCurTimerData->mTimerData->getPrimaryAccumulator(); + // walk up stack of active timers and accumulate current time while leaving timing structures active + Time* cur_timer = cur_data->mCurTimer; + TimerAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; @@ -431,11 +438,13 @@ void BlockTimer::resetFrame() { BlockTimer& timer = *it; TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); + TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + accumulator.mSelfTimeCounter = 0; accumulator.mTotalTimeCounter = 0; accumulator.mCalls = 0; - accumulator.mLastCaller = NULL; - accumulator.mMoveUpTree = false; + tree_node.mLastCaller = NULL; + tree_node.mMoveUpTree = false; } } @@ -579,32 +588,28 @@ void Time::writeLog(std::ostream& os) } -LLTrace::TimerAccumulator::TimerAccumulator() : mSelfTimeCounter(0), +TimerAccumulator::TimerAccumulator() : mSelfTimeCounter(0), mTotalTimeCounter(0), - mCalls(0), - mLastCaller(NULL), - mActiveCount(0), - mMoveUpTree(false) + mCalls(0) {} -void LLTrace::TimerAccumulator::addSamples( const LLTrace::TimerAccumulator& other ) +void TimerAccumulator::addSamples( const TimerAccumulator& other ) { mSelfTimeCounter += other.mSelfTimeCounter; mTotalTimeCounter += other.mTotalTimeCounter; mCalls += other.mCalls; - if (!mLastCaller) - { - mLastCaller = other.mLastCaller; - } - - //mActiveCount stays the same; - mMoveUpTree |= other.mMoveUpTree; } -void LLTrace::TimerAccumulator::reset( const LLTrace::TimerAccumulator* other ) +void TimerAccumulator::reset( const TimerAccumulator* other ) { mTotalTimeCounter = 0; mSelfTimeCounter = 0; mCalls = 0; } + +TimerTreeNode::TimerTreeNode() +: mLastCaller(NULL), + mActiveCount(0), + mMoveUpTree(false) +{} } diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index cfe2cf5371..9f981480f2 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -37,11 +37,13 @@ class LLMutex; namespace LLTrace { + struct CurTimerData { class Time* mCurTimer; class BlockTimer* mTimerData; U64 mChildTime; + TimerTreeNode* mTimerTreeData; }; class Time @@ -269,20 +271,20 @@ public: // tree structure BlockTimer* mParent; // BlockTimer of caller(parent) std::vector mChildren; - bool mCollapsed; // don't show children - bool mNeedsSorting; // sort children whenever child added + bool mCollapsed, // don't show children + mNeedsSorting; // sort children whenever child added // statics static std::string sLogName; - static bool sMetricLog; - static bool sLog; + static bool sMetricLog, + sLog; static LLThreadLocalPointer sCurTimerData; static U64 sClockResolution; - static S32 sCurFrameIndex; - static S32 sLastFrameIndex; + static S32 sCurFrameIndex, + sLastFrameIndex; static U64 sLastFrameTime; - static bool sPauseHistory; - static bool sResetHistory; + static bool sPauseHistory, + sResetHistory; }; @@ -291,13 +293,12 @@ LL_FORCE_INLINE Time::Time(BlockTimer& timer) #if FAST_TIMER_ON mStartTime = BlockTimer::getCPUClockCount64(); - TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); - accumulator.mActiveCount++; - accumulator.mCalls++; + CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); + TimerTreeNode& tree_node = cur_timer_data->mTimerTreeData[timer.getIndex()]; + tree_node.mActiveCount++; // keep current parent as long as it is active when we are - accumulator.mMoveUpTree |= (timer.mParent->getPrimaryAccumulator().mActiveCount == 0); + tree_node.mMoveUpTree |= (cur_timer_data->mTimerTreeData[timer.mParent->getIndex()].mActiveCount == 0); - CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); // store top of stack mLastTimerData = *cur_timer_data; // push new information @@ -313,13 +314,16 @@ LL_FORCE_INLINE Time::~Time() U64 total_time = BlockTimer::getCPUClockCount64() - mStartTime; CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); TimerAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + TimerTreeNode& tree_node = cur_timer_data->mTimerTreeData[cur_timer_data->mTimerData->getIndex()]; + + accumulator.mCalls++; accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator.mTotalTimeCounter += total_time; - accumulator.mActiveCount--; + tree_node.mActiveCount--; // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator.mLastCaller = mLastTimerData.mTimerData; + tree_node.mLastCaller = mLastTimerData.mTimerData; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 11651ef953..ad9f170aae 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -189,6 +189,11 @@ namespace LLTrace delete[] old_storage; } + size_t size() + { + return mNextStorageSlot; + } + static AccumulatorBuffer& getDefaultBuffer() { static AccumulatorBuffer sBuffer(STATIC_ALLOC); @@ -216,7 +221,7 @@ namespace LLTrace mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } - LL_FORCE_INLINE ACCUMULATOR& getPrimaryAccumulator() + LL_FORCE_INLINE ACCUMULATOR& getPrimaryAccumulator() const { return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; } @@ -399,6 +404,12 @@ namespace LLTrace U64 mSelfTimeCounter, mTotalTimeCounter; U32 mCalls; + }; + + class TimerTreeNode + { + public: + TimerTreeNode(); class BlockTimer* mLastCaller; // used to bootstrap tree construction U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index faaab4c8e7..0a2d79cf3a 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -41,25 +41,29 @@ ThreadRecorder::ThreadRecorder() get_thread_recorder() = this; mFullRecording.start(); - BlockTimer::sCurTimerData = new CurTimerData(); -} + mRootTimerData = new CurTimerData(); + mRootTimerData->mTimerData = &BlockTimer::getRootTimer(); + mRootTimerData->mTimerTreeData = new TimerTreeNode[AccumulatorBuffer::getDefaultBuffer().size()]; + BlockTimer::sCurTimerData = mRootTimerData; -ThreadRecorder::ThreadRecorder( const ThreadRecorder& other ) -: mFullRecording(other.mFullRecording) -{ - get_thread_recorder() = this; - mFullRecording.start(); + mRootTimer = new Time(BlockTimer::getRootTimer()); + mRootTimerData->mCurTimer = mRootTimer; + + mRootTimerData->mTimerTreeData[BlockTimer::getRootTimer().getIndex()].mActiveCount = 1; } ThreadRecorder::~ThreadRecorder() { + delete mRootTimer; + while(mActiveRecordings.size()) { mActiveRecordings.front().mTargetRecording->stop(); } get_thread_recorder() = NULL; - delete BlockTimer::sCurTimerData.get(); BlockTimer::sCurTimerData = NULL; + delete [] mRootTimerData->mTimerTreeData; + delete mRootTimerData; } void ThreadRecorder::activate( Recording* recording ) diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 44fe67384b..277a468a40 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -41,7 +41,6 @@ namespace LLTrace struct ActiveRecording; public: ThreadRecorder(); - ThreadRecorder(const ThreadRecorder& other); virtual ~ThreadRecorder(); @@ -63,6 +62,9 @@ namespace LLTrace }; Recording mFullRecording; std::list mActiveRecordings; + + struct CurTimerData* mRootTimerData; + class Time* mRootTimer; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder -- cgit v1.2.3 From ca37317a1473bb79ef8de4f683231700cb9e062c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 30 Nov 2012 15:48:22 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed crash when sending viewer asset stats --- indra/llcommon/lltracerecording.cpp | 13 +++++++++---- indra/llcommon/lltracerecording.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index e7ed55e8ae..e31e36cb27 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -58,10 +58,6 @@ Recording::Recording( const Recording& other ) mStackTimers = other.mStackTimers; LLStopWatchControlsMixin::initTo(other.getPlayState()); - if (other.isStarted()) - { - handleStart(); - } } @@ -127,6 +123,15 @@ bool Recording::isPrimary() const return mCounts->isPrimary(); } +void Recording::makeUnique() +{ + mCountsFloat.makeUnique(); + mMeasurementsFloat.makeUnique(); + mCounts.makeUnique(); + mMeasurements.makeUnique(); + mStackTimers.makeUnique(); +} + void Recording::appendRecording( const Recording& other ) { mCountsFloat.write()->addSamples(*other.mCountsFloat); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index efc54d240f..e5a21a2d38 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -112,6 +112,8 @@ namespace LLTrace void makePrimary(); bool isPrimary() const; + void makeUnique(); + void appendRecording(const Recording& other); void update(); -- cgit v1.2.3 From ca2207bd35c33b13b122f875a5a7d218f94ca3fc Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 1 Dec 2012 00:17:04 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed scale of reported times moved reset calls to happen at same time so we don't show partial results --- indra/llcommon/llfasttimer.cpp | 6 ++---- indra/llcommon/lltrace.h | 3 ++- indra/llcommon/llunit.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 1b3498cce3..19676cc0c6 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -144,7 +144,6 @@ U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz static LLUnit sCPUClockFrequency = LLProcessorInfo().getCPUFrequency(); - // we drop the low-order byte in our timers, so report a lower frequency #else // If we're not using RDTSC, each fast timer tick is just a performance counter tick. // Not redefining the clock frequency itself (in llprocessor.cpp/calculate_cpu_frequency()) @@ -157,7 +156,7 @@ U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer firstcall = false; } #endif - return sCPUClockFrequency >> 8; + return sCPUClockFrequency; } #endif @@ -390,8 +389,7 @@ void BlockTimer::resetFrame() static S32 call_count = 0; if (call_count % 100 == 0) { - LL_DEBUGS("FastTimers") << "countsPerSecond (32 bit): " << countsPerSecond() << LL_ENDL; - LL_DEBUGS("FastTimers") << "get_clock_count (64 bit): " << get_clock_count() << LL_ENDL; + LL_DEBUGS("FastTimers") << "countsPerSecond: " << countsPerSecond() << LL_ENDL; LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index ad9f170aae..3e43a85e80 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -223,7 +223,8 @@ namespace LLTrace LL_FORCE_INLINE ACCUMULATOR& getPrimaryAccumulator() const { - return AccumulatorBuffer::getPrimaryStorage()[mAccumulatorIndex]; + ACCUMULATOR* accumulator_storage = AccumulatorBuffer::getPrimaryStorage(); + return accumulator_storage[mAccumulatorIndex]; } size_t getIndex() const { return mAccumulatorIndex; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 53570779fc..fc1347b59f 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -71,7 +71,7 @@ template struct LLUnit { typedef LLUnit self_t; - typedef typename STORAGE_TYPE storage_t; + typedef STORAGE_TYPE storage_t; LLUnit(storage_t value = storage_t()) : mValue(value) -- cgit v1.2.3 From 4f9a5d0554c16a81625574a7a4ad6d5070e649e3 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 1 Dec 2012 12:49:01 -0800 Subject: fix for gcc compile errors --- indra/llcommon/llapr.h | 4 ++-- indra/llcommon/llunit.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 7ca0f505ef..199b5291dd 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -249,7 +249,7 @@ public: //******************************************************************************************************************************* }; -class LLThreadLocalPointerBase : LLInstanceTracker +class LLThreadLocalPointerBase : public LLInstanceTracker { public: LLThreadLocalPointerBase() @@ -331,7 +331,7 @@ public: LLThreadLocalPointer(const LLThreadLocalPointer& other) - : LLThreadLocalPointerBase(other) + : LLThreadLocalPointerBase(other) { set(other.get()); } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index fc1347b59f..54902b6322 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -177,6 +177,7 @@ template struct LLUnitStrict : public LLUnit { typedef LLUnitStrict self_t; + typedef typename LLUnit::storage_t storage_t; explicit LLUnitStrict(storage_t value = storage_t()) : LLUnit(value) -- cgit v1.2.3 From 13e4edf1cd664864afa585bc83bbe99d4f743326 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 2 Dec 2012 23:00:36 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system started moving fast timer historical stats over to LLTrace periodic recording --- indra/llcommon/llfasttimer.cpp | 6 +++--- indra/llcommon/lltracerecording.cpp | 11 +++++++++++ indra/llcommon/lltracerecording.h | 22 +++++++++++++--------- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 19676cc0c6..e33cb76eff 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -133,12 +133,12 @@ void BlockTimer::setLogLock(LLMutex* lock) //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer +U64 BlockTimer::countsPerSecond() // counts per second for the *64-bit* timer { - return sClockResolution >> 8; + return sClockResolution; } #else // windows or x86-mac or x86-linux or x86-solaris -U64 BlockTimer::countsPerSecond() // counts per second for the *32-bit* timer +U64 BlockTimer::countsPerSecond() // counts per second for the *64-bit* timer { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index e31e36cb27..ff3ae1e553 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -26,6 +26,7 @@ #include "linden_common.h" #include "lltrace.h" +#include "llfasttimer.h" #include "lltracerecording.h" #include "lltracethreadrecorder.h" #include "llthread.h" @@ -142,6 +143,16 @@ void Recording::appendRecording( const Recording& other ) mElapsedSeconds += other.mElapsedSeconds; } +LLUnit Recording::getSum(const TraceType& stat) const +{ + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::BlockTimer::countsPerSecond(); +} + +LLUnit Recording::getPerSec(const TraceType& stat) const +{ + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::BlockTimer::countsPerSecond() * mElapsedSeconds); +} + F64 Recording::getSum( const TraceType >& stat ) const { return (*mCountsFloat)[stat.getIndex()].getSum(); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index e5a21a2d38..0adea2663b 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -118,6 +118,10 @@ namespace LLTrace void update(); + // Timer accessors + LLUnit getSum(const TraceType& stat) const; + LLUnit getPerSec(const TraceType& stat) const; + // Count accessors F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; @@ -273,18 +277,18 @@ namespace LLTrace Recording& getTotalRecording(); template - typename T getPeriodMin(const TraceType >& stat) const + typename T::value_t getPeriodMin(const TraceType& stat) const { - T min_val = (std::numeric_limits::max)(); + typename T::value_t min_val = (std::numeric_limits::max)(); for (S32 i = 0; i < mNumPeriods; i++) { min_val = llmin(min_val, mRecordingPeriods[i].getSum(stat)); } - return (T)min_val; + return min_val; } template - F64 getPeriodMinPerSec(const TraceType >& stat) const + F64 getPeriodMinPerSec(const TraceType& stat) const { F64 min_val = (std::numeric_limits::max)(); for (S32 i = 0; i < mNumPeriods; i++) @@ -295,9 +299,9 @@ namespace LLTrace } template - T getPeriodMax(const TraceType >& stat) const + typename T::value_t getPeriodMax(const TraceType& stat) const { - T max_val = (std::numeric_limits::min)(); + typename T::value_t max_val = (std::numeric_limits::min)(); for (S32 i = 0; i < mNumPeriods; i++) { max_val = llmax(max_val, mRecordingPeriods[i].getSum(stat)); @@ -306,7 +310,7 @@ namespace LLTrace } template - F64 getPeriodMaxPerSec(const TraceType >& stat) const + F64 getPeriodMaxPerSec(const TraceType& stat) const { F64 max_val = (std::numeric_limits::min)(); for (S32 i = 0; i < mNumPeriods; i++) @@ -317,7 +321,7 @@ namespace LLTrace } template - F64 getPeriodMean(const TraceType >& stat) const + F64 getPeriodMean(const TraceType& stat) const { F64 mean = 0.0; F64 count = 0; @@ -334,7 +338,7 @@ namespace LLTrace } template - F64 getPeriodMeanPerSec(const TraceType >& stat) const + F64 getPeriodMeanPerSec(const TraceType& stat) const { F64 mean = 0.0; F64 count = 0; -- cgit v1.2.3 From 407e5013f3845208e0a60e26e8f0a7fad997df5d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 3 Dec 2012 19:54:53 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system converted fast timer view over to new lltrace mechanisms --- indra/llcommon/llfasttimer.cpp | 538 ++++++++++++--------------- indra/llcommon/llfasttimer.h | 111 +++--- indra/llcommon/llmetricperformancetester.cpp | 4 +- indra/llcommon/lltrace.h | 39 +- indra/llcommon/lltracerecording.cpp | 21 +- indra/llcommon/lltracerecording.h | 8 +- indra/llcommon/lltracethreadrecorder.cpp | 12 +- indra/llcommon/lltracethreadrecorder.h | 2 +- indra/llcommon/llunit.h | 8 +- 9 files changed, 333 insertions(+), 410 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e33cb76eff..cf7655acf7 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -34,6 +34,7 @@ #include "llsdserialize.h" #include "llunit.h" #include "llsd.h" +#include "lltracerecording.h" #include #include @@ -58,22 +59,22 @@ namespace LLTrace ////////////////////////////////////////////////////////////////////////////// // statics -S32 BlockTimer::sCurFrameIndex = -1; -S32 BlockTimer::sLastFrameIndex = -1; -U64 BlockTimer::sLastFrameTime = BlockTimer::getCPUClockCount64(); -bool BlockTimer::sPauseHistory = 0; -bool BlockTimer::sResetHistory = 0; -bool BlockTimer::sLog = false; -std::string BlockTimer::sLogName = ""; -bool BlockTimer::sMetricLog = false; +S32 TimeBlock::sCurFrameIndex = -1; +S32 TimeBlock::sLastFrameIndex = -1; +U64 TimeBlock::sLastFrameTime = TimeBlock::getCPUClockCount64(); +bool TimeBlock::sPauseHistory = 0; +bool TimeBlock::sResetHistory = 0; +bool TimeBlock::sLog = false; +std::string TimeBlock::sLogName = ""; +bool TimeBlock::sMetricLog = false; #if LL_LINUX || LL_SOLARIS -U64 BlockTimer::sClockResolution = 1000000000; // Nanosecond resolution +U64 TimeBlock::sClockResolution = 1000000000; // Nanosecond resolution #else -U64 BlockTimer::sClockResolution = 1000000; // Microsecond resolution +U64 TimeBlock::sClockResolution = 1000000; // Microsecond resolution #endif -LLThreadLocalPointer BlockTimer::sCurTimerData; +LLThreadLocalPointer TimeBlock::sCurTimerData; static LLMutex* sLogLock = NULL; static std::queue sLogQueue; @@ -82,13 +83,13 @@ static std::queue sLogQueue; // FIXME: move these declarations to the relevant modules // helper functions -typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; +typedef LLTreeDFSPostIter timer_tree_bottom_up_iterator_t; -static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(BlockTimer& id) +static timer_tree_bottom_up_iterator_t begin_timer_tree_bottom_up(TimeBlock& id) { return timer_tree_bottom_up_iterator_t(&id, - boost::bind(boost::mem_fn(&BlockTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&BlockTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&TimeBlock::beginChildren), _1), + boost::bind(boost::mem_fn(&TimeBlock::endChildren), _1)); } static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() @@ -96,14 +97,14 @@ static timer_tree_bottom_up_iterator_t end_timer_tree_bottom_up() return timer_tree_bottom_up_iterator_t(); } -typedef LLTreeDFSIter timer_tree_dfs_iterator_t; +typedef LLTreeDFSIter timer_tree_dfs_iterator_t; -static timer_tree_dfs_iterator_t begin_timer_tree(BlockTimer& id) +static timer_tree_dfs_iterator_t begin_timer_tree(TimeBlock& id) { return timer_tree_dfs_iterator_t(&id, - boost::bind(boost::mem_fn(&BlockTimer::beginChildren), _1), - boost::bind(boost::mem_fn(&BlockTimer::endChildren), _1)); + boost::bind(boost::mem_fn(&TimeBlock::beginChildren), _1), + boost::bind(boost::mem_fn(&TimeBlock::endChildren), _1)); } static timer_tree_dfs_iterator_t end_timer_tree() @@ -112,20 +113,29 @@ static timer_tree_dfs_iterator_t end_timer_tree() } -BlockTimer& BlockTimer::getRootTimer() +// sort child timers by name +struct SortTimerByName { - static BlockTimer root_timer("root", true, NULL); + bool operator()(const TimeBlock* i1, const TimeBlock* i2) + { + return i1->getName() < i2->getName(); + } +}; + +TimeBlock& TimeBlock::getRootTimer() +{ + static TimeBlock root_timer("root", true, NULL); return root_timer; } -void BlockTimer::pushLog(LLSD log) +void TimeBlock::pushLog(LLSD log) { LLMutexLock lock(sLogLock); sLogQueue.push(log); } -void BlockTimer::setLogLock(LLMutex* lock) +void TimeBlock::setLogLock(LLMutex* lock) { sLogLock = lock; } @@ -133,12 +143,12 @@ void BlockTimer::setLogLock(LLMutex* lock) //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -U64 BlockTimer::countsPerSecond() // counts per second for the *64-bit* timer +U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer { return sClockResolution; } #else // windows or x86-mac or x86-linux or x86-solaris -U64 BlockTimer::countsPerSecond() // counts per second for the *64-bit* timer +U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz @@ -160,13 +170,10 @@ U64 BlockTimer::countsPerSecond() // counts per second for the *64-bit* timer } #endif -BlockTimer::BlockTimer(const char* name, bool open, BlockTimer* parent) +TimeBlock::TimeBlock(const char* name, bool open, TimeBlock* parent) : TraceType(name), mCollapsed(true), mParent(NULL), - mTreeTimeCounter(0), - mCountAverage(0), - mCallAverage(0), mNeedsSorting(false) { setCollapsed(!open); @@ -179,37 +186,26 @@ BlockTimer::BlockTimer(const char* name, bool open, BlockTimer* parent) { mParent = this; } - - mCountHistory = new U64[HISTORY_NUM]; - memset(mCountHistory, 0, sizeof(U64) * HISTORY_NUM); - mCallHistory = new U32[HISTORY_NUM]; - memset(mCallHistory, 0, sizeof(U32) * HISTORY_NUM); } -BlockTimer::~BlockTimer() -{ - delete[] mCountHistory; - delete[] mCallHistory; -} - -void BlockTimer::setParent(BlockTimer* parent) +void TimeBlock::setParent(TimeBlock* parent) { llassert_always(parent != this); llassert_always(parent != NULL); if (mParent) { - // subtract our accumulated from previous parent - for (S32 i = 0; i < HISTORY_NUM; i++) - { - mParent->mCountHistory[i] -= mCountHistory[i]; - } + //// subtract our accumulated from previous parent + //for (S32 i = 0; i < HISTORY_NUM; i++) + //{ + // mParent->mCountHistory[i] -= mCountHistory[i]; + //} - // subtract average timing from previous parent - mParent->mCountAverage -= mCountAverage; + //// subtract average timing from previous parent + //mParent->mCountAverage -= mCountAverage; - std::vector& children = mParent->getChildren(); - std::vector::iterator found_it = std::find(children.begin(), children.end(), this); + std::vector& children = mParent->getChildren(); + std::vector::iterator found_it = std::find(children.begin(), children.end(), this); if (found_it != children.end()) { children.erase(found_it); @@ -224,10 +220,10 @@ void BlockTimer::setParent(BlockTimer* parent) } } -S32 BlockTimer::getDepth() +S32 TimeBlock::getDepth() { S32 depth = 0; - BlockTimer* timerp = mParent; + TimeBlock* timerp = mParent; while(timerp) { depth++; @@ -238,291 +234,152 @@ S32 BlockTimer::getDepth() } // static -void BlockTimer::processTimes() +void TimeBlock::processTimes() { - if (getCurFrameIndex() < 0) return; - - buildHierarchy(); - accumulateTimings(); -} - -// sort child timers by name -struct SortTimerByName -{ - bool operator()(const BlockTimer* i1, const BlockTimer* i2) - { - return i1->getName() < i2->getName(); - } -}; - -//static -void BlockTimer::buildHierarchy() -{ - if (getCurFrameIndex() < 0 ) return; - - // set up initial tree + //void TimeBlock::buildHierarchy() { - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; ++it) + // set up initial tree { - BlockTimer& timer = *it; - if (&timer == &BlockTimer::getRootTimer()) continue; - - // bootstrap tree construction by attaching to last timer to be on stack - // when this timer was called - if (timer.mParent == &BlockTimer::getRootTimer()) + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; ++it) { - TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + TimeBlock& timer = *it; + if (&timer == &TimeBlock::getRootTimer()) continue; - if (tree_node.mLastCaller) + // bootstrap tree construction by attaching to last timer to be on stack + // when this timer was called + if (timer.mParent == &TimeBlock::getRootTimer()) { - timer.setParent(tree_node.mLastCaller); + TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + + if (tree_node.mLastCaller) + { + timer.setParent(tree_node.mLastCaller); + } + // no need to push up tree on first use, flag can be set spuriously + tree_node.mMoveUpTree = false; } - // no need to push up tree on first use, flag can be set spuriously - tree_node.mMoveUpTree = false; } } - } - - // bump timers up tree if they have been flagged as being in the wrong place - // do this in a bottom up order to promote descendants first before promoting ancestors - // this preserves partial order derived from current frame's observations - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(BlockTimer::getRootTimer()); - it != end_timer_tree_bottom_up(); - ++it) - { - BlockTimer* timerp = *it; - // skip root timer - if (timerp == &BlockTimer::getRootTimer()) continue; - TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timerp->getIndex()]; - if (tree_node.mMoveUpTree) + // bump timers up tree if they have been flagged as being in the wrong place + // do this in a bottom up order to promote descendants first before promoting ancestors + // this preserves partial order derived from current frame's observations + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); + it != end_timer_tree_bottom_up(); + ++it) { - // since ancestors have already been visited, re-parenting won't affect tree traversal - //step up tree, bringing our descendants with us - LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << - " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; - timerp->setParent(timerp->getParent()->getParent()); - tree_node.mMoveUpTree = false; + TimeBlock* timerp = *it; + // skip root timer + if (timerp == &TimeBlock::getRootTimer()) continue; + TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timerp->getIndex()]; - // don't bubble up any ancestors until descendants are done bubbling up - it.skipAncestors(); - } - } + if (tree_node.mMoveUpTree) + { + // since ancestors have already been visited, re-parenting won't affect tree traversal + //step up tree, bringing our descendants with us + LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << + " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; + timerp->setParent(timerp->getParent()->getParent()); + tree_node.mMoveUpTree = false; - // sort timers by time last called, so call graph makes sense - for(timer_tree_dfs_iterator_t it = begin_timer_tree(BlockTimer::getRootTimer()); - it != end_timer_tree(); - ++it) - { - BlockTimer* timerp = (*it); - if (timerp->mNeedsSorting) - { - std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); + // don't bubble up any ancestors until descendants are done bubbling up + it.skipAncestors(); + } } - timerp->mNeedsSorting = false; - } -} - -//static -void BlockTimer::accumulateTimings() -{ - U64 cur_time = getCPUClockCount64(); - - // root defined by parent pointing to self - CurTimerData* cur_data = sCurTimerData.get(); - // walk up stack of active timers and accumulate current time while leaving timing structures active - Time* cur_timer = cur_data->mCurTimer; - TimerAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); - while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) - { - U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; - cur_data->mChildTime = 0; - accumulator.mSelfTimeCounter += self_time_delta; - accumulator.mTotalTimeCounter += cumulative_time_delta; - - cur_timer->mStartTime = cur_time; - cur_data = &cur_timer->mLastTimerData; - cur_data->mChildTime += cumulative_time_delta; - if (cur_data->mTimerData) + // sort timers by time last called, so call graph makes sense + for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimer()); + it != end_timer_tree(); + ++it) { - accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + TimeBlock* timerp = (*it); + if (timerp->mNeedsSorting) + { + std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); + } + timerp->mNeedsSorting = false; } - - cur_timer = cur_timer->mLastTimerData.mCurTimer; } - - // traverse tree in DFS post order, or bottom up - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(BlockTimer::getRootTimer()); - it != end_timer_tree_bottom_up(); - ++it) + + //void TimeBlock::accumulateTimings() { - BlockTimer* timerp = (*it); - TimerAccumulator& accumulator = timerp->getPrimaryAccumulator(); - timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; - for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) - { - timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; - } - - S32 cur_frame = getCurFrameIndex(); - if (cur_frame >= 0) + U64 cur_time = getCPUClockCount64(); + + // root defined by parent pointing to self + CurTimerData* cur_data = sCurTimerData.get(); + // walk up stack of active timers and accumulate current time while leaving timing structures active + BlockTimer* cur_timer = cur_data->mCurTimer; + TimeBlockAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { - // update timer history - int hidx = cur_frame % HISTORY_NUM; + U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; + U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; + cur_data->mChildTime = 0; + accumulator.mSelfTimeCounter += self_time_delta; + accumulator.mTotalTimeCounter += cumulative_time_delta; - timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; - timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); - timerp->mCallHistory[hidx] = accumulator.mCalls; - timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + accumulator.mCalls) / (cur_frame+1); - } - } -} + cur_timer->mStartTime = cur_time; -// static -void BlockTimer::resetFrame() -{ - if (sLog) - { //output current frame counts to performance log - - static S32 call_count = 0; - if (call_count % 100 == 0) - { - LL_DEBUGS("FastTimers") << "countsPerSecond: " << countsPerSecond() << LL_ENDL; - LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; - LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; - LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; - LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64()) / (LLUnit(LLProcessorInfo().getCPUFrequency())) << LL_ENDL; - } - call_count++; - - F64 iclock_freq = 1000.0 / get_clock_count(); // good place to calculate clock frequency - - F64 total_time = 0; - LLSD sd; - - { - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), - end_it = LLInstanceTracker::endInstances(); - it != end_it; - ++it) + cur_data = &cur_timer->mLastTimerData; + cur_data->mChildTime += cumulative_time_delta; + if (cur_data->mTimerData) { - BlockTimer& timer = *it; - TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); - sd[timer.getName()]["Time"] = (LLSD::Real) (accumulator.mSelfTimeCounter*iclock_freq); - sd[timer.getName()]["Calls"] = (LLSD::Integer) accumulator.mCalls; - - // computing total time here because getting the root timer's getCountHistory - // doesn't work correctly on the first frame - total_time = total_time + accumulator.mSelfTimeCounter * iclock_freq; + accumulator = cur_data->mTimerData->getPrimaryAccumulator(); } - } - sd["Total"]["Time"] = (LLSD::Real) total_time; - sd["Total"]["Calls"] = (LLSD::Integer) 1; - - { - LLMutexLock lock(sLogLock); - sLogQueue.push(sd); + cur_timer = cur_timer->mLastTimerData.mCurTimer; } - } - - // reset for next frame - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), - end_it = LLInstanceTracker::endInstances(); - it != end_it; - ++it) - { - BlockTimer& timer = *it; - TimerAccumulator& accumulator = timer.getPrimaryAccumulator(); - TimerTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; - - accumulator.mSelfTimeCounter = 0; - accumulator.mTotalTimeCounter = 0; - accumulator.mCalls = 0; - tree_node.mLastCaller = NULL; - tree_node.mMoveUpTree = false; - } -} - -//static -void BlockTimer::reset() -{ - resetFrame(); // reset frame data - - // walk up stack of active timers and reset start times to current time - // effectively zeroing out any accumulated time - U64 cur_time = getCPUClockCount64(); - - // root defined by parent pointing to self - CurTimerData* cur_data = sCurTimerData.get(); - Time* cur_timer = cur_data->mCurTimer; - while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) - { - cur_timer->mStartTime = cur_time; - cur_data->mChildTime = 0; - - cur_data = &cur_timer->mLastTimerData; - cur_timer = cur_data->mCurTimer; - } - // reset all history - { - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), - end_it = LLInstanceTracker::endInstances(); - it != end_it; - ++it) - { - BlockTimer& timer = *it; - if (&timer != &BlockTimer::getRootTimer()) - { - timer.setParent(&BlockTimer::getRootTimer()); - } - - timer.mCountAverage = 0; - timer.mCallAverage = 0; - memset(timer.mCountHistory, 0, sizeof(U64) * HISTORY_NUM); - memset(timer.mCallHistory, 0, sizeof(U32) * HISTORY_NUM); - } + // traverse tree in DFS post order, or bottom up + //for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); + // it != end_timer_tree_bottom_up(); + // ++it) + //{ + // TimeBlock* timerp = (*it); + // TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); + // timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; + // for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) + // { + // timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; + // } + + //S32 cur_frame = getCurFrameIndex(); + //if (cur_frame >= 0) + //{ + // // update timer history + + // int hidx = getCurFrameIndex() % HISTORY_NUM; + + // timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; + // timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); + // timerp->mCallHistory[hidx] = accumulator.mCalls; + // timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + accumulator.mCalls) / (cur_frame+1); + //} + //} } - - sLastFrameIndex = 0; - sCurFrameIndex = 0; } -U64 BlockTimer::getHistoricalCount(S32 history_index) const -{ - S32 history_idx = (getLastFrameIndex() + history_index) % HISTORY_NUM; - return mCountHistory[history_idx]; -} - -U32 BlockTimer::getHistoricalCalls(S32 history_index ) const -{ - S32 history_idx = (getLastFrameIndex() + history_index) % HISTORY_NUM; - return mCallHistory[history_idx]; -} -std::vector::const_iterator BlockTimer::beginChildren() +std::vector::const_iterator TimeBlock::beginChildren() { return mChildren.begin(); } -std::vector::const_iterator BlockTimer::endChildren() +std::vector::const_iterator TimeBlock::endChildren() { return mChildren.end(); } -std::vector& BlockTimer::getChildren() +std::vector& TimeBlock::getChildren() { return mChildren; } //static -void BlockTimer::nextFrame() +void TimeBlock::nextFrame() { get_clock_count(); // good place to calculate clock frequency - U64 frame_time = BlockTimer::getCPUClockCount64(); + U64 frame_time = TimeBlock::getCPUClockCount64(); if ((frame_time - sLastFrameTime) >> 8 > 0xffffffff) { llinfos << "Slow frame, fast timers inaccurate" << llendl; @@ -530,31 +387,88 @@ void BlockTimer::nextFrame() if (!sPauseHistory) { - BlockTimer::processTimes(); + TimeBlock::processTimes(); sLastFrameIndex = sCurFrameIndex++; } // get ready for next frame - BlockTimer::resetFrame(); + //void TimeBlock::resetFrame() + { + if (sLog) + { //output current frame counts to performance log + + static S32 call_count = 0; + if (call_count % 100 == 0) + { + LL_DEBUGS("FastTimers") << "countsPerSecond: " << countsPerSecond() << LL_ENDL; + LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; + LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; + LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; + LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64()) / (LLUnit(LLProcessorInfo().getCPUFrequency())) << LL_ENDL; + } + call_count++; + + LLUnit total_time = 0; + LLSD sd; + + { + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) + { + TimeBlock& timer = *it; + LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); + sd[timer.getName()]["Time"] = (LLSD::Real) (frame_recording.getLastRecordingPeriod().getSum(timer).value()); + sd[timer.getName()]["Calls"] = (LLSD::Integer) (frame_recording.getLastRecordingPeriod().getSum(timer.callCount())); + + // computing total time here because getting the root timer's getCountHistory + // doesn't work correctly on the first frame + total_time += frame_recording.getLastRecordingPeriod().getSum(timer); + } + } + + sd["Total"]["Time"] = (LLSD::Real) total_time.value(); + sd["Total"]["Calls"] = (LLSD::Integer) 1; + + { + LLMutexLock lock(sLogLock); + sLogQueue.push(sd); + } + } + + // reset for next frame + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) + { + TimeBlock& timer = *it; + TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + + tree_node.mLastCaller = NULL; + tree_node.mMoveUpTree = false; + } + } sLastFrameTime = frame_time; } //static -void Time::dumpCurTimes() +void TimeBlock::dumpCurTimes() { // accumulate timings, etc. - BlockTimer::processTimes(); + processTimes(); - F64 clock_freq = (F64)get_clock_count(); - F64 iclock_freq = 1000.0 / clock_freq; // clock_ticks -> milliseconds - // walk over timers in depth order and output timings - for(timer_tree_dfs_iterator_t it = begin_timer_tree(BlockTimer::getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimer()); it != end_timer_tree(); ++it) { - BlockTimer* timerp = (*it); - F64 total_time_ms = ((F64)timerp->getHistoricalCount(0) * iclock_freq); + LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); + TimeBlock* timerp = (*it); + LLUnit total_time_ms = frame_recording.getLastRecordingPeriod().getSum(*timerp); + U32 num_calls = frame_recording.getLastRecordingPeriod().getSum(timerp->callCount()); + // Don't bother with really brief times, keep output concise if (total_time_ms < 0.1) continue; @@ -564,17 +478,16 @@ void Time::dumpCurTimes() out_str << "\t"; } - out_str << timerp->getName() << " " - << std::setprecision(3) << total_time_ms << " ms, " - << timerp->getHistoricalCalls(0) << " calls"; + << std::setprecision(3) << total_time_ms.as() << " ms, " + << num_calls << " calls"; llinfos << out_str.str() << llendl; } } //static -void Time::writeLog(std::ostream& os) +void TimeBlock::writeLog(std::ostream& os) { while (!sLogQueue.empty()) { @@ -585,29 +498,34 @@ void Time::writeLog(std::ostream& os) } } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// TimeBlockAccumulator +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -TimerAccumulator::TimerAccumulator() : mSelfTimeCounter(0), +TimeBlockAccumulator::TimeBlockAccumulator() +: mSelfTimeCounter(0), mTotalTimeCounter(0), mCalls(0) {} -void TimerAccumulator::addSamples( const TimerAccumulator& other ) +void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) { mSelfTimeCounter += other.mSelfTimeCounter; mTotalTimeCounter += other.mTotalTimeCounter; mCalls += other.mCalls; } -void TimerAccumulator::reset( const TimerAccumulator* other ) +void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) { mTotalTimeCounter = 0; mSelfTimeCounter = 0; mCalls = 0; } -TimerTreeNode::TimerTreeNode() +TimeBlockTreeNode::TimeBlockTreeNode() : mLastCaller(NULL), mActiveCount(0), mMoveUpTree(false) {} -} + +} // namespace LLTrace diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 9f981480f2..e3d99a9e4b 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -40,28 +40,21 @@ namespace LLTrace struct CurTimerData { - class Time* mCurTimer; - class BlockTimer* mTimerData; + class BlockTimer* mCurTimer; + class TimeBlock* mTimerData; U64 mChildTime; - TimerTreeNode* mTimerTreeData; + TimeBlockTreeNode* mTimerTreeData; }; -class Time +class BlockTimer { public: - friend class BlockTimer; - typedef Time self_t; - typedef class BlockTimer DeclareTimer; + friend class TimeBlock; + typedef BlockTimer self_t; + typedef class TimeBlock DeclareTimer; - Time(BlockTimer& timer); - ~Time(); - -public: - // dumps current cumulative frame stats to log - // call nextFrame() to reset timers - static void dumpCurTimes(); - - static void writeLog(std::ostream& os); + BlockTimer(TimeBlock& timer); + ~BlockTimer(); private: @@ -69,40 +62,41 @@ private: CurTimerData mLastTimerData; }; -// stores a "named" timer instance to be reused via multiple Time stack instances -class BlockTimer -: public TraceType, - public LLInstanceTracker +// stores a "named" timer instance to be reused via multiple BlockTimer stack instances +class TimeBlock +: public TraceType, + public LLInstanceTracker { public: - BlockTimer(const char* name, bool open = false, BlockTimer* parent = &getRootTimer()); - ~BlockTimer(); + TimeBlock(const char* name, bool open = false, TimeBlock* parent = &getRootTimer()); enum { HISTORY_NUM = 300 }; - BlockTimer* getParent() const { return mParent; } - void setParent(BlockTimer* parent); + TimeBlock* getParent() const { return mParent; } + void setParent(TimeBlock* parent); S32 getDepth(); - typedef std::vector::const_iterator child_const_iter; + typedef std::vector::const_iterator child_const_iter; child_const_iter beginChildren(); child_const_iter endChildren(); - std::vector& getChildren(); + std::vector& getChildren(); void setCollapsed(bool collapsed) { mCollapsed = collapsed; } bool getCollapsed() const { return mCollapsed; } - U32 getCountAverage() const { return mCountAverage; } - U32 getCallAverage() const { return mCallAverage; } - - U64 getHistoricalCount(S32 history_index = 0) const; - U32 getHistoricalCalls(S32 history_index = 0) const; + TraceType& callCount() + { + return static_cast&>(*(TraceType*)this); + } - static BlockTimer& getRootTimer(); + static TimeBlock& getRootTimer(); static void pushLog(LLSD sd); static void setLogLock(LLMutex* mutex); - friend class Time; + static void writeLog(std::ostream& os); + // dumps current cumulative frame stats to log + // call nextFrame() to reset timers + static void dumpCurTimes(); ////////////////////////////////////////////////////////////////////////////// // @@ -126,14 +120,14 @@ public: //#undef _interlockedbittestandset //#undef _interlockedbittestandreset - //inline U32 BlockTimer::getCPUClockCount32() + //inline U32 TimeBlock::getCPUClockCount32() //{ // U64 time_stamp = __rdtsc(); // return (U32)(time_stamp >> 8); //} // //// return full timer value, *not* shifted by 8 bits - //inline U64 BlockTimer::getCPUClockCount64() + //inline U64 TimeBlock::getCPUClockCount64() //{ // return __rdtsc(); //} @@ -242,35 +236,16 @@ public: static U64 countsPerSecond(); - // recursive call to gather total time from children - static void accumulateTimings(); - // updates cumulative times and hierarchy, // can be called multiple times in a frame, at any point static void processTimes(); - static void buildHierarchy(); - static void resetFrame(); - static void reset(); // call this once a frame to reset timers static void nextFrame(); - static S32 getLastFrameIndex() { return sLastFrameIndex; } - static S32 getCurFrameIndex() { return sCurFrameIndex; } - - - - // sum of recorded self time and tree time of all children timers (might not match actual recorded time of children if topology is incomplete - U64 mTreeTimeCounter; - - U64 mCountAverage; - U32 mCallAverage; - - U64* mCountHistory; - U32* mCallHistory; - // tree structure - BlockTimer* mParent; // BlockTimer of caller(parent) - std::vector mChildren; + // tree structure, only updated from master trace thread + TimeBlock* mParent; // TimeBlock of caller(parent) + std::vector mChildren; bool mCollapsed, // don't show children mNeedsSorting; // sort children whenever child added @@ -288,13 +263,13 @@ public: }; -LL_FORCE_INLINE Time::Time(BlockTimer& timer) +LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) { #if FAST_TIMER_ON - mStartTime = BlockTimer::getCPUClockCount64(); + mStartTime = TimeBlock::getCPUClockCount64(); - CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); - TimerTreeNode& tree_node = cur_timer_data->mTimerTreeData[timer.getIndex()]; + CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); + TimeBlockTreeNode& tree_node = cur_timer_data->mTimerTreeData[timer.getIndex()]; tree_node.mActiveCount++; // keep current parent as long as it is active when we are tree_node.mMoveUpTree |= (cur_timer_data->mTimerTreeData[timer.mParent->getIndex()].mActiveCount == 0); @@ -308,13 +283,13 @@ LL_FORCE_INLINE Time::Time(BlockTimer& timer) #endif } -LL_FORCE_INLINE Time::~Time() +LL_FORCE_INLINE BlockTimer::~BlockTimer() { #if FAST_TIMER_ON - U64 total_time = BlockTimer::getCPUClockCount64() - mStartTime; - CurTimerData* cur_timer_data = BlockTimer::sCurTimerData.get(); - TimerAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); - TimerTreeNode& tree_node = cur_timer_data->mTimerTreeData[cur_timer_data->mTimerData->getIndex()]; + U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; + CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); + TimeBlockAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + TimeBlockTreeNode& tree_node = cur_timer_data->mTimerTreeData[cur_timer_data->mTimerData->getIndex()]; accumulator.mCalls++; accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; @@ -328,12 +303,12 @@ LL_FORCE_INLINE Time::~Time() // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; - *BlockTimer::sCurTimerData = mLastTimerData; + *TimeBlock::sCurTimerData = mLastTimerData; #endif } } -typedef LLTrace::Time LLFastTimer; +typedef LLTrace::BlockTimer LLFastTimer; #endif // LL_LLFASTTIMER_H diff --git a/indra/llcommon/llmetricperformancetester.cpp b/indra/llcommon/llmetricperformancetester.cpp index 43d98be47b..aaacbfb599 100644 --- a/indra/llcommon/llmetricperformancetester.cpp +++ b/indra/llcommon/llmetricperformancetester.cpp @@ -91,7 +91,7 @@ LLMetricPerformanceTesterBasic* LLMetricPerformanceTesterBasic::getTester(std::s // Return TRUE if this metric is requested or if the general default "catch all" metric is requested BOOL LLMetricPerformanceTesterBasic::isMetricLogRequested(std::string name) { - return (LLTrace::BlockTimer::sMetricLog && ((LLTrace::BlockTimer::sLogName == name) || (LLTrace::BlockTimer::sLogName == DEFAULT_METRIC_NAME))); + return (LLTrace::TimeBlock::sMetricLog && ((LLTrace::TimeBlock::sLogName == name) || (LLTrace::TimeBlock::sLogName == DEFAULT_METRIC_NAME))); } /*static*/ @@ -194,7 +194,7 @@ void LLMetricPerformanceTesterBasic::preOutputTestResults(LLSD* sd) void LLMetricPerformanceTesterBasic::postOutputTestResults(LLSD* sd) { - LLTrace::BlockTimer::pushLog(*sd); + LLTrace::TimeBlock::pushLog(*sd); } void LLMetricPerformanceTesterBasic::outputTestResults() diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 3e43a85e80..9e275da647 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -37,7 +37,7 @@ #include -#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::BlockTimer::Recorder LL_GLUE_TOKENS(block_time_recorder, __COUNTER__)(block_timer); +#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::TimeBlock::Recorder LL_GLUE_TOKENS(block_time_recorder, __COUNTER__)(block_timer); namespace LLTrace { @@ -213,10 +213,10 @@ namespace LLTrace : public LLInstanceTracker, std::string> { public: - TraceType(const char* name, const char* description = NULL) + TraceType(const char* name, const char* description = "") : LLInstanceTracker(name), mName(name), - mDescription(description ? description : "") + mDescription(description) { mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } @@ -392,26 +392,43 @@ namespace LLTrace U32 mNumSamples; }; - class TimerAccumulator + class TimeBlockAccumulator { public: - TimerAccumulator(); - void addSamples(const TimerAccumulator& other); - void reset(const TimerAccumulator* other); + typedef LLUnit value_t; + + // fake class that allows us to view call count aspect of timeblock accumulator + struct CallCountAspect + { + typedef U32 value_t; + }; + + TimeBlockAccumulator(); + void addSamples(const TimeBlockAccumulator& other); + void reset(const TimeBlockAccumulator* other); // // members // U64 mSelfTimeCounter, mTotalTimeCounter; - U32 mCalls; + U32 mCalls; + }; + + template<> + class TraceType + : public TraceType + { + TraceType(const char* name, const char* description = "") + : TraceType(name, description) + {} }; - class TimerTreeNode + class TimeBlockTreeNode { public: - TimerTreeNode(); - class BlockTimer* mLastCaller; // used to bootstrap tree construction + TimeBlockTreeNode(); + class TimeBlock* mLastCaller; // used to bootstrap tree construction U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame }; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index ff3ae1e553..0d4d07faf6 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -44,7 +44,7 @@ Recording::Recording() mMeasurementsFloat(new AccumulatorBuffer >()), mCounts(new AccumulatorBuffer >()), mMeasurements(new AccumulatorBuffer >()), - mStackTimers(new AccumulatorBuffer()) + mStackTimers(new AccumulatorBuffer()) {} Recording::Recording( const Recording& other ) @@ -143,16 +143,27 @@ void Recording::appendRecording( const Recording& other ) mElapsedSeconds += other.mElapsedSeconds; } -LLUnit Recording::getSum(const TraceType& stat) const +LLUnit Recording::getSum(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::BlockTimer::countsPerSecond(); + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); } -LLUnit Recording::getPerSec(const TraceType& stat) const +U32 Recording::getSum(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::BlockTimer::countsPerSecond() * mElapsedSeconds); + return (*mStackTimers)[stat.getIndex()].mCalls; } +LLUnit Recording::getPerSec(const TraceType& stat) const +{ + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); +} + +F32 Recording::getPerSec(const TraceType& stat) const +{ + return (F32)(*mStackTimers)[stat.getIndex()].mCalls / mElapsedSeconds; +} + + F64 Recording::getSum( const TraceType >& stat ) const { return (*mCountsFloat)[stat.getIndex()].getSum(); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 0adea2663b..efed3f662e 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -119,8 +119,10 @@ namespace LLTrace void update(); // Timer accessors - LLUnit getSum(const TraceType& stat) const; - LLUnit getPerSec(const TraceType& stat) const; + LLUnit getSum(const TraceType& stat) const; + U32 getSum(const TraceType& stat) const; + LLUnit getPerSec(const TraceType& stat) const; + F32 getPerSec(const TraceType& stat) const; // Count accessors F64 getSum(const TraceType >& stat) const; @@ -221,7 +223,7 @@ namespace LLTrace LLCopyOnWritePointer > > mMeasurementsFloat; LLCopyOnWritePointer > > mCounts; LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimers; + LLCopyOnWritePointer > mStackTimers; LLTimer mSamplingTimer; F64 mElapsedSeconds; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 0a2d79cf3a..16235473ee 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -42,14 +42,14 @@ ThreadRecorder::ThreadRecorder() mFullRecording.start(); mRootTimerData = new CurTimerData(); - mRootTimerData->mTimerData = &BlockTimer::getRootTimer(); - mRootTimerData->mTimerTreeData = new TimerTreeNode[AccumulatorBuffer::getDefaultBuffer().size()]; - BlockTimer::sCurTimerData = mRootTimerData; + mRootTimerData->mTimerData = &TimeBlock::getRootTimer(); + mRootTimerData->mTimerTreeData = new TimeBlockTreeNode[AccumulatorBuffer::getDefaultBuffer().size()]; + TimeBlock::sCurTimerData = mRootTimerData; - mRootTimer = new Time(BlockTimer::getRootTimer()); + mRootTimer = new BlockTimer(TimeBlock::getRootTimer()); mRootTimerData->mCurTimer = mRootTimer; - mRootTimerData->mTimerTreeData[BlockTimer::getRootTimer().getIndex()].mActiveCount = 1; + mRootTimerData->mTimerTreeData[TimeBlock::getRootTimer().getIndex()].mActiveCount = 1; } ThreadRecorder::~ThreadRecorder() @@ -61,7 +61,7 @@ ThreadRecorder::~ThreadRecorder() mActiveRecordings.front().mTargetRecording->stop(); } get_thread_recorder() = NULL; - BlockTimer::sCurTimerData = NULL; + TimeBlock::sCurTimerData = NULL; delete [] mRootTimerData->mTimerTreeData; delete mRootTimerData; } diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 277a468a40..102b980e44 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -64,7 +64,7 @@ namespace LLTrace std::list mActiveRecordings; struct CurTimerData* mRootTimerData; - class Time* mRootTimer; + class BlockTimer* mRootTimer; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 54902b6322..01e9eb751d 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -180,23 +180,23 @@ struct LLUnitStrict : public LLUnit typedef typename LLUnit::storage_t storage_t; explicit LLUnitStrict(storage_t value = storage_t()) - : LLUnit(value) + : LLUnit(value) {} template LLUnitStrict(LLUnit other) - : LLUnit(convert(other)) + : LLUnit(convert(other)) {} LLUnitStrict(self_t& other) - : LLUnit(other) + : LLUnit(other) {} private: operator storage_t() const { - return value(); + return LLUnit::value(); } }; -- cgit v1.2.3 From 6c7825107f6ebb3dd8697a52aeb5d29a93060dc4 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 4 Dec 2012 19:10:02 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system added copy constructor to periodic recording to allow snapshot generation in fast timer view fixed build errors --- indra/llcommon/lltrace.h | 4 ++-- indra/llcommon/lltracerecording.cpp | 14 ++++++++++++++ indra/llcommon/lltracerecording.h | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 9e275da647..a6b1b227c9 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -213,10 +213,10 @@ namespace LLTrace : public LLInstanceTracker, std::string> { public: - TraceType(const char* name, const char* description = "") + TraceType(const char* name, const char* description = NULL) : LLInstanceTracker(name), mName(name), - mDescription(description) + mDescription(description ? description : "") { mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); } diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 0d4d07faf6..7ed7e57570 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -305,6 +305,20 @@ PeriodicRecording::PeriodicRecording( S32 num_periods, EStopWatchState state) initTo(state); } +PeriodicRecording::PeriodicRecording(PeriodicRecording& other) +: mNumPeriods(other.mNumPeriods), + mCurPeriod(other.mCurPeriod), + mTotalValid(other.mTotalValid), + mTotalRecording(other.mTotalRecording) +{ + mRecordingPeriods = new Recording[mNumPeriods]; + for (S32 i = 0; i < mNumPeriods; i++) + { + mRecordingPeriods[i] = other.mRecordingPeriods[i]; + } +} + + PeriodicRecording::~PeriodicRecording() { delete[] mRecordingPeriods; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index efed3f662e..a3af215dd3 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -234,6 +234,7 @@ namespace LLTrace { public: PeriodicRecording(S32 num_periods, EStopWatchState state = STOPPED); + PeriodicRecording(PeriodicRecording& recording); ~PeriodicRecording(); void nextPeriod(); @@ -261,11 +262,13 @@ namespace LLTrace Recording& getPrevRecordingPeriod(S32 offset) { + offset = llclamp(offset, 0, mNumPeriods - 1); return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; } const Recording& getPrevRecordingPeriod(S32 offset) const { + offset = llclamp(offset, 0, mNumPeriods - 1); return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; } -- cgit v1.2.3 From 68967e7b2b9416ff66cb49ae755fb33d7b81d129 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 5 Dec 2012 14:22:18 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system changed thread id declaration to be local to llthread.cpp and use currentID() uniformly across platforms --- indra/llcommon/llmutex.cpp | 8 -------- indra/llcommon/llthread.cpp | 10 ++++++++-- indra/llcommon/llthread.h | 7 ------- 3 files changed, 8 insertions(+), 17 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp index e6beb9e680..b685bb4d60 100644 --- a/indra/llcommon/llmutex.cpp +++ b/indra/llcommon/llmutex.cpp @@ -83,11 +83,7 @@ void LLMutex::lock() mIsLocked[id] = TRUE; #endif -#if LL_DARWIN mLockingThread = LLThread::currentID(); -#else - mLockingThread = LLThread::sThreadID; -#endif } void LLMutex::unlock() @@ -126,11 +122,7 @@ bool LLMutex::isLocked() bool LLMutex::isSelfLocked() { -#if LL_DARWIN return mLockingThread == LLThread::currentID(); -#else - return mLockingThread == LLThread::sThreadID; -#endif } U32 LLMutex::lockingThread() const diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index 8ce739bf23..6374b5398b 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -62,9 +62,9 @@ #if LL_DARWIN // statically allocated thread local storage not supported in Darwin executable formats #elif LL_WINDOWS -U32 __declspec(thread) LLThread::sThreadID = 0; +U32 __declspec(thread) sThreadID = 0; #elif LL_LINUX -U32 __thread LLThread::sThreadID = 0; +U32 __thread sThreadID = 0; #endif U32 LLThread::sIDIter = 0; @@ -294,7 +294,13 @@ void LLThread::setQuitting() // static U32 LLThread::currentID() { +#if LL_DARWIN + // statically allocated thread local storage not supported in Darwin executable formats return (U32)apr_os_thread_current(); +#else + return sThreadID; +#endif + } // static diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 75222c83f9..92323f5fda 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -39,13 +39,6 @@ class LL_COMMON_API LLThread private: friend class LLMutex; static U32 sIDIter; -#if LL_DARWIN - // statically allocated thread local storage not supported in Darwin executable formats -#elif LL_WINDOWS - static U32 __declspec(thread) LLThread::sThreadID; -#elif LL_LINUX - static U32 __thread LLThread::sThreadID ; -#endif public: typedef enum e_thread_status -- cgit v1.2.3 From 60800dacdd7e9b66ed654af471f2b9e9680cd981 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 6 Dec 2012 00:37:15 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed gcc compile error made LLCopyOnWritePointer contain an LLPointer, not derive from it added type trait to control periodicrecording mean value type --- indra/llcommon/llpointer.h | 50 ++++++++++++++++++------------------- indra/llcommon/lltrace.h | 22 +++++++++++++--- indra/llcommon/lltracerecording.cpp | 2 +- indra/llcommon/lltracerecording.h | 16 +++++------- 4 files changed, 51 insertions(+), 39 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h index 6a3bbeb768..f03551045e 100644 --- a/indra/llcommon/llpointer.h +++ b/indra/llcommon/llpointer.h @@ -166,52 +166,52 @@ protected: }; template -class LLCopyOnWritePointer : public LLPointer +class LLCopyOnWritePointer { public: - typedef LLPointer ref_pointer_t; typedef LLCopyOnWritePointer self_t; LLCopyOnWritePointer() - { - } + {} LLCopyOnWritePointer(Type* ptr) - : LLPointer(ptr) - { - } + : mPointer(ptr) + {} + + LLCopyOnWritePointer(LLPointer& ptr) + : mPointer(ptr) + {} Type* write() { makeUnique(); - return mPointer; + return mPointer.get(); } void makeUnique() { - if (mPointer && mPointer->getNumRefs() > 1) + if (mPointer.notNull() && mPointer.get()->getNumRefs() > 1) { - ref_pointer_t::assign(new Type(*mPointer)); + mPointer = new Type(*mPointer.get()); } } - using ref_pointer_t::operator BOOL; - using ref_pointer_t::operator bool; - using ref_pointer_t::operator!; - - using ref_pointer_t::operator !=; - using ref_pointer_t::operator ==; - using LLPointer::operator =; + operator BOOL() const { return (BOOL)mPointer; } + operator bool() const { return (bool)mPointer; } + bool operator!() const { return !mPointer; } + bool isNull() const { return mPointer.isNull(); } + bool notNull() const { return mPointer.notNull(); } - using LLPointer::operator <; - using LLPointer::operator >; - - - operator Type*() { return mPointer; } - operator const Type*() const { return mPointer; } - Type* operator->() { return mPointer; } - const Type* operator->() const { return mPointer; } + bool operator !=(Type* ptr) const { return (mPointer.get() != ptr); } + bool operator ==(Type* ptr) const { return (mPointer.get() == ptr); } + bool operator ==(const LLCopyOnWritePointer& ptr) const { return (mPointer == ptr.mPointer); } + bool operator < (const LLCopyOnWritePointer& ptr) const { return (mPointer < ptr.mPointer); } + bool operator > (const LLCopyOnWritePointer& ptr) const { return (mPointer > ptr.mPointer); } + operator const Type*() const { return mPointer.get(); } + const Type* operator->() const { return mPointer.get(); } +protected: + LLPointer mPointer; }; #endif diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index a6b1b227c9..6e6bb51e47 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -201,18 +201,27 @@ namespace LLTrace } private: - ACCUMULATOR* mStorage; - size_t mStorageSize; - size_t mNextStorageSlot; + ACCUMULATOR* mStorage; + size_t mStorageSize; + size_t mNextStorageSlot; static LLThreadLocalPointer sPrimaryStorage; }; template LLThreadLocalPointer AccumulatorBuffer::sPrimaryStorage; + //TODO: replace with decltype when C++11 is enabled + template + struct MeanValueType + { + typedef F64 type; + }; + template class TraceType : public LLInstanceTracker, std::string> { public: + typedef typename MeanValueType >::type mean_t; + TraceType(const char* name, const char* description = NULL) : LLInstanceTracker(name), mName(name), @@ -415,6 +424,13 @@ namespace LLTrace U32 mCalls; }; + + template<> + struct MeanValueType > + { + typedef LLUnit type; + }; + template<> class TraceType : public TraceType diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 7ed7e57570..e9b3376dae 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -49,7 +49,7 @@ Recording::Recording() Recording::Recording( const Recording& other ) { - llassert(other.mCountsFloat.get() != NULL); + llassert(other.mCountsFloat.notNull()); mSamplingTimer = other.mSamplingTimer; mElapsedSeconds = other.mElapsedSeconds; mCountsFloat = other.mCountsFloat; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index a3af215dd3..6fd1a105d3 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -326,36 +326,32 @@ namespace LLTrace } template - F64 getPeriodMean(const TraceType& stat) const + typename TraceType::mean_t getPeriodMean(const TraceType& stat) const { - F64 mean = 0.0; - F64 count = 0; + typename TraceType::mean_t mean = 0.0; for (S32 i = 0; i < mNumPeriods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) { - count++; mean += mRecordingPeriods[i].getSum(stat); } } - mean /= (F64)mNumPeriods; + mean /= mNumPeriods; return mean; } template - F64 getPeriodMeanPerSec(const TraceType& stat) const + typename TraceType::mean_t getPeriodMeanPerSec(const TraceType& stat) const { - F64 mean = 0.0; - F64 count = 0; + typename TraceType::mean_t mean = 0.0; for (S32 i = 0; i < mNumPeriods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) { - count++; mean += mRecordingPeriods[i].getPerSec(stat); } } - mean /= count; + mean /= mNumPeriods; return mean; } -- cgit v1.2.3 From 2facd6374517d88f03e3f06b1ccc02565da26b45 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 6 Dec 2012 14:30:56 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved LLUnit compile time errors removed cassert in favor of llstatic_assert --- indra/llcommon/llevents.cpp | 1 - indra/llcommon/llmd5.cpp | 1 - indra/llcommon/llskipmap.h | 6 ++---- indra/llcommon/llunit.h | 7 ++++--- 4 files changed, 6 insertions(+), 9 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llevents.cpp b/indra/llcommon/llevents.cpp index 0855180dcd..1c928b3db8 100644 --- a/indra/llcommon/llevents.cpp +++ b/indra/llcommon/llevents.cpp @@ -41,7 +41,6 @@ #include // std headers #include -#include #include #include // external library headers diff --git a/indra/llcommon/llmd5.cpp b/indra/llcommon/llmd5.cpp index 1409c55d1c..ed80af36d8 100644 --- a/indra/llcommon/llmd5.cpp +++ b/indra/llcommon/llmd5.cpp @@ -76,7 +76,6 @@ documentation and/or software. #include "llmd5.h" -#include #include // cerr // how many bytes to grab at a time when checking files diff --git a/indra/llcommon/llskipmap.h b/indra/llcommon/llskipmap.h index 49ff2928d1..ed53973baa 100644 --- a/indra/llcommon/llskipmap.h +++ b/indra/llcommon/llskipmap.h @@ -210,8 +210,7 @@ inline LLSkipMap::LLSkipMap() : mInsertFirst(NULL), mEquals(defaultEquals) { - // Skipmaps must have binary depth of at least 2 - cassert(BINARY_DEPTH >= 2); + llstatic_assert(BINARY_DEPTH >= 2, "Skipmaps must have binary depth of at least 2"); S32 i; for (i = 0; i < BINARY_DEPTH; i++) @@ -229,8 +228,7 @@ inline LLSkipMap::LLSkipMap(BOOL (*insert_f : mInsertFirst(insert_first), mEquals(equals) { - // Skipmaps must have binary depth of at least 2 - cassert(BINARY_DEPTH >= 2); + llstatic_assert(BINARY_DEPTH >= 2, "Skipmaps must have binary depth of at least 2"); mLevel = 1; S32 i; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 01e9eb751d..e57974c429 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -271,10 +271,11 @@ LLUnit operator * (LLUnit firs } template -void operator * (LLUnit, LLUnit) +LLUnit operator * (LLUnit, LLUnit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + return LLUnit(); } // @@ -293,10 +294,10 @@ LLUnit operator / (LLUnit firs } template -void operator / (LLUnit, LLUnit) +STORAGE_TYPE1 operator / (LLUnit first, LLUnit second) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + return STORAGE_TYPE1(first.value() / second.value()); } #define COMPARISON_OPERATORS(op) \ -- cgit v1.2.3 From 3745d1254acc386acaadd20016123c9a47b8d10c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 6 Dec 2012 17:24:41 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system added unit tests for LLUnit --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llunit.h | 40 ++++----- indra/llcommon/tests/llunit_test.cpp | 156 +++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 20 deletions(-) create mode 100644 indra/llcommon/tests/llunit_test.cpp (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 0f5ded86ed..e1f2eb44fd 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -342,6 +342,7 @@ if (LL_TESTS) LL_ADD_INTEGRATION_TEST(llstring "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lltreeiterators "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lluri "" "${test_libs}") + LL_ADD_INTEGRATION_TEST(llunit "" "${test_libs}") LL_ADD_INTEGRATION_TEST(reflection "" "${test_libs}") LL_ADD_INTEGRATION_TEST(stringize "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lleventdispatcher "" "${test_libs}") diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index e57974c429..1f3ed0237c 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -334,7 +334,7 @@ struct HighestPrecisionType > typedef typename HighestPrecisionType::type_t type_t; }; -#define LL_DECLARE_DERIVED_UNIT(base_unit_name, unit_name, conversion_factor) \ +#define LL_DECLARE_DERIVED_UNIT(conversion_factor, base_unit_name, unit_name) \ struct unit_name \ { \ typedef base_unit_name base_unit_t; \ @@ -358,30 +358,30 @@ struct ConversionFactor \ } struct Bytes { typedef Bytes base_unit_t; }; -LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); -LL_DECLARE_DERIVED_UNIT(Bytes, Megabytes, 1024 * 1024); -LL_DECLARE_DERIVED_UNIT(Bytes, Gigabytes, 1024 * 1024 * 1024); -LL_DECLARE_DERIVED_UNIT(Bytes, Bits, (1.0 / 8.0)); -LL_DECLARE_DERIVED_UNIT(Bytes, Kilobits, (1024 / 8)); -LL_DECLARE_DERIVED_UNIT(Bytes, Megabits, (1024 / 8)); -LL_DECLARE_DERIVED_UNIT(Bytes, Gigabits, (1024 * 1024 * 1024 / 8)); +LL_DECLARE_DERIVED_UNIT(1024, Bytes, Kilobytes); +LL_DECLARE_DERIVED_UNIT(1024 * 1024, Bytes, Megabytes); +LL_DECLARE_DERIVED_UNIT(1024 * 1024 * 1024, Bytes, Gigabytes); +LL_DECLARE_DERIVED_UNIT((1.0 / 8.0), Bytes, Bits); +LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Kilobits); +LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Megabits); +LL_DECLARE_DERIVED_UNIT((1024 * 1024 * 1024 / 8), Bytes, Gigabits); struct Seconds { typedef Seconds base_unit_t; }; -LL_DECLARE_DERIVED_UNIT(Seconds, Minutes, 60); -LL_DECLARE_DERIVED_UNIT(Seconds, Hours, 60 * 60); -LL_DECLARE_DERIVED_UNIT(Seconds, Milliseconds, (1.0 / 1000.0)); -LL_DECLARE_DERIVED_UNIT(Seconds, Microseconds, (1.0 / (1000000.0))); -LL_DECLARE_DERIVED_UNIT(Seconds, Nanoseconds, (1.0 / (1000000000.0))); +LL_DECLARE_DERIVED_UNIT(60, Seconds, Minutes); +LL_DECLARE_DERIVED_UNIT(60 * 60, Seconds, Hours); +LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Seconds, Milliseconds); +LL_DECLARE_DERIVED_UNIT((1.0 / (1000000.0)), Seconds, Microseconds); +LL_DECLARE_DERIVED_UNIT((1.0 / (1000000000.0)), Seconds, Nanoseconds); struct Meters { typedef Meters base_unit_t; }; -LL_DECLARE_DERIVED_UNIT(Meters, Kilometers, 1000); -LL_DECLARE_DERIVED_UNIT(Meters, Centimeters, (1.0 / 100.0)); -LL_DECLARE_DERIVED_UNIT(Meters, Millimeters, (1.0 / 1000.0)); +LL_DECLARE_DERIVED_UNIT(1000, Meters, Kilometers); +LL_DECLARE_DERIVED_UNIT((1.0 / 100.0), Meters, Centimeters); +LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Meters, Millimeters); struct Hertz { typedef Hertz base_unit_t; }; -LL_DECLARE_DERIVED_UNIT(Hertz, Kilohertz, 1000); -LL_DECLARE_DERIVED_UNIT(Hertz, Megahertz, 1000 * 1000); -LL_DECLARE_DERIVED_UNIT(Hertz, Gigahertz, 1000 * 1000 * 1000); -} +LL_DECLARE_DERIVED_UNIT(1000, Hertz, Kilohertz); +LL_DECLARE_DERIVED_UNIT(1000 * 1000, Hertz, Megahertz); +LL_DECLARE_DERIVED_UNIT(1000 * 1000 * 1000, Hertz, Gigahertz); +} // namespace LLUnits #endif // LL_LLUNIT_H diff --git a/indra/llcommon/tests/llunit_test.cpp b/indra/llcommon/tests/llunit_test.cpp new file mode 100644 index 0000000000..a7e9c00740 --- /dev/null +++ b/indra/llcommon/tests/llunit_test.cpp @@ -0,0 +1,156 @@ +/** + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llunit.h" +#include "../test/lltut.h" + +namespace LLUnits +{ + // using powers of 2 to allow strict floating point equality + struct Quatloos { typedef Quatloos base_unit_t; }; + LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); + LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); +} + +namespace tut +{ + using namespace LLUnits; + struct units + { + }; + + typedef test_group units_t; + typedef units_t::object units_object_t; + tut::units_t tut_singleton("LLUnit"); + + // storage type conversions + template<> template<> + void units_object_t::test<1>() + { + LLUnit float_quatloos; + ensure(float_quatloos.value() == 0.f); + + LLUnit int_quatloos; + ensure(int_quatloos.value() == 0); + + int_quatloos = 42; + ensure(int_quatloos.value() == 42); + float_quatloos = int_quatloos; + ensure(float_quatloos.value() == 42.f); + + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + + float_quatloos = 42.1f; + ensure(float_quatloos == 42.1f); + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + LLUnit unsigned_int_quatloos(float_quatloos); + ensure(unsigned_int_quatloos.value() == 42); + } + + // conversions to/from base unit + template<> template<> + void units_object_t::test<2>() + { + LLUnit quatloos(1.f); + ensure(quatloos.value() == 1.f); + LLUnit latinum_bars(quatloos); + ensure(latinum_bars.value() == 1.f / 4.f); + + latinum_bars = 256; + quatloos = latinum_bars; + ensure(quatloos.value() == 1024); + + LLUnit solari(quatloos); + ensure(solari.value() == 4096); + } + + // conversions across non-base units + template<> template<> + void units_object_t::test<3>() + { + LLUnit solari = 4.f; + LLUnit latinum_bars = solari; + ensure(latinum_bars.value() == 0.25f); + } + + // math operations + template<> template<> + void units_object_t::test<4>() + { + LLUnit quatloos = 1.f; + quatloos *= 4.f; + ensure(quatloos.value() == 4); + quatloos = quatloos * 2; + ensure(quatloos.value() == 8); + quatloos = 2.f * quatloos; + ensure(quatloos.value() == 16); + + quatloos += 4.f; + ensure(quatloos.value() == 20); + quatloos += 4; + ensure(quatloos.value() == 24); + quatloos = quatloos + 4; + ensure(quatloos.value() == 28); + quatloos = 4 + quatloos; + ensure(quatloos.value() == 32); + quatloos += quatloos * 3; + ensure(quatloos.value() == 128); + + quatloos -= quatloos / 4 * 3; + ensure(quatloos.value() == 32); + quatloos = quatloos - 8; + ensure(quatloos.value() == 24); + quatloos -= 4; + ensure(quatloos.value() == 20); + quatloos -= 4.f; + ensure(quatloos.value() == 16); + + quatloos *= 2.f; + ensure(quatloos.value() == 32); + quatloos = quatloos * 2.f; + ensure(quatloos.value() == 64); + quatloos = 0.5f * quatloos; + ensure(quatloos.value() == 32); + + quatloos /= 2.f; + ensure(quatloos.value() == 16); + quatloos = quatloos / 4; + ensure(quatloos.value() == 4); + + F32 ratio = quatloos / LLUnit(4.f); + ensure(ratio == 1); + + quatloos += LLUnit(4.f); + ensure(quatloos.value() == 5); + quatloos -= LLUnit(1.f); + ensure(quatloos.value() == 1); + } +} -- cgit v1.2.3 From c99886d94389babc78e92bbfa5084fdd785915af Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Dec 2012 15:20:12 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved unit tests for LLUnit renamed LLUnit to LLUnitImplicit with LLUnit being reserved for explicit units --- indra/llcommon/CMakeLists.txt | 2 +- indra/llcommon/llfasttimer.cpp | 6 +- indra/llcommon/llleap.cpp | 2 +- indra/llcommon/llprocessor.cpp | 2 +- indra/llcommon/llprocessor.h | 2 +- indra/llcommon/lltimer.cpp | 14 +-- indra/llcommon/lltimer.h | 16 +-- indra/llcommon/lltrace.h | 7 +- indra/llcommon/lltracerecording.h | 2 +- indra/llcommon/llunit.h | 193 ++++++++++++++++++++++--------- indra/llcommon/tests/llunit_test.cpp | 156 ------------------------- indra/llcommon/tests/llunits_test.cpp | 208 ++++++++++++++++++++++++++++++++++ 12 files changed, 376 insertions(+), 234 deletions(-) delete mode 100644 indra/llcommon/tests/llunit_test.cpp create mode 100644 indra/llcommon/tests/llunits_test.cpp (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index e1f2eb44fd..5b76703af7 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -342,7 +342,7 @@ if (LL_TESTS) LL_ADD_INTEGRATION_TEST(llstring "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lltreeiterators "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lluri "" "${test_libs}") - LL_ADD_INTEGRATION_TEST(llunit "" "${test_libs}") + LL_ADD_INTEGRATION_TEST(llunits "" "${test_libs}") LL_ADD_INTEGRATION_TEST(reflection "" "${test_libs}") LL_ADD_INTEGRATION_TEST(stringize "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lleventdispatcher "" "${test_libs}") diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index cf7655acf7..37e0fbac0a 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -166,7 +166,7 @@ U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer firstcall = false; } #endif - return sCPUClockFrequency; + return sCPUClockFrequency.value(); } #endif @@ -408,7 +408,7 @@ void TimeBlock::nextFrame() } call_count++; - LLUnit total_time = 0; + LLUnit total_time(0); LLSD sd; { @@ -479,7 +479,7 @@ void TimeBlock::dumpCurTimes() } out_str << timerp->getName() << " " - << std::setprecision(3) << total_time_ms.as() << " ms, " + << std::setprecision(3) << total_time_ms.as().value() << " ms, " << num_calls << " calls"; llinfos << out_str.str() << llendl; diff --git a/indra/llcommon/llleap.cpp b/indra/llcommon/llleap.cpp index 0a57ef1c48..84d2a12f65 100644 --- a/indra/llcommon/llleap.cpp +++ b/indra/llcommon/llleap.cpp @@ -394,7 +394,7 @@ public: LLProcess::WritePipe& childin(mChild->getWritePipe(LLProcess::STDIN)); LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); LLSD nop; - F64 until(LLTimer::getElapsedSeconds() + 2); + F64 until = (LLTimer::getElapsedSeconds() + 2).value(); while (childin.size() && LLTimer::getElapsedSeconds() < until) { mainloop.post(nop); diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 6fe53396ca..5ddfa6fcef 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -875,7 +875,7 @@ LLProcessorInfo::LLProcessorInfo() : mImpl(NULL) LLProcessorInfo::~LLProcessorInfo() {} -LLUnit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } +LLUnitImplicit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } bool LLProcessorInfo::hasSSE() const { return mImpl->hasSSE(); } bool LLProcessorInfo::hasSSE2() const { return mImpl->hasSSE2(); } bool LLProcessorInfo::hasAltivec() const { return mImpl->hasAltivec(); } diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h index 2a21a5c115..fbd427f484 100644 --- a/indra/llcommon/llprocessor.h +++ b/indra/llcommon/llprocessor.h @@ -37,7 +37,7 @@ public: LLProcessorInfo(); ~LLProcessorInfo(); - LLUnit getCPUFrequency() const; + LLUnitImplicit getCPUFrequency() const; bool hasSSE() const; bool hasSSE2() const; bool hasAltivec() const; diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 26063beff0..838155d54d 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -285,14 +285,14 @@ LLTimer::~LLTimer() } // static -LLUnit LLTimer::getTotalTime() +LLUnitImplicit LLTimer::getTotalTime() { // simply call into the implementation function. return totalTime(); } // static -LLUnit LLTimer::getTotalSeconds() +LLUnitImplicit LLTimer::getTotalSeconds() { return U64_to_F64(getTotalTime()) * USEC_TO_SEC_F64; } @@ -341,23 +341,23 @@ U64 getElapsedTimeAndUpdate(U64& lastClockCount) } -LLUnit LLTimer::getElapsedTimeF64() const +LLUnitImplicit LLTimer::getElapsedTimeF64() const { U64 last = mLastClockCount; return (F64)getElapsedTimeAndUpdate(last) * gClockFrequencyInv; } -LLUnit LLTimer::getElapsedTimeF32() const +LLUnitImplicit LLTimer::getElapsedTimeF32() const { return (F32)getElapsedTimeF64(); } -LLUnit LLTimer::getElapsedTimeAndResetF64() +LLUnitImplicit LLTimer::getElapsedTimeAndResetF64() { return (F64)getElapsedTimeAndUpdate(mLastClockCount) * gClockFrequencyInv; } -LLUnit LLTimer::getElapsedTimeAndResetF32() +LLUnitImplicit LLTimer::getElapsedTimeAndResetF32() { return (F32)getElapsedTimeAndResetF64(); } @@ -370,7 +370,7 @@ void LLTimer::setTimerExpirySec(F32 expiration) + (U64)((F32)(expiration * gClockFrequency)); } -LLUnit LLTimer::getRemainingTimeF32() const +LLUnitImplicit LLTimer::getRemainingTimeF32() const { U64 cur_ticks = get_clock_count(); if (cur_ticks > mExpirationTicks) diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index 5cb2b18111..0ba87d1e15 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -67,16 +67,16 @@ public: // Return a high precision number of seconds since the start of // this application instance. - static LLUnit getElapsedSeconds() + static LLUnitImplicit getElapsedSeconds() { return sTimer->getElapsedTimeF64(); } // Return a high precision usec since epoch - static LLUnit getTotalTime(); + static LLUnitImplicit getTotalTime(); // Return a high precision seconds since epoch - static LLUnit getTotalSeconds(); + static LLUnitImplicit getTotalSeconds(); // MANIPULATORS @@ -87,16 +87,16 @@ public: void setTimerExpirySec(F32 expiration); BOOL checkExpirationAndReset(F32 expiration); BOOL hasExpired() const; - LLUnit getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset - LLUnit getElapsedTimeAndResetF64(); + LLUnitImplicit getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset + LLUnitImplicit getElapsedTimeAndResetF64(); - LLUnit getRemainingTimeF32() const; + LLUnitImplicit getRemainingTimeF32() const; static BOOL knownBadTimer(); // ACCESSORS - LLUnit getElapsedTimeF32() const; // Returns elapsed time in seconds - LLUnit getElapsedTimeF64() const; // Returns elapsed time in seconds + LLUnitImplicit getElapsedTimeF32() const; // Returns elapsed time in seconds + LLUnitImplicit getElapsedTimeF64() const; // Returns elapsed time in seconds bool getStarted() const { return mStarted; } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6e6bb51e47..25d95d9670 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -435,6 +435,9 @@ namespace LLTrace class TraceType : public TraceType { + public: + typedef F32 mean_t; + TraceType(const char* name, const char* description = "") : TraceType(name, description) {} @@ -465,7 +468,7 @@ namespace LLTrace void sample(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().sample((storage_t)converted_value); + getPrimaryAccumulator().sample(LLUnits::rawValue(converted_value)); } }; @@ -484,7 +487,7 @@ namespace LLTrace void add(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().add((storage_t)converted_value); + getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); } }; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 6fd1a105d3..f92281cea8 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -205,7 +205,7 @@ namespace LLTrace U32 getSampleCount(const TraceType >& stat) const; U32 getSampleCount(const TraceType >& stat) const; - LLUnit getDuration() const { return mElapsedSeconds; } + LLUnit getDuration() const { return LLUnit(mElapsedSeconds); } private: friend class ThreadRecorder; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 1f3ed0237c..6b023f8287 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -65,6 +65,7 @@ struct ConversionFactor return 1; } }; + } template @@ -73,25 +74,25 @@ struct LLUnit typedef LLUnit self_t; typedef STORAGE_TYPE storage_t; + // value initialization LLUnit(storage_t value = storage_t()) : mValue(value) {} + // unit initialization and conversion template LLUnit(LLUnit other) : mValue(convert(other)) {} - - LLUnit(self_t& other) - : mValue(other.mValue) - {} - + + // value assignment self_t& operator = (storage_t value) { mValue = value; return *this; } + // unit assignment template self_t& operator = (LLUnit other) { @@ -99,11 +100,6 @@ struct LLUnit return *this; } - operator storage_t() const - { - return value(); - } - storage_t value() const { return mValue; @@ -157,7 +153,7 @@ struct LLUnit void operator /= (LLUnit divisor) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(OTHER_UNIT) == 0, "Division of unit types not supported."); + llstatic_assert(sizeof(OTHER_UNIT) == 0, "Illegal in-place division of unit types."); } template @@ -169,34 +165,30 @@ struct LLUnit } protected: - storage_t mValue; }; template -struct LLUnitStrict : public LLUnit +struct LLUnitImplicit : public LLUnit { - typedef LLUnitStrict self_t; + typedef LLUnitImplicit self_t; typedef typename LLUnit::storage_t storage_t; + typedef LLUnit base_t; - explicit LLUnitStrict(storage_t value = storage_t()) - : LLUnit(value) + LLUnitImplicit(storage_t value = storage_t()) + : base_t(value) {} template - LLUnitStrict(LLUnit other) - : LLUnit(convert(other)) + LLUnitImplicit(LLUnit other) + : base_t(convert(other)) {} - LLUnitStrict(self_t& other) - : LLUnit(other) - {} - - -private: + // unlike LLUnit, LLUnitImplicit is *implicitly* convertable to a POD scalar (F32, S32, etc) + // this allows for interoperability with legacy code operator storage_t() const { - return LLUnit::value(); + return value(); } }; @@ -204,7 +196,7 @@ private: // operator + // template -LLUnit operator + (LLUnit first, LLUnit second) +LLUnit operator + (LLUnit first, LLUnit second) { LLUnit result(first); result += second; @@ -227,6 +219,30 @@ LLUnit operator + (SCALAR_TYPE first, LLUnit +LLUnitImplicit operator + (LLUnitImplicit first, LLUnit second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + +template +LLUnitImplicit operator + (LLUnitImplicit first, SCALAR_TYPE second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + +template +LLUnitImplicit operator + (LLUnitImplicit first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + // // operator - // @@ -238,7 +254,6 @@ LLUnit operator - (LLUnit return result; } - template LLUnit operator - (LLUnit first, SCALAR_TYPE second) { @@ -255,6 +270,30 @@ LLUnit operator - (SCALAR_TYPE first, LLUnit +LLUnitImplicit operator - (LLUnitImplicit first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + +template +LLUnitImplicit operator - (LLUnitImplicit first, SCALAR_TYPE second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + +template +LLUnitImplicit operator - (SCALAR_TYPE first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + // // operator * // @@ -278,6 +317,26 @@ LLUnit operator * (LLUnit, return LLUnit(); } +template +LLUnitImplicit operator * (SCALAR_TYPE first, LLUnitImplicit second) +{ + return LLUnitImplicit(first * second.value()); +} + +template +LLUnitImplicit operator * (LLUnitImplicit first, SCALAR_TYPE second) +{ + return LLUnitImplicit(first.value() * second); +} + +template +LLUnitImplicit operator * (LLUnitImplicit, LLUnitImplicit) +{ + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + return LLUnitImplicit(); +} + // // operator / // @@ -300,23 +359,42 @@ STORAGE_TYPE1 operator / (LLUnit first, LLUnit \ -bool operator op (SCALAR_TYPE first, LLUnit second) \ -{ \ - return first op second.value(); \ -} \ - \ -template \ -bool operator op (LLUnit first, SCALAR_TYPE second) \ -{ \ - return first.value() op second; \ -} \ - \ -template \ -bool operator op (LLUnit first, LLUnit second) \ -{ \ - return first.value() op first.convert(second); \ +template +LLUnitImplicit operator / (LLUnitImplicit first, SCALAR_TYPE second) +{ + return LLUnitImplicit(first.value() / second); +} + +template +STORAGE_TYPE1 operator / (LLUnitImplicit first, LLUnitImplicit second) +{ + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + return STORAGE_TYPE1(first.value() / second.value()); +} + +#define COMPARISON_OPERATORS(op) \ +template \ +bool operator op (SCALAR_TYPE first, LLUnit second) \ +{ \ + return first op second.value(); \ +} \ + \ +template \ +bool operator op (LLUnit first, SCALAR_TYPE second) \ +{ \ + return first.value() op second; \ +} \ + \ +template \ +bool operator op (LLUnitImplicit first, LLUnitImplicit second) \ +{ \ + return first.value() op first.convert(second); \ +} \ + \ +template \ + bool operator op (LLUnit first, LLUnit second) \ +{ \ + return first.value() op first.convert(second); \ } COMPARISON_OPERATORS(<) @@ -328,6 +406,15 @@ COMPARISON_OPERATORS(!=) namespace LLUnits { +template +T rawValue(T val) { return val; } + +template +STORAGE_TYPE rawValue(LLUnit val) { return val.value(); } + +template +STORAGE_TYPE rawValue(LLUnitImplicit val) { return val.value(); } + template struct HighestPrecisionType > { @@ -361,22 +448,22 @@ struct Bytes { typedef Bytes base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1024, Bytes, Kilobytes); LL_DECLARE_DERIVED_UNIT(1024 * 1024, Bytes, Megabytes); LL_DECLARE_DERIVED_UNIT(1024 * 1024 * 1024, Bytes, Gigabytes); -LL_DECLARE_DERIVED_UNIT((1.0 / 8.0), Bytes, Bits); -LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Kilobits); -LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Megabits); -LL_DECLARE_DERIVED_UNIT((1024 * 1024 * 1024 / 8), Bytes, Gigabits); +LL_DECLARE_DERIVED_UNIT(1.0 / 8.0, Bytes, Bits); +LL_DECLARE_DERIVED_UNIT(1024 / 8, Bytes, Kilobits); +LL_DECLARE_DERIVED_UNIT(1024 / 8, Bytes, Megabits); +LL_DECLARE_DERIVED_UNIT(1024 * 1024 * 1024 / 8, Bytes, Gigabits); struct Seconds { typedef Seconds base_unit_t; }; LL_DECLARE_DERIVED_UNIT(60, Seconds, Minutes); LL_DECLARE_DERIVED_UNIT(60 * 60, Seconds, Hours); -LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Seconds, Milliseconds); -LL_DECLARE_DERIVED_UNIT((1.0 / (1000000.0)), Seconds, Microseconds); -LL_DECLARE_DERIVED_UNIT((1.0 / (1000000000.0)), Seconds, Nanoseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000.0, Seconds, Milliseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000000.0, Seconds, Microseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000000000.0, Seconds, Nanoseconds); struct Meters { typedef Meters base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1000, Meters, Kilometers); -LL_DECLARE_DERIVED_UNIT((1.0 / 100.0), Meters, Centimeters); -LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Meters, Millimeters); +LL_DECLARE_DERIVED_UNIT(1.0 / 100.0, Meters, Centimeters); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000.0, Meters, Millimeters); struct Hertz { typedef Hertz base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1000, Hertz, Kilohertz); diff --git a/indra/llcommon/tests/llunit_test.cpp b/indra/llcommon/tests/llunit_test.cpp deleted file mode 100644 index a7e9c00740..0000000000 --- a/indra/llcommon/tests/llunit_test.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * @file llsingleton_test.cpp - * @date 2011-08-11 - * @brief Unit test for the LLSingleton class - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "llunit.h" -#include "../test/lltut.h" - -namespace LLUnits -{ - // using powers of 2 to allow strict floating point equality - struct Quatloos { typedef Quatloos base_unit_t; }; - LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); - LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); -} - -namespace tut -{ - using namespace LLUnits; - struct units - { - }; - - typedef test_group units_t; - typedef units_t::object units_object_t; - tut::units_t tut_singleton("LLUnit"); - - // storage type conversions - template<> template<> - void units_object_t::test<1>() - { - LLUnit float_quatloos; - ensure(float_quatloos.value() == 0.f); - - LLUnit int_quatloos; - ensure(int_quatloos.value() == 0); - - int_quatloos = 42; - ensure(int_quatloos.value() == 42); - float_quatloos = int_quatloos; - ensure(float_quatloos.value() == 42.f); - - int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); - - float_quatloos = 42.1f; - ensure(float_quatloos == 42.1f); - int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); - LLUnit unsigned_int_quatloos(float_quatloos); - ensure(unsigned_int_quatloos.value() == 42); - } - - // conversions to/from base unit - template<> template<> - void units_object_t::test<2>() - { - LLUnit quatloos(1.f); - ensure(quatloos.value() == 1.f); - LLUnit latinum_bars(quatloos); - ensure(latinum_bars.value() == 1.f / 4.f); - - latinum_bars = 256; - quatloos = latinum_bars; - ensure(quatloos.value() == 1024); - - LLUnit solari(quatloos); - ensure(solari.value() == 4096); - } - - // conversions across non-base units - template<> template<> - void units_object_t::test<3>() - { - LLUnit solari = 4.f; - LLUnit latinum_bars = solari; - ensure(latinum_bars.value() == 0.25f); - } - - // math operations - template<> template<> - void units_object_t::test<4>() - { - LLUnit quatloos = 1.f; - quatloos *= 4.f; - ensure(quatloos.value() == 4); - quatloos = quatloos * 2; - ensure(quatloos.value() == 8); - quatloos = 2.f * quatloos; - ensure(quatloos.value() == 16); - - quatloos += 4.f; - ensure(quatloos.value() == 20); - quatloos += 4; - ensure(quatloos.value() == 24); - quatloos = quatloos + 4; - ensure(quatloos.value() == 28); - quatloos = 4 + quatloos; - ensure(quatloos.value() == 32); - quatloos += quatloos * 3; - ensure(quatloos.value() == 128); - - quatloos -= quatloos / 4 * 3; - ensure(quatloos.value() == 32); - quatloos = quatloos - 8; - ensure(quatloos.value() == 24); - quatloos -= 4; - ensure(quatloos.value() == 20); - quatloos -= 4.f; - ensure(quatloos.value() == 16); - - quatloos *= 2.f; - ensure(quatloos.value() == 32); - quatloos = quatloos * 2.f; - ensure(quatloos.value() == 64); - quatloos = 0.5f * quatloos; - ensure(quatloos.value() == 32); - - quatloos /= 2.f; - ensure(quatloos.value() == 16); - quatloos = quatloos / 4; - ensure(quatloos.value() == 4); - - F32 ratio = quatloos / LLUnit(4.f); - ensure(ratio == 1); - - quatloos += LLUnit(4.f); - ensure(quatloos.value() == 5); - quatloos -= LLUnit(1.f); - ensure(quatloos.value() == 1); - } -} diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp new file mode 100644 index 0000000000..2a941e8229 --- /dev/null +++ b/indra/llcommon/tests/llunits_test.cpp @@ -0,0 +1,208 @@ +/** + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llunit.h" +#include "../test/lltut.h" + +namespace LLUnits +{ + // using powers of 2 to allow strict floating point equality + struct Quatloos { typedef Quatloos base_unit_t; }; + LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); + LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); +} + +namespace tut +{ + using namespace LLUnits; + struct units + { + }; + + typedef test_group units_t; + typedef units_t::object units_object_t; + tut::units_t tut_singleton("LLUnit"); + + // storage type conversions + template<> template<> + void units_object_t::test<1>() + { + LLUnit float_quatloos; + ensure(float_quatloos.value() == 0.f); + + LLUnit int_quatloos; + ensure(int_quatloos.value() == 0); + + int_quatloos = 42; + ensure(int_quatloos.value() == 42); + float_quatloos = int_quatloos; + ensure(float_quatloos.value() == 42.f); + + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + + float_quatloos = 42.1f; + ensure(float_quatloos.value() == 42.1f); + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + LLUnit unsigned_int_quatloos(float_quatloos); + ensure(unsigned_int_quatloos.value() == 42); + } + + // conversions to/from base unit + template<> template<> + void units_object_t::test<2>() + { + LLUnit quatloos(1.f); + ensure(quatloos.value() == 1.f); + LLUnit latinum_bars(quatloos); + ensure(latinum_bars.value() == 1.f / 4.f); + + latinum_bars = 256; + quatloos = latinum_bars; + ensure(quatloos.value() == 1024); + + LLUnit solari(quatloos); + ensure(solari.value() == 4096); + } + + // conversions across non-base units + template<> template<> + void units_object_t::test<3>() + { + LLUnit solari = 4.f; + LLUnit latinum_bars = solari; + ensure(latinum_bars.value() == 0.25f); + } + + // math operations + template<> template<> + void units_object_t::test<4>() + { + LLUnit quatloos = 1.f; + quatloos *= 4.f; + ensure(quatloos.value() == 4); + quatloos = quatloos * 2; + ensure(quatloos.value() == 8); + quatloos = 2.f * quatloos; + ensure(quatloos.value() == 16); + + quatloos += 4.f; + ensure(quatloos.value() == 20); + quatloos += 4; + ensure(quatloos.value() == 24); + quatloos = quatloos + 4; + ensure(quatloos.value() == 28); + quatloos = 4 + quatloos; + ensure(quatloos.value() == 32); + quatloos += quatloos * 3; + ensure(quatloos.value() == 128); + + quatloos -= quatloos / 4 * 3; + ensure(quatloos.value() == 32); + quatloos = quatloos - 8; + ensure(quatloos.value() == 24); + quatloos -= 4; + ensure(quatloos.value() == 20); + quatloos -= 4.f; + ensure(quatloos.value() == 16); + + quatloos *= 2.f; + ensure(quatloos.value() == 32); + quatloos = quatloos * 2.f; + ensure(quatloos.value() == 64); + quatloos = 0.5f * quatloos; + ensure(quatloos.value() == 32); + + quatloos /= 2.f; + ensure(quatloos.value() == 16); + quatloos = quatloos / 4; + ensure(quatloos.value() == 4); + + F32 ratio = quatloos / LLUnit(4.f); + ensure(ratio == 1); + + quatloos += LLUnit(4.f); + ensure(quatloos.value() == 5); + quatloos -= LLUnit(1.f); + ensure(quatloos.value() == 1); + } + + // implicit units + template<> template<> + void units_object_t::test<5>() + { + // 0-initialized + LLUnit quatloos(0); + // initialize implicit unit from explicit + LLUnitImplicit quatloos_implicit = quatloos + 1; + ensure(quatloos_implicit.value() == 1); + + // assign implicit to explicit, or perform math operations + quatloos = quatloos_implicit; + ensure(quatloos.value() == 1); + quatloos += quatloos_implicit; + ensure(quatloos.value() == 2); + + // math operations on implicits + quatloos_implicit = 1; + ensure(quatloos_implicit == 1); + + quatloos_implicit += 2; + ensure(quatloos_implicit == 3); + + quatloos_implicit *= 2; + ensure(quatloos_implicit == 6); + + quatloos_implicit -= 1; + ensure(quatloos_implicit == 5); + + quatloos_implicit /= 5; + ensure(quatloos_implicit == 1); + + quatloos_implicit = quatloos_implicit + 3 + quatloos_implicit; + ensure(quatloos_implicit == 5); + + quatloos_implicit = 10 - quatloos_implicit - 1; + ensure(quatloos_implicit == 4); + + quatloos_implicit = 2 * quatloos_implicit * 2; + ensure(quatloos_implicit == 16); + + F32 one_half = quatloos_implicit / (quatloos_implicit * 2); + ensure(one_half == 0.5f); + + // implicit conversion to POD + F32 float_val = quatloos_implicit; + ensure(float_val == 16); + + S32 int_val = quatloos_implicit; + ensure(int_val == 16); + } +} -- cgit v1.2.3 From c8c14ac72db3374cbd43893e5a97d98817cde0a3 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Dec 2012 15:26:59 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system potential fixes for gcc builds --- indra/llcommon/lltrace.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 25d95d9670..0cb6a84aec 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -223,7 +223,7 @@ namespace LLTrace typedef typename MeanValueType >::type mean_t; TraceType(const char* name, const char* description = NULL) - : LLInstanceTracker(name), + : LLInstanceTracker, std::string>(name), mName(name), mDescription(description ? description : "") { @@ -459,16 +459,17 @@ namespace LLTrace { public: typedef typename LLUnits::HighestPrecisionType::type_t storage_t; + typedef TraceType::type_t> > trace_t; Measurement(const char* name, const char* description = NULL) - : TraceType(name, description) + : trace_t(name, description) {} template void sample(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().sample(LLUnits::rawValue(converted_value)); + trace_t::getPrimaryAccumulator().sample(LLUnits::rawValue(converted_value)); } }; @@ -478,16 +479,17 @@ namespace LLTrace { public: typedef typename LLUnits::HighestPrecisionType::type_t storage_t; + typedef TraceType::type_t> > trace_t; Count(const char* name, const char* description = NULL) - : TraceType(name) + : trace_t(name) {} template void add(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); + trace_t::getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); } }; } -- cgit v1.2.3 From b44c8593a34961f82fb523e42ad13b7e3da00ab6 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Dec 2012 19:00:13 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system further fixes for gcc builds --- indra/llcommon/llunit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 6b023f8287..72a6020ff8 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -188,7 +188,7 @@ struct LLUnitImplicit : public LLUnit // this allows for interoperability with legacy code operator storage_t() const { - return value(); + return base_t::value(); } }; -- cgit v1.2.3 From 8c2e3bea71ea15b805a9e2a288744f10d195d803 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 9 Dec 2012 23:19:11 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system added ability to query self time of block timers indepedently --- indra/llcommon/llfasttimer.h | 5 +++++ indra/llcommon/lltrace.h | 17 +++++++++++++++++ indra/llcommon/lltracerecording.cpp | 11 +++++++++++ indra/llcommon/lltracerecording.h | 3 +++ 4 files changed, 36 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index e3d99a9e4b..b5b4a8d0b4 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -89,6 +89,11 @@ public: return static_cast&>(*(TraceType*)this); } + TraceType& selfTime() + { + return static_cast&>(*(TraceType*)this); + } + static TimeBlock& getRootTimer(); static void pushLog(LLSD sd); static void setLogLock(LLMutex* mutex); diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 0cb6a84aec..d29d43a92c 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -412,6 +412,11 @@ namespace LLTrace typedef U32 value_t; }; + struct SelfTimeAspect + { + typedef LLUnit value_t; + }; + TimeBlockAccumulator(); void addSamples(const TimeBlockAccumulator& other); void reset(const TimeBlockAccumulator* other); @@ -443,6 +448,18 @@ namespace LLTrace {} }; + template<> + class TraceType + : public TraceType + { + public: + typedef F32 mean_t; + + TraceType(const char* name, const char* description = "") + : TraceType(name, description) + {} + }; + class TimeBlockTreeNode { public: diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index e9b3376dae..3ea511ff3c 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -144,16 +144,27 @@ void Recording::appendRecording( const Recording& other ) } LLUnit Recording::getSum(const TraceType& stat) const +{ + return (F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); +} + +LLUnit Recording::getSum(const TraceType& stat) const { return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); } + U32 Recording::getSum(const TraceType& stat) const { return (*mStackTimers)[stat.getIndex()].mCalls; } LLUnit Recording::getPerSec(const TraceType& stat) const +{ + return (F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); +} + +LLUnit Recording::getPerSec(const TraceType& stat) const { return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f92281cea8..f4841214e8 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -120,8 +120,11 @@ namespace LLTrace // Timer accessors LLUnit getSum(const TraceType& stat) const; + LLUnit getSum(const TraceType& stat) const; U32 getSum(const TraceType& stat) const; + LLUnit getPerSec(const TraceType& stat) const; + LLUnit getPerSec(const TraceType& stat) const; F32 getPerSec(const TraceType& stat) const; // Count accessors -- cgit v1.2.3 From 1f56e57008f5a50c9e75fc0b4512c483ac359a52 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 18 Dec 2012 00:58:26 -0800 Subject: SH-3468 WIP add memory tracking base class created memory tracking trace type instrumented a few classes with memory tracking --- indra/llcommon/lltrace.h | 270 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 266 insertions(+), 4 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index d29d43a92c..d4fc93342d 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -424,9 +424,9 @@ namespace LLTrace // // members // - U64 mSelfTimeCounter, - mTotalTimeCounter; - U32 mCalls; + U64 mSelfTimeCounter, + mTotalTimeCounter; + U32 mCalls; }; @@ -509,6 +509,268 @@ namespace LLTrace trace_t::getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); } }; -} +struct MemStatAccumulator +{ + MemStatAccumulator() + : mSize(0), + mChildSize(0), + mAllocatedCount(0), + mDeallocatedCount(0) + {} + + void addSamples(const MemStatAccumulator& other) + { + mSize += other.mSize; + mChildSize += other.mChildSize; + mAllocatedCount += other.mAllocatedCount; + mDeallocatedCount += other.mDeallocatedCount; + } + + void reset(const MemStatAccumulator* other) + { + mSize = 0; + mChildSize = 0; + mAllocatedCount = 0; + mDeallocatedCount = 0; + } + + size_t mSize, + mChildSize; + int mAllocatedCount, + mDeallocatedCount; +}; + +class MemStat : public TraceType +{ +public: + typedef TraceType trace_t; + MemStat(const char* name) + : trace_t(name) + {} +}; + +// measures effective memory footprint of specified type +// specialize to cover different types + +template +struct MemFootprint +{ + static size_t measure(const T& value) + { + return sizeof(T); + } + + static size_t measure() + { + return sizeof(T); + } +}; + +template +struct MemFootprint +{ + static size_t measure(const T* value) + { + if (!value) + { + return 0; + } + return MemFootprint::measure(*value); + } + + static size_t measure() + { + return MemFootPrint::measure(); + } +}; + +template +struct MemFootprint > +{ + static size_t measure(const std::basic_string& value) + { + return value.capacity() * sizeof(T); + } + + static size_t measure() + { + return sizeof(std::basic_string); + } +}; + +template +struct MemFootprint > +{ + static size_t measure(const std::vector& value) + { + return value.capacity() * MemFootPrint::measure(); + } + + static size_t measure() + { + return sizeof(std::vector); + } +}; + +template +struct MemFootprint > +{ + static size_t measure(const std::list& value) + { + return value.size() * (MemFootPrint::measure() + sizeof(void*) * 2); + } + + static size_t measure() + { + return sizeof(std::list); + } +}; + +template +class MemTrackable +{ + template + struct TrackMemImpl; + + typedef MemTrackable mem_trackable_t; + +public: + typedef void mem_trackable_tag_t; + + ~MemTrackable() + { + memDisclaim(mMemFootprint); + } + + void* operator new(size_t allocation_size) + { + // reserve 8 bytes for allocation size (and preserving 8 byte alignment of structs) + void* allocation = ::operator new(allocation_size + 8); + *(size_t*)allocation = allocation_size; + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mSize += allocation_size; + accumulator.mAllocatedCount++; + return (void*)((char*)allocation + 8); + } + + void operator delete(void* ptr) + { + size_t* allocation_size = (size_t*)((char*)ptr - 8); + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mSize -= *allocation_size; + accumulator.mAllocatedCount--; + accumulator.mDeallocatedCount++; + ::delete((char*)ptr - 8); + } + + void *operator new [](size_t size) + { + size_t* result = (size_t*)malloc(size + 8); + *result = size; + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mSize += size; + accumulator.mAllocatedCount++; + return (void*)((char*)result + 8); + } + + void operator delete[](void* ptr) + { + size_t* allocation_size = (size_t*)((char*)ptr - 8); + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mSize -= *allocation_size; + accumulator.mAllocatedCount--; + accumulator.mDeallocatedCount++; + ::delete[]((char*)ptr - 8); + } + + // claim memory associated with other objects/data as our own, adding to our calculated footprint + template + T& memClaim(T& value) + { + TrackMemImpl::claim(*this, value); + return value; + } + + template + const T& memClaim(const T& value) + { + TrackMemImpl::claim(*this, value); + return value; + } + + + void memClaim(size_t size) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + mMemFootprint += size; + accumulator.mSize += size; + } + + // remove memory we had claimed from our calculated footprint + template + T& memDisclaim(T& value) + { + TrackMemImpl::disclaim(*this, value); + return value; + } + + template + const T& memDisclaim(const T& value) + { + TrackMemImpl::disclaim(*this, value); + return value; + } + + void memDisclaim(size_t size) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mSize -= size; + mMemFootprint -= size; + } + +private: + size_t mMemFootprint; + + template + struct TrackMemImpl + { + static void claim(mem_trackable_t& tracker, const TRACKED& tracked) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + size_t footprint = MemFootprint::measure(tracked); + accumulator.mSize += footprint; + tracker.mMemFootprint += footprint; + } + + static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + size_t footprint = MemFootprint::measure(tracked); + accumulator.mSize -= footprint; + tracker.mMemFootprint -= footprint; + } + }; + + template + struct TrackMemImpl + { + static void claim(mem_trackable_t& tracker, TRACKED& tracked) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mChildSize += MemFootprint::measure(tracked); + } + + static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) + { + MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + accumulator.mChildSize -= MemFootprint::measure(tracked); + } + }; + static MemStat sStat; +}; + +template MemStat MemTrackable::sStat(typeid(T).name()); + +} #endif // LL_LLTRACE_H -- cgit v1.2.3 From c219282f5de753a044cecb53bd806145f68add9a Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 18 Dec 2012 20:07:25 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system removed some potential data races got memory stats recording in trace system --- indra/llcommon/llapr.h | 51 +++-- indra/llcommon/llfasttimer.cpp | 326 +++++++++++++------------------ indra/llcommon/llfasttimer.h | 27 +-- indra/llcommon/lltrace.h | 56 +++--- indra/llcommon/lltracerecording.cpp | 21 +- indra/llcommon/lltracerecording.h | 11 +- indra/llcommon/lltracethreadrecorder.cpp | 14 +- 7 files changed, 238 insertions(+), 268 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 199b5291dd..f8f94263e4 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -48,6 +48,19 @@ extern LL_COMMON_API apr_thread_mutex_t* gLogMutexp; extern apr_thread_mutex_t* gCallStacksLogMutexp; struct apr_dso_handle_t; +/** + * @brief Function which appropriately logs error or remains quiet on + * APR_SUCCESS. + * @return Returns true if status is an error condition. + */ +bool LL_COMMON_API ll_apr_warn_status(apr_status_t status); +/// There's a whole other APR error-message function if you pass a DSO handle. +bool LL_COMMON_API ll_apr_warn_status(apr_status_t status, apr_dso_handle_t* handle); + +void LL_COMMON_API ll_apr_assert_status(apr_status_t status); +void LL_COMMON_API ll_apr_assert_status(apr_status_t status, apr_dso_handle_t* handle); + +extern "C" LL_COMMON_API apr_pool_t* gAPRPoolp; // Global APR memory pool /** * @brief initialize the common apr constructs -- apr itself, the @@ -285,26 +298,26 @@ protected: { llassert(sInitialized); void* ptr; - //apr_status_t result = + apr_status_t result = apr_threadkey_private_get(&ptr, mThreadKey); - //if (result != APR_SUCCESS) - //{ - // ll_apr_warn_status(s); - // llerrs << "Failed to get thread local data" << llendl; - //} + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } return ptr; } LL_FORCE_INLINE const void* get() const { void* ptr; - //apr_status_t result = + apr_status_t result = apr_threadkey_private_get(&ptr, mThreadKey); - //if (result != APR_SUCCESS) - //{ - // ll_apr_warn_status(s); - // llerrs << "Failed to get thread local data" << llendl; - //} + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } return ptr; } @@ -379,18 +392,4 @@ public: } }; -/** - * @brief Function which appropriately logs error or remains quiet on - * APR_SUCCESS. - * @return Returns true if status is an error condition. - */ -bool LL_COMMON_API ll_apr_warn_status(apr_status_t status); -/// There's a whole other APR error-message function if you pass a DSO handle. -bool LL_COMMON_API ll_apr_warn_status(apr_status_t status, apr_dso_handle_t* handle); - -void LL_COMMON_API ll_apr_assert_status(apr_status_t status); -void LL_COMMON_API ll_apr_assert_status(apr_status_t status, apr_dso_handle_t* handle); - -extern "C" LL_COMMON_API apr_pool_t* gAPRPoolp; // Global APR memory pool - #endif // LL_LLAPR_H diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 37e0fbac0a..f4fa8f1e61 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -59,11 +59,6 @@ namespace LLTrace ////////////////////////////////////////////////////////////////////////////// // statics -S32 TimeBlock::sCurFrameIndex = -1; -S32 TimeBlock::sLastFrameIndex = -1; -U64 TimeBlock::sLastFrameTime = TimeBlock::getCPUClockCount64(); -bool TimeBlock::sPauseHistory = 0; -bool TimeBlock::sResetHistory = 0; bool TimeBlock::sLog = false; std::string TimeBlock::sLogName = ""; bool TimeBlock::sMetricLog = false; @@ -220,143 +215,126 @@ void TimeBlock::setParent(TimeBlock* parent) } } -S32 TimeBlock::getDepth() -{ - S32 depth = 0; - TimeBlock* timerp = mParent; - while(timerp) - { - depth++; - if (timerp->getParent() == timerp) break; - timerp = timerp->mParent; - } - return depth; -} - // static void TimeBlock::processTimes() { - //void TimeBlock::buildHierarchy() + get_clock_count(); // good place to calculate clock frequency + U64 cur_time = getCPUClockCount64(); + CurTimerData* cur_data = sCurTimerData.get(); + + // set up initial tree + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) { - // set up initial tree + TimeBlock& timer = *it; + if (&timer == &TimeBlock::getRootTimer()) continue; + + // bootstrap tree construction by attaching to last timer to be on stack + // when this timer was called + if (timer.mParent == &TimeBlock::getRootTimer()) { - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; ++it) + TimeBlockAccumulator& accumulator = timer.getPrimaryAccumulator(); + + if (accumulator.mLastCaller) { - TimeBlock& timer = *it; - if (&timer == &TimeBlock::getRootTimer()) continue; - - // bootstrap tree construction by attaching to last timer to be on stack - // when this timer was called - if (timer.mParent == &TimeBlock::getRootTimer()) - { - TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; - - if (tree_node.mLastCaller) - { - timer.setParent(tree_node.mLastCaller); - } - // no need to push up tree on first use, flag can be set spuriously - tree_node.mMoveUpTree = false; - } + timer.setParent(accumulator.mLastCaller); + accumulator.mParent = accumulator.mLastCaller; } + // no need to push up tree on first use, flag can be set spuriously + accumulator.mMoveUpTree = false; } + } - // bump timers up tree if they have been flagged as being in the wrong place - // do this in a bottom up order to promote descendants first before promoting ancestors - // this preserves partial order derived from current frame's observations - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); - it != end_timer_tree_bottom_up(); - ++it) + // bump timers up tree if they have been flagged as being in the wrong place + // do this in a bottom up order to promote descendants first before promoting ancestors + // this preserves partial order derived from current frame's observations + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); + it != end_timer_tree_bottom_up(); + ++it) + { + TimeBlock* timerp = *it; + + // sort timers by time last called, so call graph makes sense + if (timerp->mNeedsSorting) { - TimeBlock* timerp = *it; - // skip root timer - if (timerp == &TimeBlock::getRootTimer()) continue; - TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timerp->getIndex()]; + std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); + } + + // skip root timer + if (timerp != &TimeBlock::getRootTimer()) + { + TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); - if (tree_node.mMoveUpTree) + if (accumulator.mMoveUpTree) { // since ancestors have already been visited, re-parenting won't affect tree traversal //step up tree, bringing our descendants with us LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; timerp->setParent(timerp->getParent()->getParent()); - tree_node.mMoveUpTree = false; + accumulator.mParent = timerp->mParent; + accumulator.mMoveUpTree = false; // don't bubble up any ancestors until descendants are done bubbling up + // as ancestors may call this timer only on certain paths, so we want to resolve + // child-most block locations before their parents it.skipAncestors(); } } - - // sort timers by time last called, so call graph makes sense - for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimer()); - it != end_timer_tree(); - ++it) - { - TimeBlock* timerp = (*it); - if (timerp->mNeedsSorting) - { - std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); - } - timerp->mNeedsSorting = false; - } } - - //void TimeBlock::accumulateTimings() - { - U64 cur_time = getCPUClockCount64(); - - // root defined by parent pointing to self - CurTimerData* cur_data = sCurTimerData.get(); - // walk up stack of active timers and accumulate current time while leaving timing structures active - BlockTimer* cur_timer = cur_data->mCurTimer; - TimeBlockAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); - while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) - { - U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; - cur_data->mChildTime = 0; - accumulator.mSelfTimeCounter += self_time_delta; - accumulator.mTotalTimeCounter += cumulative_time_delta; - cur_timer->mStartTime = cur_time; + // walk up stack of active timers and accumulate current time while leaving timing structures active + BlockTimer* cur_timer = cur_data->mCurTimer; + TimeBlockAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + // root defined by parent pointing to self + while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) + { + U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; + U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; + cur_data->mChildTime = 0; + accumulator.mSelfTimeCounter += self_time_delta; + accumulator.mTotalTimeCounter += cumulative_time_delta; - cur_data = &cur_timer->mLastTimerData; - cur_data->mChildTime += cumulative_time_delta; - if (cur_data->mTimerData) - { - accumulator = cur_data->mTimerData->getPrimaryAccumulator(); - } + cur_timer->mStartTime = cur_time; - cur_timer = cur_timer->mLastTimerData.mCurTimer; + cur_data = &cur_timer->mLastTimerData; + cur_data->mChildTime += cumulative_time_delta; + if (cur_data->mTimerData) + { + accumulator = cur_data->mTimerData->getPrimaryAccumulator(); } - // traverse tree in DFS post order, or bottom up - //for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); - // it != end_timer_tree_bottom_up(); - // ++it) - //{ - // TimeBlock* timerp = (*it); - // TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); - // timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; - // for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) - // { - // timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; - // } - - //S32 cur_frame = getCurFrameIndex(); - //if (cur_frame >= 0) - //{ - // // update timer history + cur_timer = cur_timer->mLastTimerData.mCurTimer; + } - // int hidx = getCurFrameIndex() % HISTORY_NUM; - // timerp->mCountHistory[hidx] = timerp->mTreeTimeCounter; - // timerp->mCountAverage = ((U64)timerp->mCountAverage * cur_frame + timerp->mTreeTimeCounter) / (cur_frame+1); - // timerp->mCallHistory[hidx] = accumulator.mCalls; - // timerp->mCallAverage = ((U64)timerp->mCallAverage * cur_frame + accumulator.mCalls) / (cur_frame+1); - //} - //} + // reset for next frame + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) + { + TimeBlock& timer = *it; + TimeBlockAccumulator& accumulator = timer.getPrimaryAccumulator(); + + accumulator.mLastCaller = NULL; + accumulator.mMoveUpTree = false; } + + // traverse tree in DFS post order, or bottom up + //for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); + // it != end_timer_tree_bottom_up(); + // ++it) + //{ + // TimeBlock* timerp = (*it); + // TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); + // timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; + // for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) + // { + // timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; + // } + //} } @@ -376,106 +354,78 @@ std::vector& TimeBlock::getChildren() } //static -void TimeBlock::nextFrame() +void TimeBlock::logStats() { - get_clock_count(); // good place to calculate clock frequency - U64 frame_time = TimeBlock::getCPUClockCount64(); - if ((frame_time - sLastFrameTime) >> 8 > 0xffffffff) - { - llinfos << "Slow frame, fast timers inaccurate" << llendl; - } - - if (!sPauseHistory) - { - TimeBlock::processTimes(); - sLastFrameIndex = sCurFrameIndex++; - } - // get ready for next frame - //void TimeBlock::resetFrame() - { - if (sLog) - { //output current frame counts to performance log + if (sLog) + { //output current frame counts to performance log - static S32 call_count = 0; - if (call_count % 100 == 0) - { - LL_DEBUGS("FastTimers") << "countsPerSecond: " << countsPerSecond() << LL_ENDL; - LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; - LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; - LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; - LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64()) / (LLUnit(LLProcessorInfo().getCPUFrequency())) << LL_ENDL; - } - call_count++; + static S32 call_count = 0; + if (call_count % 100 == 0) + { + LL_DEBUGS("FastTimers") << "countsPerSecond: " << countsPerSecond() << LL_ENDL; + LL_DEBUGS("FastTimers") << "LLProcessorInfo().getCPUFrequency() " << LLProcessorInfo().getCPUFrequency() << LL_ENDL; + LL_DEBUGS("FastTimers") << "getCPUClockCount32() " << getCPUClockCount32() << LL_ENDL; + LL_DEBUGS("FastTimers") << "getCPUClockCount64() " << getCPUClockCount64() << LL_ENDL; + LL_DEBUGS("FastTimers") << "elapsed sec " << ((F64)getCPUClockCount64()) / (LLUnit(LLProcessorInfo().getCPUFrequency())) << LL_ENDL; + } + call_count++; - LLUnit total_time(0); - LLSD sd; + LLUnit total_time(0); + LLSD sd; + { + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), + end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) { - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), - end_it = LLInstanceTracker::endInstances(); - it != end_it; - ++it) - { - TimeBlock& timer = *it; - LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); - sd[timer.getName()]["Time"] = (LLSD::Real) (frame_recording.getLastRecordingPeriod().getSum(timer).value()); - sd[timer.getName()]["Calls"] = (LLSD::Integer) (frame_recording.getLastRecordingPeriod().getSum(timer.callCount())); - - // computing total time here because getting the root timer's getCountHistory - // doesn't work correctly on the first frame - total_time += frame_recording.getLastRecordingPeriod().getSum(timer); - } - } - - sd["Total"]["Time"] = (LLSD::Real) total_time.value(); - sd["Total"]["Calls"] = (LLSD::Integer) 1; + TimeBlock& timer = *it; + LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); + sd[timer.getName()]["Time"] = (LLSD::Real) (frame_recording.getLastRecordingPeriod().getSum(timer).value()); + sd[timer.getName()]["Calls"] = (LLSD::Integer) (frame_recording.getLastRecordingPeriod().getSum(timer.callCount())); - { - LLMutexLock lock(sLogLock); - sLogQueue.push(sd); + // computing total time here because getting the root timer's getCountHistory + // doesn't work correctly on the first frame + total_time += frame_recording.getLastRecordingPeriod().getSum(timer); } } - // reset for next frame - for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), - end_it = LLInstanceTracker::endInstances(); - it != end_it; - ++it) - { - TimeBlock& timer = *it; - TimeBlockTreeNode& tree_node = sCurTimerData->mTimerTreeData[timer.getIndex()]; + sd["Total"]["Time"] = (LLSD::Real) total_time.value(); + sd["Total"]["Calls"] = (LLSD::Integer) 1; - tree_node.mLastCaller = NULL; - tree_node.mMoveUpTree = false; + { + LLMutexLock lock(sLogLock); + sLogQueue.push(sd); } } - sLastFrameTime = frame_time; + } //static void TimeBlock::dumpCurTimes() { - // accumulate timings, etc. - processTimes(); - + LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); + LLTrace::Recording& last_frame_recording = frame_recording.getLastRecordingPeriod(); + // walk over timers in depth order and output timings for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimer()); it != end_timer_tree(); ++it) { - LLTrace::PeriodicRecording& frame_recording = LLTrace::get_frame_recording(); TimeBlock* timerp = (*it); - LLUnit total_time_ms = frame_recording.getLastRecordingPeriod().getSum(*timerp); - U32 num_calls = frame_recording.getLastRecordingPeriod().getSum(timerp->callCount()); + LLUnit total_time_ms = 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; std::ostringstream out_str; - for (S32 i = 0; i < timerp->getDepth(); i++) + TimeBlock* parent_timerp = timerp; + while(parent_timerp && parent_timerp != parent_timerp->getParent()) { out_str << "\t"; + parent_timerp = parent_timerp->getParent(); } out_str << timerp->getName() << " " @@ -505,7 +455,11 @@ void TimeBlock::writeLog(std::ostream& os) TimeBlockAccumulator::TimeBlockAccumulator() : mSelfTimeCounter(0), mTotalTimeCounter(0), - mCalls(0) + mCalls(0), + mLastCaller(NULL), + mActiveCount(0), + mMoveUpTree(false), + mParent(NULL) {} void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) @@ -513,6 +467,10 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) mSelfTimeCounter += other.mSelfTimeCounter; mTotalTimeCounter += other.mTotalTimeCounter; mCalls += other.mCalls; + mLastCaller = other.mLastCaller; + mActiveCount = other.mActiveCount; + mMoveUpTree = other.mMoveUpTree; + mParent = other.mParent; } void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) @@ -522,10 +480,4 @@ void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) mCalls = 0; } -TimeBlockTreeNode::TimeBlockTreeNode() -: mLastCaller(NULL), - mActiveCount(0), - mMoveUpTree(false) -{} - } // namespace LLTrace diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index b5b4a8d0b4..1e2e4b590f 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -43,7 +43,6 @@ struct CurTimerData class BlockTimer* mCurTimer; class TimeBlock* mTimerData; U64 mChildTime; - TimeBlockTreeNode* mTimerTreeData; }; class BlockTimer @@ -70,11 +69,8 @@ class TimeBlock public: TimeBlock(const char* name, bool open = false, TimeBlock* parent = &getRootTimer()); - enum { HISTORY_NUM = 300 }; - TimeBlock* getParent() const { return mParent; } void setParent(TimeBlock* parent); - S32 getDepth(); typedef std::vector::const_iterator child_const_iter; child_const_iter beginChildren(); @@ -245,12 +241,12 @@ public: // can be called multiple times in a frame, at any point static void processTimes(); - // call this once a frame to reset timers - static void nextFrame(); + // call this once a frame to periodically log timers + static void logStats(); // tree structure, only updated from master trace thread TimeBlock* mParent; // TimeBlock of caller(parent) - std::vector mChildren; + std::vector mChildren; // TimeBlock of callees bool mCollapsed, // don't show children mNeedsSorting; // sort children whenever child added @@ -260,12 +256,6 @@ public: sLog; static LLThreadLocalPointer sCurTimerData; static U64 sClockResolution; - static S32 sCurFrameIndex, - sLastFrameIndex; - static U64 sLastFrameTime; - static bool sPauseHistory, - sResetHistory; - }; LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) @@ -274,10 +264,10 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) mStartTime = TimeBlock::getCPUClockCount64(); CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); - TimeBlockTreeNode& tree_node = cur_timer_data->mTimerTreeData[timer.getIndex()]; - tree_node.mActiveCount++; + TimeBlockAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + accumulator.mActiveCount++; // keep current parent as long as it is active when we are - tree_node.mMoveUpTree |= (cur_timer_data->mTimerTreeData[timer.mParent->getIndex()].mActiveCount == 0); + accumulator.mMoveUpTree |= (accumulator.mParent->getPrimaryAccumulator().mActiveCount == 0); // store top of stack mLastTimerData = *cur_timer_data; @@ -294,16 +284,15 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); TimeBlockAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); - TimeBlockTreeNode& tree_node = cur_timer_data->mTimerTreeData[cur_timer_data->mTimerData->getIndex()]; accumulator.mCalls++; accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator.mTotalTimeCounter += total_time; - tree_node.mActiveCount--; + accumulator.mActiveCount--; // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - tree_node.mLastCaller = mLastTimerData.mTimerData; + accumulator.mLastCaller = mLastTimerData.mTimerData; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index d4fc93342d..5b5e2b7879 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -82,18 +82,21 @@ namespace LLTrace enum StaticAllocationMarker { STATIC_ALLOC }; AccumulatorBuffer(StaticAllocationMarker m) - : mStorageSize(64), - mNextStorageSlot(0), - mStorage(new ACCUMULATOR[DEFAULT_ACCUMULATOR_BUFFER_SIZE]) - {} + : mStorageSize(0), + mStorage(NULL), + mNextStorageSlot(0) + { + resize(DEFAULT_ACCUMULATOR_BUFFER_SIZE); + } public: AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) - : mStorageSize(other.mStorageSize), - mStorage(new ACCUMULATOR[other.mStorageSize]), + : mStorageSize(0), + mStorage(NULL), mNextStorageSlot(other.mNextStorageSlot) { + resize(other.mStorageSize); for (S32 i = 0; i < mNextStorageSlot; i++) { mStorage[i] = other.mStorage[i]; @@ -181,9 +184,12 @@ namespace LLTrace { ACCUMULATOR* old_storage = mStorage; mStorage = new ACCUMULATOR[new_size]; - for (S32 i = 0; i < mStorageSize; i++) + if (old_storage) { - mStorage[i] = old_storage[i]; + for (S32 i = 0; i < mStorageSize; i++) + { + mStorage[i] = old_storage[i]; + } } mStorageSize = new_size; delete[] old_storage; @@ -300,14 +306,14 @@ namespace LLTrace mNumSamples += other.mNumSamples; mMean = mMean * weight + other.mMean * (1.f - weight); + // combine variance (and hence standard deviation) of 2 different sized sample groups using + // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm F64 n_1 = (F64)mNumSamples, n_2 = (F64)other.mNumSamples; F64 m_1 = mMean, m_2 = other.mMean; F64 sd_1 = getStandardDeviation(), sd_2 = other.getStandardDeviation(); - // combine variance (and hence standard deviation) of 2 different sized sample groups using - // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm if (n_1 == 0) { mVarianceSum = other.mVarianceSum; @@ -405,6 +411,7 @@ namespace LLTrace { public: typedef LLUnit value_t; + typedef TimeBlockAccumulator self_t; // fake class that allows us to view call count aspect of timeblock accumulator struct CallCountAspect @@ -418,15 +425,20 @@ namespace LLTrace }; TimeBlockAccumulator(); - void addSamples(const TimeBlockAccumulator& other); - void reset(const TimeBlockAccumulator* other); + void addSamples(const self_t& other); + void reset(const self_t* other); // // members // - U64 mSelfTimeCounter, - mTotalTimeCounter; - U32 mCalls; + U64 mSelfTimeCounter, + mTotalTimeCounter; + U32 mCalls; + class TimeBlock* mParent; // last acknowledged parent of this time block + class TimeBlock* mLastCaller; // used to bootstrap tree construction + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame + }; @@ -460,16 +472,6 @@ namespace LLTrace {} }; - class TimeBlockTreeNode - { - public: - TimeBlockTreeNode(); - class TimeBlock* mLastCaller; // used to bootstrap tree construction - U16 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - }; - - template class Measurement : public TraceType::type_t> > @@ -604,7 +606,7 @@ struct MemFootprint > { static size_t measure(const std::vector& value) { - return value.capacity() * MemFootPrint::measure(); + return value.capacity() * MemFootprint::measure(); } static size_t measure() @@ -618,7 +620,7 @@ struct MemFootprint > { static size_t measure(const std::list& value) { - return value.size() * (MemFootPrint::measure() + sizeof(void*) * 2); + return value.size() * (MemFootprint::measure() + sizeof(void*) * 2); } static size_t measure() diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 3ea511ff3c..40079f40f1 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -44,7 +44,8 @@ Recording::Recording() mMeasurementsFloat(new AccumulatorBuffer >()), mCounts(new AccumulatorBuffer >()), mMeasurements(new AccumulatorBuffer >()), - mStackTimers(new AccumulatorBuffer()) + mStackTimers(new AccumulatorBuffer()), + mMemStats(new AccumulatorBuffer()) {} Recording::Recording( const Recording& other ) @@ -57,6 +58,7 @@ Recording::Recording( const Recording& other ) mCounts = other.mCounts; mMeasurements = other.mMeasurements; mStackTimers = other.mStackTimers; + mMemStats = other.mMemStats; LLStopWatchControlsMixin::initTo(other.getPlayState()); } @@ -84,6 +86,7 @@ void Recording::handleReset() mCounts.write()->reset(); mMeasurements.write()->reset(); mStackTimers.write()->reset(); + mMemStats.write()->reset(); mElapsedSeconds = 0.0; mSamplingTimer.reset(); @@ -98,6 +101,7 @@ void Recording::handleStart() void Recording::handleStop() { mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::TimeBlock::processTimes(); LLTrace::get_thread_recorder()->deactivate(this); } @@ -107,9 +111,9 @@ void Recording::handleSplitTo(Recording& other) other.restart(); other.mMeasurementsFloat.write()->reset(mMeasurementsFloat); other.mMeasurements.write()->reset(mMeasurements); + //TODO: figure out how to get seamless handoff of timing stats } - void Recording::makePrimary() { mCountsFloat.write()->makePrimary(); @@ -117,6 +121,7 @@ void Recording::makePrimary() mCounts.write()->makePrimary(); mMeasurements.write()->makePrimary(); mStackTimers.write()->makePrimary(); + mMemStats.write()->makePrimary(); } bool Recording::isPrimary() const @@ -131,6 +136,7 @@ void Recording::makeUnique() mCounts.makeUnique(); mMeasurements.makeUnique(); mStackTimers.makeUnique(); + mMemStats.makeUnique(); } void Recording::appendRecording( const Recording& other ) @@ -140,6 +146,7 @@ void Recording::appendRecording( const Recording& other ) mCounts.write()->addSamples(*other.mCounts); mMeasurements.write()->addSamples(*other.mMeasurements); mStackTimers.write()->addSamples(*other.mStackTimers); + mMemStats.write()->addSamples(*other.mMemStats); mElapsedSeconds += other.mElapsedSeconds; } @@ -174,6 +181,16 @@ F32 Recording::getPerSec(const TraceType& return (F32)(*mStackTimers)[stat.getIndex()].mCalls / mElapsedSeconds; } +LLUnit Recording::getSum(const TraceType& stat) const +{ + return (*mMemStats)[stat.getIndex()].mAllocatedCount; +} + +LLUnit Recording::getPerSec(const TraceType& stat) const +{ + return (F32)(*mMemStats)[stat.getIndex()].mAllocatedCount / mElapsedSeconds; +} + F64 Recording::getSum( const TraceType >& stat ) const { diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f4841214e8..8e5f1125ec 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -34,7 +34,7 @@ #include "lltimer.h" #include "lltrace.h" -class LL_COMMON_API LLStopWatchControlsMixinCommon +class LLStopWatchControlsMixinCommon { public: virtual ~LLStopWatchControlsMixinCommon() {} @@ -101,7 +101,7 @@ private: namespace LLTrace { - class LL_COMMON_API Recording : public LLStopWatchControlsMixin + class Recording : public LLStopWatchControlsMixin { public: Recording(); @@ -127,6 +127,10 @@ namespace LLTrace LLUnit getPerSec(const TraceType& stat) const; F32 getPerSec(const TraceType& stat) const; + // Memory accessors + LLUnit getSum(const TraceType& stat) const; + LLUnit getPerSec(const TraceType& stat) const; + // Count accessors F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; @@ -226,7 +230,8 @@ namespace LLTrace LLCopyOnWritePointer > > mMeasurementsFloat; LLCopyOnWritePointer > > mCounts; LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimers; + LLCopyOnWritePointer > mStackTimers; + LLCopyOnWritePointer > mMemStats; LLTimer mSamplingTimer; F64 mElapsedSeconds; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 16235473ee..c4144b4999 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -43,13 +43,20 @@ ThreadRecorder::ThreadRecorder() mRootTimerData = new CurTimerData(); mRootTimerData->mTimerData = &TimeBlock::getRootTimer(); - mRootTimerData->mTimerTreeData = new TimeBlockTreeNode[AccumulatorBuffer::getDefaultBuffer().size()]; + TimeBlock::sCurTimerData = mRootTimerData; + TimeBlock::getRootTimer().getPrimaryAccumulator().mActiveCount = 1; + + // initialize parent pointers in time blocks + for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); + it != end_it; + ++it) + { + it->getPrimaryAccumulator().mParent = it->mParent; + } mRootTimer = new BlockTimer(TimeBlock::getRootTimer()); mRootTimerData->mCurTimer = mRootTimer; - - mRootTimerData->mTimerTreeData[TimeBlock::getRootTimer().getIndex()].mActiveCount = 1; } ThreadRecorder::~ThreadRecorder() @@ -62,7 +69,6 @@ ThreadRecorder::~ThreadRecorder() } get_thread_recorder() = NULL; TimeBlock::sCurTimerData = NULL; - delete [] mRootTimerData->mTimerTreeData; delete mRootTimerData; } -- cgit v1.2.3 From 013f04cabec8e110ee659d9b3f75a4d25f114b7b Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 21 Dec 2012 00:13:21 -0800 Subject: SH-3468 WIP add memory tracking base class improvements on lifetime of lltrace core data structures tweaks to thread local pointer handling so that static constructors/destructors can safely call functions that use lltrace --- indra/llcommon/llapr.cpp | 12 +-- indra/llcommon/llapr.h | 2 +- indra/llcommon/llfasttimer.cpp | 93 ++++++------------- indra/llcommon/llfasttimer.h | 34 ++++--- indra/llcommon/lltrace.cpp | 29 ++++++ indra/llcommon/lltrace.h | 150 ++++++++++++++++++++++--------- indra/llcommon/lltracerecording.cpp | 24 ++++- indra/llcommon/lltracerecording.h | 4 + indra/llcommon/lltracethreadrecorder.cpp | 71 ++++++++++++--- indra/llcommon/lltracethreadrecorder.h | 13 ++- 10 files changed, 286 insertions(+), 146 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 1db3aa9e89..6affdad61b 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -542,12 +542,12 @@ void LLThreadLocalPointerBase::destroyAllThreadLocalStorage() { if (sInitialized) { - for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); - it != end_it; - ++it) - { - (*it).destroyStorage(); - } + //for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + // it != end_it; + // ++it) + //{ + // (*it).destroyStorage(); + //} sInitialized = false; } } diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index f8f94263e4..2faf4aad2d 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -296,7 +296,7 @@ protected: LL_FORCE_INLINE void* get() { - llassert(sInitialized); + // llassert(sInitialized); void* ptr; apr_status_t result = apr_threadkey_private_get(&ptr, mThreadKey); diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index f4fa8f1e61..7c90b946af 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -35,6 +35,7 @@ #include "llunit.h" #include "llsd.h" #include "lltracerecording.h" +#include "lltracethreadrecorder.h" #include #include @@ -167,52 +168,16 @@ U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer TimeBlock::TimeBlock(const char* name, bool open, TimeBlock* parent) : TraceType(name), - mCollapsed(true), - mParent(NULL), - mNeedsSorting(false) + mCollapsed(true) { setCollapsed(!open); - - if (parent) - { - setParent(parent); - } - else - { - mParent = this; - } } -void TimeBlock::setParent(TimeBlock* parent) +TimeBlockTreeNode& TimeBlock::getTreeNode() const { - llassert_always(parent != this); - llassert_always(parent != NULL); - - if (mParent) - { - //// subtract our accumulated from previous parent - //for (S32 i = 0; i < HISTORY_NUM; i++) - //{ - // mParent->mCountHistory[i] -= mCountHistory[i]; - //} - - //// subtract average timing from previous parent - //mParent->mCountAverage -= mCountAverage; - - std::vector& children = mParent->getChildren(); - std::vector::iterator found_it = std::find(children.begin(), children.end(), this); - if (found_it != children.end()) - { - children.erase(found_it); - } - } - - mParent = parent; - if (parent) - { - parent->getChildren().push_back(this); - parent->mNeedsSorting = true; - } + TimeBlockTreeNode* nodep = LLTrace::get_thread_recorder()->getTimeBlockTreeNode(getIndex()); + llassert(nodep); + return *nodep; } // static @@ -232,17 +197,17 @@ void TimeBlock::processTimes() // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.mParent == &TimeBlock::getRootTimer()) + if (timer.getParent() == &TimeBlock::getRootTimer()) { - TimeBlockAccumulator& accumulator = timer.getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - if (accumulator.mLastCaller) + if (accumulator->mLastCaller) { - timer.setParent(accumulator.mLastCaller); - accumulator.mParent = accumulator.mLastCaller; + timer.setParent(accumulator->mLastCaller); + accumulator->mParent = accumulator->mLastCaller; } // no need to push up tree on first use, flag can be set spuriously - accumulator.mMoveUpTree = false; + accumulator->mMoveUpTree = false; } } @@ -256,25 +221,25 @@ void TimeBlock::processTimes() TimeBlock* timerp = *it; // sort timers by time last called, so call graph makes sense - if (timerp->mNeedsSorting) + if (timerp->getTreeNode().mNeedsSorting) { - std::sort(timerp->getChildren().begin(), timerp->getChildren().end(), SortTimerByName()); + std::sort(timerp->beginChildren(), timerp->endChildren(), SortTimerByName()); } // skip root timer if (timerp != &TimeBlock::getRootTimer()) { - TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = timerp->getPrimaryAccumulator(); - if (accumulator.mMoveUpTree) + if (accumulator->mMoveUpTree) { // since ancestors have already been visited, re-parenting won't affect tree traversal //step up tree, bringing our descendants with us LL_DEBUGS("FastTimers") << "Moving " << timerp->getName() << " from child of " << timerp->getParent()->getName() << " to child of " << timerp->getParent()->getParent()->getName() << LL_ENDL; timerp->setParent(timerp->getParent()->getParent()); - accumulator.mParent = timerp->mParent; - accumulator.mMoveUpTree = false; + accumulator->mParent = timerp->getParent(); + accumulator->mMoveUpTree = false; // don't bubble up any ancestors until descendants are done bubbling up // as ancestors may call this timer only on certain paths, so we want to resolve @@ -286,15 +251,15 @@ void TimeBlock::processTimes() // walk up stack of active timers and accumulate current time while leaving timing structures active BlockTimer* cur_timer = cur_data->mCurTimer; - TimeBlockAccumulator& accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = cur_data->mTimerData->getPrimaryAccumulator(); // root defined by parent pointing to self while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; cur_data->mChildTime = 0; - accumulator.mSelfTimeCounter += self_time_delta; - accumulator.mTotalTimeCounter += cumulative_time_delta; + accumulator->mSelfTimeCounter += self_time_delta; + accumulator->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; @@ -316,10 +281,10 @@ void TimeBlock::processTimes() ++it) { TimeBlock& timer = *it; - TimeBlockAccumulator& accumulator = timer.getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - accumulator.mLastCaller = NULL; - accumulator.mMoveUpTree = false; + accumulator->mLastCaller = NULL; + accumulator->mMoveUpTree = false; } // traverse tree in DFS post order, or bottom up @@ -338,19 +303,19 @@ void TimeBlock::processTimes() } -std::vector::const_iterator TimeBlock::beginChildren() +std::vector::iterator TimeBlock::beginChildren() { - return mChildren.begin(); + return getTreeNode().mChildren.begin(); } -std::vector::const_iterator TimeBlock::endChildren() +std::vector::iterator TimeBlock::endChildren() { - return mChildren.end(); + return getTreeNode().mChildren.end(); } std::vector& TimeBlock::getChildren() { - return mChildren; + return getTreeNode().mChildren; } //static diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 1e2e4b590f..4d820d0664 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -69,12 +69,14 @@ class TimeBlock public: TimeBlock(const char* name, bool open = false, TimeBlock* parent = &getRootTimer()); - TimeBlock* getParent() const { return mParent; } - void setParent(TimeBlock* parent); + TimeBlockTreeNode& getTreeNode() const; + TimeBlock* getParent() const { return getTreeNode().getParent(); } + void setParent(TimeBlock* parent) { getTreeNode().setParent(parent); } + typedef std::vector::iterator child_iter; typedef std::vector::const_iterator child_const_iter; - child_const_iter beginChildren(); - child_const_iter endChildren(); + child_iter beginChildren(); + child_iter endChildren(); std::vector& getChildren(); void setCollapsed(bool collapsed) { mCollapsed = collapsed; } @@ -244,11 +246,7 @@ public: // call this once a frame to periodically log timers static void logStats(); - // tree structure, only updated from master trace thread - TimeBlock* mParent; // TimeBlock of caller(parent) - std::vector mChildren; // TimeBlock of callees - bool mCollapsed, // don't show children - mNeedsSorting; // sort children whenever child added + bool mCollapsed; // don't show children // statics static std::string sLogName; @@ -264,10 +262,10 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) mStartTime = TimeBlock::getCPUClockCount64(); CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); - TimeBlockAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); - accumulator.mActiveCount++; + TimeBlockAccumulator* accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + accumulator->mActiveCount++; // keep current parent as long as it is active when we are - accumulator.mMoveUpTree |= (accumulator.mParent->getPrimaryAccumulator().mActiveCount == 0); + accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); // store top of stack mLastTimerData = *cur_timer_data; @@ -283,16 +281,16 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() #if FAST_TIMER_ON U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); - TimeBlockAccumulator& accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); - accumulator.mCalls++; - accumulator.mSelfTimeCounter += total_time - cur_timer_data->mChildTime; - accumulator.mTotalTimeCounter += total_time; - accumulator.mActiveCount--; + accumulator->mCalls++; + accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; + accumulator->mTotalTimeCounter += total_time; + accumulator->mActiveCount--; // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator.mLastCaller = mLastTimerData.mTimerData; + accumulator->mLastCaller = mLastTimerData.mTimerData; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index e11e39a1a2..9d0c93b352 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -66,5 +66,34 @@ LLThreadLocalPointer& get_thread_recorder() return s_thread_recorder; } +TimeBlockTreeNode::TimeBlockTreeNode() +: mBlock(NULL), + mParent(NULL), + mNeedsSorting(false) +{} + +void TimeBlockTreeNode::setParent( TimeBlock* parent ) +{ + llassert_always(parent != mBlock); + llassert_always(parent != NULL); + + TimeBlockTreeNode* parent_tree_node = get_thread_recorder()->getTimeBlockTreeNode(parent->getIndex()); + if (!parent_tree_node) return; + + if (mParent) + { + std::vector& children = mParent->getChildren(); + std::vector::iterator found_it = std::find(children.begin(), children.end(), mBlock); + if (found_it != children.end()) + { + children.erase(found_it); + } + } + + mParent = parent; + mBlock->getPrimaryAccumulator()->mParent = parent; + parent_tree_node->mChildren.push_back(mBlock); + parent_tree_node->mNeedsSorting = true; } +} diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 5b5e2b7879..4bb19f6070 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -77,21 +77,21 @@ namespace LLTrace template class AccumulatorBuffer : public LLRefCount { + typedef AccumulatorBuffer self_t; static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; private: - enum StaticAllocationMarker { STATIC_ALLOC }; + struct StaticAllocationMarker { }; AccumulatorBuffer(StaticAllocationMarker m) : mStorageSize(0), mStorage(NULL), mNextStorageSlot(0) { - resize(DEFAULT_ACCUMULATOR_BUFFER_SIZE); } public: - AccumulatorBuffer(const AccumulatorBuffer& other = getDefaultBuffer()) + AccumulatorBuffer(const AccumulatorBuffer& other = *getDefaultBuffer()) : mStorageSize(0), mStorage(NULL), mNextStorageSlot(other.mNextStorageSlot) @@ -107,8 +107,7 @@ namespace LLTrace { if (sPrimaryStorage == mStorage) { - //TODO pick another primary? - sPrimaryStorage = NULL; + sPrimaryStorage = getDefaultBuffer()->mStorage; } delete[] mStorage; } @@ -182,6 +181,8 @@ namespace LLTrace void resize(size_t new_size) { + if (new_size <= mStorageSize) return; + ACCUMULATOR* old_storage = mStorage; mStorage = new ACCUMULATOR[new_size]; if (old_storage) @@ -193,16 +194,33 @@ namespace LLTrace } mStorageSize = new_size; delete[] old_storage; + + self_t* default_buffer = getDefaultBuffer(); + if (this != default_buffer + && new_size > default_buffer->size()) + { + //NB: this is not thread safe, but we assume that all resizing occurs during static initialization + default_buffer->resize(new_size); + } } - size_t size() + size_t size() const { return mNextStorageSlot; } - static AccumulatorBuffer& getDefaultBuffer() + static self_t* getDefaultBuffer() { - static AccumulatorBuffer sBuffer(STATIC_ALLOC); + // this buffer is allowed to leak so that trace calls from global destructors have somewhere to put their data + // so as not to trigger an access violation + //TODO: make this thread local but need to either demand-init apr or remove apr dependency + static self_t* sBuffer = new AccumulatorBuffer(StaticAllocationMarker()); + static bool sInitialized = false; + if (!sInitialized) + { + sBuffer->resize(DEFAULT_ACCUMULATOR_BUFFER_SIZE); + sInitialized = true; + } return sBuffer; } @@ -233,13 +251,13 @@ namespace LLTrace mName(name), mDescription(description ? description : "") { - mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer().reserveSlot(); + mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer()->reserveSlot(); } - LL_FORCE_INLINE ACCUMULATOR& getPrimaryAccumulator() const + LL_FORCE_INLINE ACCUMULATOR* getPrimaryAccumulator() const { ACCUMULATOR* accumulator_storage = AccumulatorBuffer::getPrimaryStorage(); - return accumulator_storage[mAccumulatorIndex]; + return &accumulator_storage[mAccumulatorIndex]; } size_t getIndex() const { return mAccumulatorIndex; } @@ -472,6 +490,22 @@ namespace LLTrace {} }; + class TimeBlock; + class TimeBlockTreeNode + { + public: + TimeBlockTreeNode(); + + void setParent(TimeBlock* parent); + TimeBlock* getParent() { return mParent; } + + TimeBlock* mBlock; + TimeBlock* mParent; + std::vector mChildren; + bool mNeedsSorting; + }; + + template class Measurement : public TraceType::type_t> > @@ -488,7 +522,7 @@ namespace LLTrace void sample(UNIT_T value) { T converted_value(value); - trace_t::getPrimaryAccumulator().sample(LLUnits::rawValue(converted_value)); + trace_t::getPrimaryAccumulator()->sample(LLUnits::rawValue(converted_value)); } }; @@ -508,7 +542,7 @@ namespace LLTrace void add(UNIT_T value) { T converted_value(value); - trace_t::getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); + trace_t::getPrimaryAccumulator()->add(LLUnits::rawValue(converted_value)); } }; @@ -650,19 +684,25 @@ public: // reserve 8 bytes for allocation size (and preserving 8 byte alignment of structs) void* allocation = ::operator new(allocation_size + 8); *(size_t*)allocation = allocation_size; - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mSize += allocation_size; - accumulator.mAllocatedCount++; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mSize += allocation_size; + accumulator->mAllocatedCount++; + } return (void*)((char*)allocation + 8); } void operator delete(void* ptr) { size_t* allocation_size = (size_t*)((char*)ptr - 8); - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mSize -= *allocation_size; - accumulator.mAllocatedCount--; - accumulator.mDeallocatedCount++; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mSize -= *allocation_size; + accumulator->mAllocatedCount--; + accumulator->mDeallocatedCount++; + } ::delete((char*)ptr - 8); } @@ -670,19 +710,25 @@ public: { size_t* result = (size_t*)malloc(size + 8); *result = size; - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mSize += size; - accumulator.mAllocatedCount++; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mSize += size; + accumulator->mAllocatedCount++; + } return (void*)((char*)result + 8); } void operator delete[](void* ptr) { size_t* allocation_size = (size_t*)((char*)ptr - 8); - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mSize -= *allocation_size; - accumulator.mAllocatedCount--; - accumulator.mDeallocatedCount++; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mSize -= *allocation_size; + accumulator->mAllocatedCount--; + accumulator->mDeallocatedCount++; + } ::delete[]((char*)ptr - 8); } @@ -704,9 +750,12 @@ public: void memClaim(size_t size) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); mMemFootprint += size; - accumulator.mSize += size; + if (accumulator) + { + accumulator->mSize += size; + } } // remove memory we had claimed from our calculated footprint @@ -726,8 +775,11 @@ public: void memDisclaim(size_t size) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mSize -= size; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mSize -= size; + } mMemFootprint -= size; } @@ -739,18 +791,24 @@ private: { static void claim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - size_t footprint = MemFootprint::measure(tracked); - accumulator.mSize += footprint; - tracker.mMemFootprint += footprint; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + size_t footprint = MemFootprint::measure(tracked); + accumulator->mSize += footprint; + tracker.mMemFootprint += footprint; + } } static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - size_t footprint = MemFootprint::measure(tracked); - accumulator.mSize -= footprint; - tracker.mMemFootprint -= footprint; + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + size_t footprint = MemFootprint::measure(tracked); + accumulator->mSize -= footprint; + tracker.mMemFootprint -= footprint; + } } }; @@ -759,14 +817,20 @@ private: { static void claim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mChildSize += MemFootprint::measure(tracked); + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mChildSize += MemFootprint::measure(tracked); + } } static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = sStat.getPrimaryAccumulator(); - accumulator.mChildSize -= MemFootprint::measure(tracked); + MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + if (accumulator) + { + accumulator->mChildSize -= MemFootprint::measure(tracked); + } } }; static MemStat sStat; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 40079f40f1..9dbafc4e82 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -122,6 +122,18 @@ void Recording::makePrimary() mMeasurements.write()->makePrimary(); mStackTimers.write()->makePrimary(); mMemStats.write()->makePrimary(); + + ThreadRecorder* thread_recorder = get_thread_recorder().get(); + AccumulatorBuffer& timer_accumulator_buffer = *mStackTimers.write(); + // update stacktimer parent pointers + for (S32 i = 0, end_i = mStackTimers->size(); i < end_i; i++) + { + TimeBlockTreeNode* tree_node = thread_recorder->getTimeBlockTreeNode(i); + if (tree_node) + { + timer_accumulator_buffer[i].mParent = tree_node->mParent; + } + } } bool Recording::isPrimary() const @@ -145,11 +157,21 @@ void Recording::appendRecording( const Recording& other ) mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); mCounts.write()->addSamples(*other.mCounts); mMeasurements.write()->addSamples(*other.mMeasurements); - mStackTimers.write()->addSamples(*other.mStackTimers); mMemStats.write()->addSamples(*other.mMemStats); + + mStackTimers.write()->addSamples(*other.mStackTimers); mElapsedSeconds += other.mElapsedSeconds; } +void Recording::mergeRecording( const Recording& other) +{ + mCountsFloat.write()->addSamples(*other.mCountsFloat); + mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); + mCounts.write()->addSamples(*other.mCounts); + mMeasurements.write()->addSamples(*other.mMeasurements); + mMemStats.write()->addSamples(*other.mMemStats); +} + LLUnit Recording::getSum(const TraceType& stat) const { return (F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 8e5f1125ec..f2d7d42211 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -114,8 +114,12 @@ namespace LLTrace void makeUnique(); + // accumulate data from subsequent, non-overlapping recording void appendRecording(const Recording& other); + // gather data from recording, ignoring time relationship (for example, pulling data from slave threads) + void mergeRecording(const Recording& other); + void update(); // Timer accessors diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index c4144b4999..156b0ef26b 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -38,25 +38,37 @@ namespace LLTrace ThreadRecorder::ThreadRecorder() { + //NB: the ordering of initialization in this function is very fragile due to a large number of implicit dependencies get_thread_recorder() = this; - mFullRecording.start(); mRootTimerData = new CurTimerData(); mRootTimerData->mTimerData = &TimeBlock::getRootTimer(); - TimeBlock::sCurTimerData = mRootTimerData; - TimeBlock::getRootTimer().getPrimaryAccumulator().mActiveCount = 1; - // initialize parent pointers in time blocks + mNumTimeBlockTreeNodes = AccumulatorBuffer::getDefaultBuffer()->size(); + mTimeBlockTreeNodes = new TimeBlockTreeNode[mNumTimeBlockTreeNodes]; + + mFullRecording.start(); + + TimeBlock& root_timer = TimeBlock::getRootTimer(); + + // initialize time block parent pointers for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; ++it) { - it->getPrimaryAccumulator().mParent = it->mParent; + TimeBlock& time_block = *it; + TimeBlockTreeNode& tree_node = mTimeBlockTreeNodes[it->getIndex()]; + tree_node.mBlock = &time_block; + tree_node.mParent = &root_timer; + + it->getPrimaryAccumulator()->mParent = &root_timer; } - mRootTimer = new BlockTimer(TimeBlock::getRootTimer()); + mRootTimer = new BlockTimer(root_timer); mRootTimerData->mCurTimer = mRootTimer; + + TimeBlock::getRootTimer().getPrimaryAccumulator()->mActiveCount = 1; } ThreadRecorder::~ThreadRecorder() @@ -70,8 +82,19 @@ ThreadRecorder::~ThreadRecorder() get_thread_recorder() = NULL; TimeBlock::sCurTimerData = NULL; delete mRootTimerData; + delete[] mTimeBlockTreeNodes; } +TimeBlockTreeNode* ThreadRecorder::getTimeBlockTreeNode(S32 index) +{ + if (0 <= index && index < mNumTimeBlockTreeNodes) + { + return &mTimeBlockTreeNodes[index]; + } + return NULL; +} + + void ThreadRecorder::activate( Recording* recording ) { mActiveRecordings.push_front(ActiveRecording(recording)); @@ -113,6 +136,13 @@ std::list::iterator ThreadRecorder::update( Rec return it; } +AccumulatorBuffer > gCountsFloat; +AccumulatorBuffer > gMeasurementsFloat; +AccumulatorBuffer > gCounts; +AccumulatorBuffer > gMeasurements; +AccumulatorBuffer gStackTimers; +AccumulatorBuffer gMemStats; + void ThreadRecorder::deactivate( Recording* recording ) { std::list::iterator it = update(recording); @@ -169,23 +199,42 @@ void SlaveThreadRecorder::pushToMaster() mFullRecording.stop(); { LLMutexLock(getMasterThreadRecorder().getSlaveListMutex()); - mSharedData.copyFrom(mFullRecording); + mSharedData.appendFrom(mFullRecording); } mFullRecording.start(); } -void SlaveThreadRecorder::SharedData::copyFrom( const Recording& source ) +void SlaveThreadRecorder::SharedData::appendFrom( const Recording& source ) { LLMutexLock lock(&mRecordingMutex); mRecording.appendRecording(source); } -void SlaveThreadRecorder::SharedData::copyTo( Recording& sink ) +void SlaveThreadRecorder::SharedData::appendTo( Recording& sink ) { LLMutexLock lock(&mRecordingMutex); sink.appendRecording(mRecording); } +void SlaveThreadRecorder::SharedData::mergeFrom( const Recording& source ) +{ + LLMutexLock lock(&mRecordingMutex); + mRecording.mergeRecording(source); +} + +void SlaveThreadRecorder::SharedData::mergeTo( Recording& sink ) +{ + LLMutexLock lock(&mRecordingMutex); + sink.mergeRecording(mRecording); +} + +void SlaveThreadRecorder::SharedData::reset() +{ + LLMutexLock lock(&mRecordingMutex); + mRecording.reset(); +} + + /////////////////////////////////////////////////////////////////////// // MasterThreadRecorder /////////////////////////////////////////////////////////////////////// @@ -203,7 +252,9 @@ void MasterThreadRecorder::pullFromSlaveThreads() it != end_it; ++it) { - (*it)->mSharedData.copyTo(target_recording); + // ignore block timing info for now + (*it)->mSharedData.mergeTo(target_recording); + (*it)->mSharedData.reset(); } } diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 102b980e44..d09527eced 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -50,6 +50,8 @@ namespace LLTrace virtual void pushToMaster() = 0; + TimeBlockTreeNode* getTimeBlockTreeNode(S32 index); + protected: struct ActiveRecording { @@ -64,7 +66,9 @@ namespace LLTrace std::list mActiveRecordings; struct CurTimerData* mRootTimerData; - class BlockTimer* mRootTimer; + class BlockTimer* mRootTimer; + TimeBlockTreeNode* mTimeBlockTreeNodes; + size_t mNumTimeBlockTreeNodes; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder @@ -104,8 +108,11 @@ namespace LLTrace class SharedData { public: - void copyFrom(const Recording& source); - void copyTo(Recording& sink); + void appendFrom(const Recording& source); + void appendTo(Recording& sink); + void mergeFrom(const Recording& source); + void mergeTo(Recording& sink); + void reset(); private: LLMutex mRecordingMutex; Recording mRecording; -- cgit v1.2.3 From 3fd640a6e3dea7a3551c239323d782fb082e1dbd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 23 Dec 2012 12:27:25 -0800 Subject: SH-3468 WIP add memory tracking base class fixed crash on exit by making LLInstanceTracker iterators use atomic iterator nesting count for thread safety --- indra/llcommon/llapr.cpp | 1 + indra/llcommon/llapr.h | 137 ++-------------------------- indra/llcommon/llinstancetracker.cpp | 18 ++++ indra/llcommon/llinstancetracker.h | 27 +++--- indra/llcommon/llstl.h | 1 + indra/llcommon/llthreadlocalpointer.h | 164 ++++++++++++++++++++++++++++++++++ indra/llcommon/lltrace.h | 1 + indra/llcommon/llworkerthread.h | 5 +- 8 files changed, 209 insertions(+), 145 deletions(-) create mode 100644 indra/llcommon/llthreadlocalpointer.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 6affdad61b..092c276936 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -29,6 +29,7 @@ #include "linden_common.h" #include "llapr.h" #include "apr_dso.h" +#include "llthreadlocalpointer.h" apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool. diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 2faf4aad2d..b3c9bfd58c 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -42,7 +42,6 @@ #include "apr_atomic.h" #include "llstring.h" -#include "llinstancetracker.h" extern LL_COMMON_API apr_thread_mutex_t* gLogMutexp; extern apr_thread_mutex_t* gCallStacksLogMutexp; @@ -170,14 +169,17 @@ public: LLAtomic32(Type x) {apr_atomic_set32(&mData, apr_uint32_t(x)); }; ~LLAtomic32() {}; - operator const Type() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); } + operator const Type() { return get(); } Type operator =(const Type& x) { apr_atomic_set32(&mData, apr_uint32_t(x)); return Type(mData); } void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); } void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); } Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++ - Type operator --(int) { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) + Type operator ++() { apr_atomic_inc32(&mData); return get(); } // ++Type + Type operator --(int) { const Type result(get()); apr_atomic_dec32(&mData); return result; } // Type-- + Type operator --() { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) private: + const Type get() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); } apr_uint32_t mData; }; @@ -262,134 +264,5 @@ public: //******************************************************************************************************************************* }; -class LLThreadLocalPointerBase : public LLInstanceTracker -{ -public: - LLThreadLocalPointerBase() - : mThreadKey(NULL) - { - if (sInitialized) - { - initStorage(); - } - } - - LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) - : mThreadKey(NULL) - { - if (sInitialized) - { - initStorage(); - } - } - - ~LLThreadLocalPointerBase() - { - destroyStorage(); - } - - static void initAllThreadLocalStorage(); - static void destroyAllThreadLocalStorage(); - -protected: - void set(void* value); - - LL_FORCE_INLINE void* get() - { - // llassert(sInitialized); - void* ptr; - apr_status_t result = - apr_threadkey_private_get(&ptr, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to get thread local data" << llendl; - } - return ptr; - } - - LL_FORCE_INLINE const void* get() const - { - void* ptr; - apr_status_t result = - apr_threadkey_private_get(&ptr, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to get thread local data" << llendl; - } - return ptr; - } - - void initStorage(); - void destroyStorage(); - -protected: - apr_threadkey_t* mThreadKey; - static bool sInitialized; -}; - -template -class LLThreadLocalPointer : public LLThreadLocalPointerBase -{ -public: - - LLThreadLocalPointer() - {} - - explicit LLThreadLocalPointer(T* value) - { - set(value); - } - - - LLThreadLocalPointer(const LLThreadLocalPointer& other) - : LLThreadLocalPointerBase(other) - { - set(other.get()); - } - - LL_FORCE_INLINE T* get() - { - return (T*)LLThreadLocalPointerBase::get(); - } - - const T* get() const - { - return (const T*)LLThreadLocalPointerBase::get(); - } - - T* operator -> () - { - return (T*)get(); - } - - const T* operator -> () const - { - return (T*)get(); - } - - T& operator*() - { - return *(T*)get(); - } - - const T& operator*() const - { - return *(T*)get(); - } - - LLThreadLocalPointer& operator = (T* value) - { - set((void*)value); - return *this; - } - - bool operator ==(T* other) - { - if (!sInitialized) return false; - return get() == other; - } -}; #endif // LL_LLAPR_H diff --git a/indra/llcommon/llinstancetracker.cpp b/indra/llcommon/llinstancetracker.cpp index 5dc3ea5d7b..071a637cda 100644 --- a/indra/llcommon/llinstancetracker.cpp +++ b/indra/llcommon/llinstancetracker.cpp @@ -27,6 +27,8 @@ #include "linden_common.h" // associated header #include "llinstancetracker.h" +#include "llapr.h" + // STL headers // std headers // external library headers @@ -47,3 +49,19 @@ void * & LLInstanceTrackerBase::getInstances(std::type_info const & info) InstancesMap::mapped_type())) .first->second; } + +void LLInstanceTrackerBase::StaticBase::incrementDepth() +{ + apr_atomic_inc32(&sIterationNestDepth); +} + +void LLInstanceTrackerBase::StaticBase::decrementDepth() +{ + apr_atomic_dec32(&sIterationNestDepth); +} + +U32 LLInstanceTrackerBase::StaticBase::getDepth() +{ + apr_uint32_t data = apr_atomic_read32(&sIterationNestDepth); + return data; +} diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index 3a1187a4c1..9dd6d4a7ed 100644 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -70,7 +70,12 @@ protected: StaticBase(): sIterationNestDepth(0) {} - S32 sIterationNestDepth; + + void incrementDepth(); + void decrementDepth(); + U32 getDepth(); + private: + U32 sIterationNestDepth; }; }; @@ -99,12 +104,12 @@ public: instance_iter(const typename InstanceMap::iterator& it) : mIterator(it) { - ++getStatic().sIterationNestDepth; + getStatic().incrementDepth(); } ~instance_iter() { - --getStatic().sIterationNestDepth; + getStatic().decrementDepth(); } @@ -133,18 +138,18 @@ public: key_iter(typename InstanceMap::iterator it) : mIterator(it) { - ++getStatic().sIterationNestDepth; + getStatic().incrementDepth(); } key_iter(const key_iter& other) : mIterator(other.mIterator) { - ++getStatic().sIterationNestDepth; + getStatic().incrementDepth(); } ~key_iter() { - --getStatic().sIterationNestDepth; + getStatic().decrementDepth(); } @@ -203,7 +208,7 @@ protected: virtual ~LLInstanceTracker() { // it's unsafe to delete instances of this type while all instances are being iterated over. - llassert_always(getStatic().sIterationNestDepth == 0); + llassert_always(getStatic().getDepth() == 0); remove_(); } virtual void setKey(KEY key) { remove_(); add_(key); } @@ -262,18 +267,18 @@ public: instance_iter(const typename InstanceSet::iterator& it) : mIterator(it) { - ++getStatic().sIterationNestDepth; + getStatic().incrementDepth(); } instance_iter(const instance_iter& other) : mIterator(other.mIterator) { - ++getStatic().sIterationNestDepth; + getStatic().incrementDepth(); } ~instance_iter() { - --getStatic().sIterationNestDepth; + getStatic().decrementDepth(); } private: @@ -306,7 +311,7 @@ protected: virtual ~LLInstanceTracker() { // it's unsafe to delete instances of this type while all instances are being iterated over. - llassert_always(getStatic().sIterationNestDepth == 0); + llassert_always(getStatic().getDepth() == 0); getSet_().erase(static_cast(this)); } diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h index d3941e1bc9..424138dad1 100644 --- a/indra/llcommon/llstl.h +++ b/indra/llcommon/llstl.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/indra/llcommon/llthreadlocalpointer.h b/indra/llcommon/llthreadlocalpointer.h new file mode 100644 index 0000000000..d40a8b5a27 --- /dev/null +++ b/indra/llcommon/llthreadlocalpointer.h @@ -0,0 +1,164 @@ +/** + * @file llthreadlocalpointer.h + * @author Richard + * @brief Pointer class that manages a distinct value per thread + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTHREADLOCALPOINTER_H +#define LL_LLTHREADLOCALPOINTER_H + +#include "llinstancetracker.h" +#include "llapr.h" + +class LLThreadLocalPointerBase : public LLInstanceTracker +{ +public: + LLThreadLocalPointerBase() + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + ~LLThreadLocalPointerBase() + { + destroyStorage(); + } + + static void initAllThreadLocalStorage(); + static void destroyAllThreadLocalStorage(); + +protected: + void set(void* value); + + LL_FORCE_INLINE void* get() + { + // llassert(sInitialized); + void* ptr; + apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } + return ptr; + } + + LL_FORCE_INLINE const void* get() const + { + void* ptr; + apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } + return ptr; + } + + void initStorage(); + void destroyStorage(); + +protected: + apr_threadkey_t* mThreadKey; + static bool sInitialized; +}; + +template +class LLThreadLocalPointer : public LLThreadLocalPointerBase +{ +public: + + LLThreadLocalPointer() + {} + + explicit LLThreadLocalPointer(T* value) + { + set(value); + } + + + LLThreadLocalPointer(const LLThreadLocalPointer& other) + : LLThreadLocalPointerBase(other) + { + set(other.get()); + } + + LL_FORCE_INLINE T* get() + { + return (T*)LLThreadLocalPointerBase::get(); + } + + const T* get() const + { + return (const T*)LLThreadLocalPointerBase::get(); + } + + T* operator -> () + { + return (T*)get(); + } + + const T* operator -> () const + { + return (T*)get(); + } + + T& operator*() + { + return *(T*)get(); + } + + const T& operator*() const + { + return *(T*)get(); + } + + LLThreadLocalPointer& operator = (T* value) + { + set((void*)value); + return *this; + } + + bool operator ==(T* other) + { + if (!sInitialized) return false; + return get() == other; + } +}; + +#endif // LL_LLTHREADLOCALPOINTER_H diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 4bb19f6070..05191cafaa 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -34,6 +34,7 @@ #include "llrefcount.h" #include "llunit.h" #include "llapr.h" +#include "llthreadlocalpointer.h" #include diff --git a/indra/llcommon/llworkerthread.h b/indra/llcommon/llworkerthread.h index be46394d6e..09776816a8 100644 --- a/indra/llcommon/llworkerthread.h +++ b/indra/llcommon/llworkerthread.h @@ -26,10 +26,11 @@ #ifndef LL_LLWORKERTHREAD_H #define LL_LLWORKERTHREAD_H -#include -#include +#include #include +#include #include +#include #include "llqueuedthread.h" #include "llapr.h" -- cgit v1.2.3 From cda2cdda511eb2f7a58e284db2c852fd4a3808ae Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 3 Jan 2013 00:30:54 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system made fast timer stack thread local added LLThreadLocalSingleton made LLThreadLocalPointer obey pointer rules for const added LLThreadLocalSingletonPointer for fast thread local pointers --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llapr.cpp | 2 +- indra/llcommon/llfasttimer.cpp | 41 +++-- indra/llcommon/llfasttimer.h | 45 ++++-- indra/llcommon/llsingleton.h | 52 ++++--- indra/llcommon/llthreadlocalpointer.h | 164 -------------------- indra/llcommon/llthreadlocalstorage.h | 254 +++++++++++++++++++++++++++++++ indra/llcommon/lltrace.cpp | 13 +- indra/llcommon/lltrace.h | 32 ++-- indra/llcommon/lltracethreadrecorder.cpp | 33 ++-- indra/llcommon/lltracethreadrecorder.h | 9 +- 11 files changed, 380 insertions(+), 266 deletions(-) delete mode 100644 indra/llcommon/llthreadlocalpointer.h create mode 100644 indra/llcommon/llthreadlocalstorage.h (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 5b76703af7..6f5fe1832a 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -242,6 +242,7 @@ set(llcommon_HEADER_FILES llstringtable.h llsys.h llthread.h + llthreadlocalstorage.h llthreadsafequeue.h lltimer.h lltrace.h diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 092c276936..d911f258b6 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -29,7 +29,7 @@ #include "linden_common.h" #include "llapr.h" #include "apr_dso.h" -#include "llthreadlocalpointer.h" +#include "llthreadlocalstorage.h" apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool. diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 7c90b946af..ad8cf7296e 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -70,8 +70,6 @@ U64 TimeBlock::sClockResolution = 1000000000; // Nanosecond resolution U64 TimeBlock::sClockResolution = 1000000; // Microsecond resolution #endif -LLThreadLocalPointer TimeBlock::sCurTimerData; - static LLMutex* sLogLock = NULL; static std::queue sLogQueue; @@ -118,7 +116,7 @@ struct SortTimerByName } }; -TimeBlock& TimeBlock::getRootTimer() +TimeBlock& TimeBlock::getRootTimeBlock() { static TimeBlock root_timer("root", true, NULL); return root_timer; @@ -185,7 +183,7 @@ void TimeBlock::processTimes() { get_clock_count(); // good place to calculate clock frequency U64 cur_time = getCPUClockCount64(); - CurTimerData* cur_data = sCurTimerData.get(); + BlockTimerStackRecord* stack_record = ThreadTimerStack::getInstance(); // set up initial tree for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); @@ -193,11 +191,11 @@ void TimeBlock::processTimes() ++it) { TimeBlock& timer = *it; - if (&timer == &TimeBlock::getRootTimer()) continue; + if (&timer == &TimeBlock::getRootTimeBlock()) continue; // bootstrap tree construction by attaching to last timer to be on stack // when this timer was called - if (timer.getParent() == &TimeBlock::getRootTimer()) + if (timer.getParent() == &TimeBlock::getRootTimeBlock()) { TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); @@ -214,20 +212,21 @@ void TimeBlock::processTimes() // bump timers up tree if they have been flagged as being in the wrong place // do this in a bottom up order to promote descendants first before promoting ancestors // this preserves partial order derived from current frame's observations - for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); + for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimeBlock()); it != end_timer_tree_bottom_up(); ++it) { TimeBlock* timerp = *it; // sort timers by time last called, so call graph makes sense - if (timerp->getTreeNode().mNeedsSorting) + TimeBlockTreeNode& tree_node = timerp->getTreeNode(); + if (tree_node.mNeedsSorting) { - std::sort(timerp->beginChildren(), timerp->endChildren(), SortTimerByName()); + std::sort(tree_node.mChildren.begin(), tree_node.mChildren.end(), SortTimerByName()); } // skip root timer - if (timerp != &TimeBlock::getRootTimer()) + if (timerp != &TimeBlock::getRootTimeBlock()) { TimeBlockAccumulator* accumulator = timerp->getPrimaryAccumulator(); @@ -250,27 +249,27 @@ void TimeBlock::processTimes() } // walk up stack of active timers and accumulate current time while leaving timing structures active - BlockTimer* cur_timer = cur_data->mCurTimer; - TimeBlockAccumulator* accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + BlockTimer* cur_timer = stack_record->mActiveTimer; + TimeBlockAccumulator* accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); // root defined by parent pointing to self - while(cur_timer && cur_timer->mLastTimerData.mCurTimer != cur_timer) + while(cur_timer && cur_timer->mLastTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U64 self_time_delta = cumulative_time_delta - cur_data->mChildTime; - cur_data->mChildTime = 0; + U64 self_time_delta = cumulative_time_delta - stack_record->mChildTime; + stack_record->mChildTime = 0; accumulator->mSelfTimeCounter += self_time_delta; accumulator->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; - cur_data = &cur_timer->mLastTimerData; - cur_data->mChildTime += cumulative_time_delta; - if (cur_data->mTimerData) + stack_record = &cur_timer->mLastTimerData; + stack_record->mChildTime += cumulative_time_delta; + if (stack_record->mTimeBlock) { - accumulator = cur_data->mTimerData->getPrimaryAccumulator(); + accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); } - cur_timer = cur_timer->mLastTimerData.mCurTimer; + cur_timer = cur_timer->mLastTimerData.mActiveTimer; } @@ -374,7 +373,7 @@ void TimeBlock::dumpCurTimes() LLTrace::Recording& last_frame_recording = frame_recording.getLastRecordingPeriod(); // walk over timers in depth order and output timings - for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimer()); + for(timer_tree_dfs_iterator_t it = begin_timer_tree(TimeBlock::getRootTimeBlock()); it != end_timer_tree(); ++it) { diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 4d820d0664..995eebd16a 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -38,13 +38,29 @@ class LLMutex; namespace LLTrace { -struct CurTimerData +struct BlockTimerStackRecord { - class BlockTimer* mCurTimer; - class TimeBlock* mTimerData; + class BlockTimer* mActiveTimer; + class TimeBlock* mTimeBlock; U64 mChildTime; }; +class ThreadTimerStack +: public BlockTimerStackRecord, + public LLThreadLocalSingleton +{ + friend LLThreadLocalSingleton; + ThreadTimerStack() + {} + +public: + ThreadTimerStack& operator=(const BlockTimerStackRecord& other) + { + BlockTimerStackRecord::operator=(other); + return *this; + } +}; + class BlockTimer { public: @@ -58,7 +74,7 @@ public: private: U64 mStartTime; - CurTimerData mLastTimerData; + BlockTimerStackRecord mLastTimerData; }; // stores a "named" timer instance to be reused via multiple BlockTimer stack instances @@ -67,7 +83,7 @@ class TimeBlock public LLInstanceTracker { public: - TimeBlock(const char* name, bool open = false, TimeBlock* parent = &getRootTimer()); + TimeBlock(const char* name, bool open = false, TimeBlock* parent = &getRootTimeBlock()); TimeBlockTreeNode& getTreeNode() const; TimeBlock* getParent() const { return getTreeNode().getParent(); } @@ -92,7 +108,7 @@ public: return static_cast&>(*(TraceType*)this); } - static TimeBlock& getRootTimer(); + static TimeBlock& getRootTimeBlock(); static void pushLog(LLSD sd); static void setLogLock(LLMutex* mutex); static void writeLog(std::ostream& os); @@ -252,7 +268,6 @@ public: static std::string sLogName; static bool sMetricLog, sLog; - static LLThreadLocalPointer sCurTimerData; static U64 sClockResolution; }; @@ -261,8 +276,8 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) #if FAST_TIMER_ON mStartTime = TimeBlock::getCPUClockCount64(); - CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); - TimeBlockAccumulator* accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); + TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); accumulator->mActiveCount++; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -270,8 +285,8 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) // store top of stack mLastTimerData = *cur_timer_data; // push new information - cur_timer_data->mCurTimer = this; - cur_timer_data->mTimerData = &timer; + cur_timer_data->mActiveTimer = this; + cur_timer_data->mTimeBlock = &timer; cur_timer_data->mChildTime = 0; #endif } @@ -280,8 +295,8 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() { #if FAST_TIMER_ON U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; - CurTimerData* cur_timer_data = TimeBlock::sCurTimerData.get(); - TimeBlockAccumulator* accumulator = cur_timer_data->mTimerData->getPrimaryAccumulator(); + BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); + TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); accumulator->mCalls++; accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; @@ -290,12 +305,12 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator->mLastCaller = mLastTimerData.mTimerData; + accumulator->mLastCaller = mLastTimerData.mTimeBlock; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; - *TimeBlock::sCurTimerData = mLastTimerData; + *ThreadTimerStack::getIfExists() = mLastTimerData; #endif } diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h index 49d99f2cd0..f6b0a7194b 100644 --- a/indra/llcommon/llsingleton.h +++ b/indra/llcommon/llsingleton.h @@ -90,7 +90,7 @@ template class LLSingleton : private boost::noncopyable { -private: +protected: typedef enum e_init_state { UNINITIALIZED, @@ -124,7 +124,7 @@ private: public: virtual ~LLSingleton() { - SingletonInstanceData& data = getData(); + SingletonInstanceData& data = getSingletonData(); data.mSingletonInstance = NULL; data.mInitState = DELETED; } @@ -151,29 +151,15 @@ public: */ static void deleteSingleton() { - delete getData().mSingletonInstance; - getData().mSingletonInstance = NULL; - getData().mInitState = DELETED; - } - - static SingletonInstanceData& getData() - { - // this is static to cache the lookup results - static void * & registry = LLSingletonRegistry::get(); - - // *TODO - look into making this threadsafe - if(NULL == registry) - { - static SingletonInstanceData data; - registry = &data; - } - - return *static_cast(registry); + SingletonInstanceData& data = getSingletonData(); + delete data.mSingletonInstance; + data.mSingletonInstance = NULL; + data.mInitState = DELETED; } static DERIVED_TYPE* getInstance() { - SingletonInstanceData& data = getData(); + SingletonInstanceData& data = getSingletonData(); if (data.mInitState == CONSTRUCTING) { @@ -197,6 +183,12 @@ public: return data.mSingletonInstance; } + static DERIVED_TYPE* getIfExists() + { + SingletonInstanceData& data = getSingletonData(); + return data.mSingletonInstance; + } + // Reference version of getInstance() // Preferred over getInstance() as it disallows checking for NULL static DERIVED_TYPE& instance() @@ -208,17 +200,31 @@ public: // Use this to avoid accessing singletons before the can safely be constructed static bool instanceExists() { - return getData().mInitState == INITIALIZED; + return getSingletonData().mInitState == INITIALIZED; } // Has this singleton already been deleted? // Use this to avoid accessing singletons from a static object's destructor static bool destroyed() { - return getData().mInitState == DELETED; + return getSingletonData().mInitState == DELETED; } private: + static SingletonInstanceData& getSingletonData() + { + // this is static to cache the lookup results + static void * & registry = LLSingletonRegistry::get(); + + // *TODO - look into making this threadsafe + if(NULL == registry) + { + static SingletonInstanceData data; + registry = &data; + } + + return *static_cast(registry); + } virtual void initSingleton() {} }; diff --git a/indra/llcommon/llthreadlocalpointer.h b/indra/llcommon/llthreadlocalpointer.h deleted file mode 100644 index d40a8b5a27..0000000000 --- a/indra/llcommon/llthreadlocalpointer.h +++ /dev/null @@ -1,164 +0,0 @@ -/** - * @file llthreadlocalpointer.h - * @author Richard - * @brief Pointer class that manages a distinct value per thread - * - * $LicenseInfo:firstyear=2004&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLTHREADLOCALPOINTER_H -#define LL_LLTHREADLOCALPOINTER_H - -#include "llinstancetracker.h" -#include "llapr.h" - -class LLThreadLocalPointerBase : public LLInstanceTracker -{ -public: - LLThreadLocalPointerBase() - : mThreadKey(NULL) - { - if (sInitialized) - { - initStorage(); - } - } - - LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) - : mThreadKey(NULL) - { - if (sInitialized) - { - initStorage(); - } - } - - ~LLThreadLocalPointerBase() - { - destroyStorage(); - } - - static void initAllThreadLocalStorage(); - static void destroyAllThreadLocalStorage(); - -protected: - void set(void* value); - - LL_FORCE_INLINE void* get() - { - // llassert(sInitialized); - void* ptr; - apr_status_t result = - apr_threadkey_private_get(&ptr, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to get thread local data" << llendl; - } - return ptr; - } - - LL_FORCE_INLINE const void* get() const - { - void* ptr; - apr_status_t result = - apr_threadkey_private_get(&ptr, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to get thread local data" << llendl; - } - return ptr; - } - - void initStorage(); - void destroyStorage(); - -protected: - apr_threadkey_t* mThreadKey; - static bool sInitialized; -}; - -template -class LLThreadLocalPointer : public LLThreadLocalPointerBase -{ -public: - - LLThreadLocalPointer() - {} - - explicit LLThreadLocalPointer(T* value) - { - set(value); - } - - - LLThreadLocalPointer(const LLThreadLocalPointer& other) - : LLThreadLocalPointerBase(other) - { - set(other.get()); - } - - LL_FORCE_INLINE T* get() - { - return (T*)LLThreadLocalPointerBase::get(); - } - - const T* get() const - { - return (const T*)LLThreadLocalPointerBase::get(); - } - - T* operator -> () - { - return (T*)get(); - } - - const T* operator -> () const - { - return (T*)get(); - } - - T& operator*() - { - return *(T*)get(); - } - - const T& operator*() const - { - return *(T*)get(); - } - - LLThreadLocalPointer& operator = (T* value) - { - set((void*)value); - return *this; - } - - bool operator ==(T* other) - { - if (!sInitialized) return false; - return get() == other; - } -}; - -#endif // LL_LLTHREADLOCALPOINTER_H diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h new file mode 100644 index 0000000000..fdf0c18085 --- /dev/null +++ b/indra/llcommon/llthreadlocalstorage.h @@ -0,0 +1,254 @@ +/** + * @file llthreadlocalstorage.h + * @author Richard + * @brief Class wrappers for thread local storage + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTHREADLOCALSTORAGE_H +#define LL_LLTHREADLOCALSTORAGE_H + +#include "llinstancetracker.h" +#include "llapr.h" + +class LLThreadLocalPointerBase : public LLInstanceTracker +{ +public: + LLThreadLocalPointerBase() + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + ~LLThreadLocalPointerBase() + { + destroyStorage(); + } + + static void initAllThreadLocalStorage(); + static void destroyAllThreadLocalStorage(); + +protected: + void set(void* value); + + LL_FORCE_INLINE void* get() const + { + // llassert(sInitialized); + void* ptr; + apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } + return ptr; + } + + void initStorage(); + void destroyStorage(); + +protected: + apr_threadkey_t* mThreadKey; + static bool sInitialized; +}; + +template +class LLThreadLocalPointer : public LLThreadLocalPointerBase +{ +public: + + LLThreadLocalPointer() + {} + + explicit LLThreadLocalPointer(T* value) + { + set(value); + } + + + LLThreadLocalPointer(const LLThreadLocalPointer& other) + : LLThreadLocalPointerBase(other) + { + set(other.get()); + } + + LL_FORCE_INLINE T* get() const + { + return (T*)LLThreadLocalPointerBase::get(); + } + + T* operator -> () const + { + return (T*)get(); + } + + T& operator*() const + { + return *(T*)get(); + } + + LLThreadLocalPointer& operator = (T* value) + { + set((void*)value); + return *this; + } + + bool operator ==(const T* other) const + { + if (!sInitialized) return false; + return get() == other; + } +}; + +template +class LLThreadLocalSingleton +{ + typedef enum e_init_state + { + UNINITIALIZED = 0, + CONSTRUCTING, + INITIALIZING, + INITIALIZED, + DELETED + } EInitState; + +public: + LLThreadLocalSingleton() + {} + + virtual ~LLThreadLocalSingleton() + { + sInstance = NULL; + sInitState = DELETED; + } + + static void deleteSingleton() + { + delete sInstance; + sInstance = NULL; + sInitState = DELETED; + } + + static DERIVED_TYPE* getInstance() + { + if (sInitState == CONSTRUCTING) + { + llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl; + } + + if (sInitState == DELETED) + { + llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; + } + + if (!sInstance) + { + sInitState = CONSTRUCTING; + sInstance = new DERIVED_TYPE(); + sInitState = INITIALIZING; + sInstance->initSingleton(); + sInitState = INITIALIZED; + } + + return sInstance; + } + + static DERIVED_TYPE* getIfExists() + { + return sInstance; + } + + // Reference version of getInstance() + // Preferred over getInstance() as it disallows checking for NULL + static DERIVED_TYPE& instance() + { + return *getInstance(); + } + + // Has this singleton been created uet? + // Use this to avoid accessing singletons before the can safely be constructed + static bool instanceExists() + { + return sInitState == INITIALIZED; + } + + // Has this singleton already been deleted? + // Use this to avoid accessing singletons from a static object's destructor + static bool destroyed() + { + return sInitState == DELETED; + } +private: + LLThreadLocalSingleton(const LLThreadLocalSingleton& other); + virtual void initSingleton() {} + + static __declspec(thread) DERIVED_TYPE* sInstance; + static __declspec(thread) EInitState sInitState; +}; + +template +__declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; + +template +__declspec(thread) typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; + +template +class LLThreadLocalSingletonPointer +{ +public: + void operator =(DERIVED_TYPE* value) + { + sInstance = value; + } + + LL_FORCE_INLINE static DERIVED_TYPE* getInstance() + { + return sInstance; + } + + LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) + { + sInstance = instance; + } + +private: + static __declspec(thread) DERIVED_TYPE* sInstance; +}; + +template +__declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; + +#endif // LL_LLTHREADLOCALSTORAGE_H diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 9d0c93b352..9cadd70dd8 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -60,12 +60,23 @@ MasterThreadRecorder& getMasterThreadRecorder() return *gMasterThreadRecorder; } -LLThreadLocalPointer& get_thread_recorder() +LLThreadLocalPointer& get_thread_recorder_ptr() { static LLThreadLocalPointer s_thread_recorder; return s_thread_recorder; } +const LLThreadLocalPointer& get_thread_recorder() +{ + return get_thread_recorder_ptr(); +} + +void set_thread_recorder(ThreadRecorder* recorder) +{ + get_thread_recorder_ptr() = recorder; +} + + TimeBlockTreeNode::TimeBlockTreeNode() : mBlock(NULL), mParent(NULL), diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 05191cafaa..285d4389af 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -34,7 +34,7 @@ #include "llrefcount.h" #include "llunit.h" #include "llapr.h" -#include "llthreadlocalpointer.h" +#include "llthreadlocalstorage.h" #include @@ -70,7 +70,8 @@ namespace LLTrace void cleanup(); bool isInitialized(); - LLThreadLocalPointer& get_thread_recorder(); + const LLThreadLocalPointer& get_thread_recorder(); + void set_thread_recorder(class ThreadRecorder*); class MasterThreadRecorder& getMasterThreadRecorder(); @@ -106,9 +107,9 @@ namespace LLTrace ~AccumulatorBuffer() { - if (sPrimaryStorage == mStorage) + if (LLThreadLocalSingletonPointer::getInstance() == mStorage) { - sPrimaryStorage = getDefaultBuffer()->mStorage; + LLThreadLocalSingletonPointer::setInstance(getDefaultBuffer()->mStorage); } delete[] mStorage; } @@ -151,17 +152,17 @@ namespace LLTrace void makePrimary() { - sPrimaryStorage = mStorage; + LLThreadLocalSingletonPointer::setInstance(mStorage); } bool isPrimary() const { - return sPrimaryStorage == mStorage; + return LLThreadLocalSingletonPointer::getInstance() == mStorage; } LL_FORCE_INLINE static ACCUMULATOR* getPrimaryStorage() { - return sPrimaryStorage.get(); + return LLThreadLocalSingletonPointer::getInstance(); } // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned @@ -214,7 +215,6 @@ namespace LLTrace { // this buffer is allowed to leak so that trace calls from global destructors have somewhere to put their data // so as not to trigger an access violation - //TODO: make this thread local but need to either demand-init apr or remove apr dependency static self_t* sBuffer = new AccumulatorBuffer(StaticAllocationMarker()); static bool sInitialized = false; if (!sInitialized) @@ -229,9 +229,7 @@ namespace LLTrace ACCUMULATOR* mStorage; size_t mStorageSize; size_t mNextStorageSlot; - static LLThreadLocalPointer sPrimaryStorage; }; - template LLThreadLocalPointer AccumulatorBuffer::sPrimaryStorage; //TODO: replace with decltype when C++11 is enabled template @@ -250,10 +248,9 @@ namespace LLTrace TraceType(const char* name, const char* description = NULL) : LLInstanceTracker, std::string>(name), mName(name), - mDescription(description ? description : "") - { - mAccumulatorIndex = AccumulatorBuffer::getDefaultBuffer()->reserveSlot(); - } + mDescription(description ? description : ""), + mAccumulatorIndex(AccumulatorBuffer::getDefaultBuffer()->reserveSlot()) + {} LL_FORCE_INLINE ACCUMULATOR* getPrimaryAccumulator() const { @@ -263,13 +260,12 @@ namespace LLTrace size_t getIndex() const { return mAccumulatorIndex; } - std::string& getName() { return mName; } const std::string& getName() const { return mName; } protected: - std::string mName; - std::string mDescription; - size_t mAccumulatorIndex; + const std::string mName; + const std::string mDescription; + const size_t mAccumulatorIndex; }; template diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 156b0ef26b..9fb789c62d 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -39,18 +39,17 @@ namespace LLTrace ThreadRecorder::ThreadRecorder() { //NB: the ordering of initialization in this function is very fragile due to a large number of implicit dependencies - get_thread_recorder() = this; + set_thread_recorder(this); + TimeBlock& root_time_block = TimeBlock::getRootTimeBlock(); - mRootTimerData = new CurTimerData(); - mRootTimerData->mTimerData = &TimeBlock::getRootTimer(); - TimeBlock::sCurTimerData = mRootTimerData; + ThreadTimerStack* timer_stack = ThreadTimerStack::getInstance(); + timer_stack->mTimeBlock = &root_time_block; + timer_stack->mActiveTimer = NULL; mNumTimeBlockTreeNodes = AccumulatorBuffer::getDefaultBuffer()->size(); mTimeBlockTreeNodes = new TimeBlockTreeNode[mNumTimeBlockTreeNodes]; - mFullRecording.start(); - - TimeBlock& root_timer = TimeBlock::getRootTimer(); + mThreadRecording.start(); // initialize time block parent pointers for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); @@ -60,15 +59,15 @@ ThreadRecorder::ThreadRecorder() TimeBlock& time_block = *it; TimeBlockTreeNode& tree_node = mTimeBlockTreeNodes[it->getIndex()]; tree_node.mBlock = &time_block; - tree_node.mParent = &root_timer; + tree_node.mParent = &root_time_block; - it->getPrimaryAccumulator()->mParent = &root_timer; + it->getPrimaryAccumulator()->mParent = &root_time_block; } - mRootTimer = new BlockTimer(root_timer); - mRootTimerData->mCurTimer = mRootTimer; + mRootTimer = new BlockTimer(root_time_block); + timer_stack->mActiveTimer = mRootTimer; - TimeBlock::getRootTimer().getPrimaryAccumulator()->mActiveCount = 1; + TimeBlock::getRootTimeBlock().getPrimaryAccumulator()->mActiveCount = 1; } ThreadRecorder::~ThreadRecorder() @@ -79,9 +78,7 @@ ThreadRecorder::~ThreadRecorder() { mActiveRecordings.front().mTargetRecording->stop(); } - get_thread_recorder() = NULL; - TimeBlock::sCurTimerData = NULL; - delete mRootTimerData; + set_thread_recorder(NULL); delete[] mTimeBlockTreeNodes; } @@ -196,12 +193,12 @@ SlaveThreadRecorder::~SlaveThreadRecorder() void SlaveThreadRecorder::pushToMaster() { - mFullRecording.stop(); + mThreadRecording.stop(); { LLMutexLock(getMasterThreadRecorder().getSlaveListMutex()); - mSharedData.appendFrom(mFullRecording); + mSharedData.appendFrom(mThreadRecording); } - mFullRecording.start(); + mThreadRecording.start(); } void SlaveThreadRecorder::SharedData::appendFrom( const Recording& source ) diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index d09527eced..337035974c 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -62,13 +62,12 @@ namespace LLTrace void moveBaselineToTarget(); }; - Recording mFullRecording; + Recording mThreadRecording; std::list mActiveRecordings; - struct CurTimerData* mRootTimerData; - class BlockTimer* mRootTimer; - TimeBlockTreeNode* mTimeBlockTreeNodes; - size_t mNumTimeBlockTreeNodes; + class BlockTimer* mRootTimer; + TimeBlockTreeNode* mTimeBlockTreeNodes; + size_t mNumTimeBlockTreeNodes; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder -- cgit v1.2.3 From 6e82bb7789c1e046dcfb97c6773150df110153f8 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Jan 2013 22:34:34 +0000 Subject: fixing linux compile errors for llcommon after LLTrace work --- indra/llcommon/llfasttimer.h | 2 +- indra/llcommon/llmemory.h | 1 + indra/llcommon/llthreadlocalstorage.h | 21 +++++++++++++++++++++ indra/llcommon/lltrace.h | 26 +++++++++++++------------- indra/llcommon/lltracerecording.h | 18 +++++++++--------- 5 files changed, 45 insertions(+), 23 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 995eebd16a..fb2868ff98 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -49,7 +49,7 @@ class ThreadTimerStack : public BlockTimerStackRecord, public LLThreadLocalSingleton { - friend LLThreadLocalSingleton; + friend class LLThreadLocalSingleton; ThreadTimerStack() {} diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index e725bdd9fa..7e73afe06a 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -27,6 +27,7 @@ #define LLMEMORY_H #include "linden_common.h" +#include "stdint.h" class LLMutex ; diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index fdf0c18085..5a38d54eea 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -215,15 +215,28 @@ private: LLThreadLocalSingleton(const LLThreadLocalSingleton& other); virtual void initSingleton() {} +#ifdef LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; static __declspec(thread) EInitState sInitState; +#elif LL_LINUX + static __thread DERIVED_TYPE* sInstance; + static __thread EInitState sInitState; +#endif }; +#ifdef LL_WINDOWS template __declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __declspec(thread) typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#elif LL_LINUX +template +__thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; + +template +__thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#endif template class LLThreadLocalSingletonPointer @@ -245,10 +258,18 @@ public: } private: +#ifdef LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; +#elif LL_LINUX + static __thread DERIVED_TYPE* sInstance; +#endif }; template +#ifdef LL_WINDOWS __declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#elif LL_LINUX +__thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#endif #endif // LL_LLTHREADLOCALSTORAGE_H diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 285d4389af..e15cffd7d2 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -614,7 +614,7 @@ struct MemFootprint static size_t measure() { - return MemFootPrint::measure(); + return MemFootprint::measure(); } }; @@ -730,17 +730,17 @@ public: } // claim memory associated with other objects/data as our own, adding to our calculated footprint - template - T& memClaim(T& value) + template + CLAIM_T& memClaim(CLAIM_T& value) { - TrackMemImpl::claim(*this, value); + TrackMemImpl::claim(*this, value); return value; } - template - const T& memClaim(const T& value) + template + const CLAIM_T& memClaim(const CLAIM_T& value) { - TrackMemImpl::claim(*this, value); + TrackMemImpl::claim(*this, value); return value; } @@ -756,17 +756,17 @@ public: } // remove memory we had claimed from our calculated footprint - template - T& memDisclaim(T& value) + template + CLAIM_T& memDisclaim(CLAIM_T& value) { - TrackMemImpl::disclaim(*this, value); + TrackMemImpl::disclaim(*this, value); return value; } - template - const T& memDisclaim(const T& value) + template + const CLAIM_T& memDisclaim(const CLAIM_T& value) { - TrackMemImpl::disclaim(*this, value); + TrackMemImpl::disclaim(*this, value); return value; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f2d7d42211..aa3200e5ad 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -141,7 +141,7 @@ namespace LLTrace template T getSum(const Count& stat) const { - return (T)getSum(static_cast::type_t> >&> (stat)); + return (T)getSum(static_cast::type_t> >&> (stat)); } F64 getPerSec(const TraceType >& stat) const; @@ -149,7 +149,7 @@ namespace LLTrace template T getPerSec(const Count& stat) const { - return (T)getPerSec(static_cast::type_t> >&> (stat)); + return (T)getPerSec(static_cast::type_t> >&> (stat)); } U32 getSampleCount(const TraceType >& stat) const; @@ -162,7 +162,7 @@ namespace LLTrace template T getSum(const Measurement& stat) const { - return (T)getSum(static_cast::type_t> >&> (stat)); + return (T)getSum(static_cast::type_t> >&> (stat)); } F64 getPerSec(const TraceType >& stat) const; @@ -170,7 +170,7 @@ namespace LLTrace template T getPerSec(const Measurement& stat) const { - return (T)getPerSec(static_cast::type_t> >&> (stat)); + return (T)getPerSec(static_cast::type_t> >&> (stat)); } F64 getMin(const TraceType >& stat) const; @@ -178,7 +178,7 @@ namespace LLTrace template T getMin(const Measurement& stat) const { - return (T)getMin(static_cast::type_t> >&> (stat)); + return (T)getMin(static_cast::type_t> >&> (stat)); } F64 getMax(const TraceType >& stat) const; @@ -186,7 +186,7 @@ namespace LLTrace template T getMax(const Measurement& stat) const { - return (T)getMax(static_cast::type_t> >&> (stat)); + return (T)getMax(static_cast::type_t> >&> (stat)); } F64 getMean(const TraceType >& stat) const; @@ -194,7 +194,7 @@ namespace LLTrace template T getMean(Measurement& stat) const { - return (T)getMean(static_cast::type_t> >&> (stat)); + return (T)getMean(static_cast::type_t> >&> (stat)); } F64 getStandardDeviation(const TraceType >& stat) const; @@ -202,7 +202,7 @@ namespace LLTrace template T getStandardDeviation(const Measurement& stat) const { - return (T)getMean(static_cast::type_t> >&> (stat)); + return (T)getMean(static_cast::type_t> >&> (stat)); } F64 getLastValue(const TraceType >& stat) const; @@ -210,7 +210,7 @@ namespace LLTrace template T getLastValue(const Measurement& stat) const { - return (T)getLastValue(static_cast::type_t> >&> (stat)); + return (T)getLastValue(static_cast::type_t> >&> (stat)); } U32 getSampleCount(const TraceType >& stat) const; -- cgit v1.2.3 From 019836a39667889d4347277cde82270113992bb6 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 4 Jan 2013 03:02:54 +0000 Subject: More fixes for linux build of lltrace changes --- indra/llcommon/llerrorlegacy.h | 2 ++ indra/llcommon/llunit.h | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llerrorlegacy.h b/indra/llcommon/llerrorlegacy.h index 58cc2899af..097a533b1a 100644 --- a/indra/llcommon/llerrorlegacy.h +++ b/indra/llcommon/llerrorlegacy.h @@ -114,8 +114,10 @@ const int LL_ERR_PRICE_MISMATCH = -23018; #ifdef LL_WINDOWS #define llstatic_assert(func, msg) static_assert(func, msg) +#define llstatic_assert_template(type, func, msg) static_assert(func, msg) #else #define llstatic_assert(func, msg) BOOST_STATIC_ASSERT(func) +#define llstatic_assert_template(type, func, msg) BOOST_STATIC_ASSERT(sizeof(type) != 0 && func); #endif // handy compile-time assert - enforce those template parameters! diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 72a6020ff8..c600883607 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -29,6 +29,7 @@ #include "stdtypes.h" #include "llpreprocessor.h" +#include "llerrorlegacy.h" namespace LLUnits { @@ -53,7 +54,7 @@ struct ConversionFactor static typename HighestPrecisionType::type_t get() { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(DERIVED_UNITS_TAG) == 0, "Cannot convert between types."); + llstatic_assert_template(DERIVED_UNITS_TAG, false, "Cannot convert between types."); } }; @@ -141,7 +142,7 @@ struct LLUnit void operator *= (LLUnit multiplicand) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(OTHER_UNIT) == 0, "Multiplication of unit types not supported."); + llstatic_assert_template(OTHER_UNIT, 0, "Multiplication of unit types not supported."); } void operator /= (storage_t divisor) @@ -153,7 +154,7 @@ struct LLUnit void operator /= (LLUnit divisor) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(OTHER_UNIT) == 0, "Illegal in-place division of unit types."); + llstatic_assert_template(OTHER_UNIT, 0, "Illegal in-place division of unit types."); } template @@ -313,7 +314,7 @@ template operator * (LLUnit, LLUnit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + llstatic_assert_template(STORAGE_TYPE1, 0, "Multiplication of unit types results in new unit type - not supported."); return LLUnit(); } @@ -333,7 +334,7 @@ template operator * (LLUnitImplicit, LLUnitImplicit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + llstatic_assert_template(STORAGE_TYPE1, 0, "Multiplication of unit types results in new unit type - not supported."); return LLUnitImplicit(); } -- cgit v1.2.3 From b2197101c488de66ca9ecf71c229f5b80d1390fd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 4 Jan 2013 13:04:09 -0800 Subject: SH-3468 WIP add memory tracking base class fix for compile error on windows ignore stdint.h even though VS2010 provides it --- indra/llcommon/llmemory.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 7e73afe06a..4ead45679f 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -27,7 +27,9 @@ #define LLMEMORY_H #include "linden_common.h" -#include "stdint.h" +#if !LL_WINDOWS +#include +#endif class LLMutex ; -- cgit v1.2.3 From cbff0e7ab8afeebb6ddab854d35ea12ef9a9930a Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 4 Jan 2013 13:48:35 -0800 Subject: SH-3468 WIP add memory tracking base class attempted fix for gcc compile errors can't use typeid() on a class that doesn't have a method defined in a translation unit fix is to force classes deriving from LLMemTrackable to use their own static member named sMemStat --- indra/llcommon/lltrace.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index e15cffd7d2..1a156e583e 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -660,13 +660,13 @@ struct MemFootprint > } }; -template +template class MemTrackable { template struct TrackMemImpl; - typedef MemTrackable mem_trackable_t; + typedef MemTrackable mem_trackable_t; public: typedef void mem_trackable_tag_t; @@ -681,7 +681,7 @@ public: // reserve 8 bytes for allocation size (and preserving 8 byte alignment of structs) void* allocation = ::operator new(allocation_size + 8); *(size_t*)allocation = allocation_size; - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize += allocation_size; @@ -693,7 +693,7 @@ public: void operator delete(void* ptr) { size_t* allocation_size = (size_t*)((char*)ptr - 8); - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize -= *allocation_size; @@ -707,7 +707,7 @@ public: { size_t* result = (size_t*)malloc(size + 8); *result = size; - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize += size; @@ -719,7 +719,7 @@ public: void operator delete[](void* ptr) { size_t* allocation_size = (size_t*)((char*)ptr - 8); - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize -= *allocation_size; @@ -747,7 +747,7 @@ public: void memClaim(size_t size) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); mMemFootprint += size; if (accumulator) { @@ -772,7 +772,7 @@ public: void memDisclaim(size_t size) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize -= size; @@ -788,7 +788,7 @@ private: { static void claim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { size_t footprint = MemFootprint::measure(tracked); @@ -799,7 +799,7 @@ private: static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { size_t footprint = MemFootprint::measure(tracked); @@ -814,7 +814,7 @@ private: { static void claim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mChildSize += MemFootprint::measure(tracked); @@ -823,17 +823,14 @@ private: static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mChildSize -= MemFootprint::measure(tracked); } } }; - static MemStat sStat; }; -template MemStat MemTrackable::sStat(typeid(T).name()); - } #endif // LL_LLTRACE_H -- cgit v1.2.3 From cf8fa1a958f8676a0911bac7bdb950a865b58c83 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 4 Jan 2013 15:57:28 -0800 Subject: SH-3468 WIP add memory tracking base class further compile error fixes --- indra/llcommon/llfasttimer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index ad8cf7296e..e6233a094e 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -137,12 +137,12 @@ void TimeBlock::setLogLock(LLMutex* lock) //static #if (LL_DARWIN || LL_LINUX || LL_SOLARIS) && !(defined(__i386__) || defined(__amd64__)) -U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer +U64 TimeBlock::countsPerSecond() { return sClockResolution; } #else // windows or x86-mac or x86-linux or x86-solaris -U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer +U64 TimeBlock::countsPerSecond() { #if LL_FASTTIMER_USE_RDTSC || !LL_WINDOWS //getCPUFrequency returns MHz and sCPUClockFrequency wants to be in Hz @@ -165,7 +165,7 @@ U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer #endif TimeBlock::TimeBlock(const char* name, bool open, TimeBlock* parent) -: TraceType(name), +: TraceType(name), mCollapsed(true) { setCollapsed(!open); -- cgit v1.2.3 From 7dbb8860373769dfca7d6c6588284866a1bf86a3 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 4 Jan 2013 16:19:20 -0800 Subject: SH-3468 WIP add memory tracking base class further compile error fixes --- indra/llcommon/lltracerecording.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 9dbafc4e82..c110e64380 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -60,7 +60,7 @@ Recording::Recording( const Recording& other ) mStackTimers = other.mStackTimers; mMemStats = other.mMemStats; - LLStopWatchControlsMixin::initTo(other.getPlayState()); + LLStopWatchControlsMixin::initTo(other.getPlayState()); } -- cgit v1.2.3 From 68413515029f50713c70e4adec3ce6fd1022d59f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 6 Jan 2013 21:37:31 -0800 Subject: SH-3468 WIP add memory tracking base class fix for unit test failures...cleanup apr without destroying pools, allowing LLProxy to clean itself up as a singleton (and avoiding spurious dependencies associated with manually destorying singletons that rely on apr pools) --- indra/llcommon/llapr.cpp | 4 ++-- indra/llcommon/llapr.h | 2 +- indra/llcommon/lltracethreadrecorder.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index d911f258b6..8a87911315 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -60,7 +60,7 @@ void ll_init_apr() } -void ll_cleanup_apr() +void ll_cleanup_apr(bool destroy_pools) { LL_INFOS("APR") << "Cleaning up APR" << LL_ENDL; @@ -83,7 +83,7 @@ void ll_cleanup_apr() LLThreadLocalPointerBase::destroyAllThreadLocalStorage(); - if (gAPRPoolp) + if (gAPRPoolp && destroy_pools) { apr_pool_destroy(gAPRPoolp); gAPRPoolp = NULL; diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index b3c9bfd58c..424ddc6505 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -70,7 +70,7 @@ void LL_COMMON_API ll_init_apr(); /** * @brief Cleanup those common apr constructs. */ -void LL_COMMON_API ll_cleanup_apr(); +void LL_COMMON_API ll_cleanup_apr(bool destroy_pools = true); // //LL apr_pool diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 9fb789c62d..7b493a651e 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -127,7 +127,7 @@ std::list::iterator ThreadRecorder::update( Rec if (it == end_it) { - llerrs << "Recording not active on this thread" << llendl; + llwarns << "Recording not active on this thread" << llendl; } return it; -- cgit v1.2.3 From 3c341a11ab7b8f3fd18afcf3f50af6dfafa632c2 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 8 Jan 2013 00:25:07 -0800 Subject: SH-3468 WIP add memory tracking base class more fixes for unit test crashes added llcommon initialization/teardown for unit tests that indirectly trigger lltrace changed access of atomic refcount to use preincrement/decrement operators to reflect desired semantics always call apr_initialize in LLCommon::initClass, even if already initialized...apr does internal reference counting to keep things straight --- indra/llcommon/llapr.cpp | 19 +++++++++++++++---- indra/llcommon/llapr.h | 5 ++++- indra/llcommon/llmutex.cpp | 11 +++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 8a87911315..0556fadb26 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -38,12 +38,15 @@ apr_thread_mutex_t *gCallStacksLogMutexp = NULL; const S32 FULL_VOLATILE_APR_POOL = 1024 ; //number of references to LLVolatileAPRPool +bool gAPRInitialized = false; + void ll_init_apr() { + // Initialize APR and create the global pool + apr_initialize(); + if (!gAPRPoolp) { - // Initialize APR and create the global pool - apr_initialize(); apr_pool_create(&gAPRPoolp, NULL); // Initialize the logging mutex @@ -57,11 +60,19 @@ void ll_init_apr() } LLThreadLocalPointerBase::initAllThreadLocalStorage(); + gAPRInitialized = true; } -void ll_cleanup_apr(bool destroy_pools) +bool ll_apr_is_initialized() +{ + return gAPRInitialized; +} + +void ll_cleanup_apr() { + gAPRInitialized = false; + LL_INFOS("APR") << "Cleaning up APR" << LL_ENDL; if (gLogMutexp) @@ -83,7 +94,7 @@ void ll_cleanup_apr(bool destroy_pools) LLThreadLocalPointerBase::destroyAllThreadLocalStorage(); - if (gAPRPoolp && destroy_pools) + if (gAPRPoolp) { apr_pool_destroy(gAPRPoolp); gAPRPoolp = NULL; diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 424ddc6505..3b65c0dc34 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -70,7 +70,10 @@ void LL_COMMON_API ll_init_apr(); /** * @brief Cleanup those common apr constructs. */ -void LL_COMMON_API ll_cleanup_apr(bool destroy_pools = true); +void LL_COMMON_API ll_cleanup_apr(); + +bool LL_COMMON_API ll_apr_is_initialized(); + // //LL apr_pool diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp index b685bb4d60..ad0287c6d5 100644 --- a/indra/llcommon/llmutex.cpp +++ b/indra/llcommon/llmutex.cpp @@ -56,12 +56,15 @@ LLMutex::~LLMutex() //bad assertion, the subclass LLSignal might be "locked", and that's OK //llassert_always(!isLocked()); // better not be locked! #endif - apr_thread_mutex_destroy(mAPRMutexp); - mAPRMutexp = NULL; - if (mIsLocalPool) + if (ll_apr_is_initialized()) { - apr_pool_destroy(mAPRPoolp); + apr_thread_mutex_destroy(mAPRMutexp); + if (mIsLocalPool) + { + apr_pool_destroy(mAPRPoolp); + } } + mAPRMutexp = NULL; } -- cgit v1.2.3 From 0ba9a00c3116b69745f2d5070ce772d5d4965dbf Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 8 Jan 2013 23:50:27 -0800 Subject: SH-3468 WIP add memory tracking base class cleaned up hacks used to get unit tests working LLTrace::init now supports recursive initialization/cleanup put NOMINMAX back in win32 header wrappers --- indra/llcommon/lltrace.cpp | 17 +++++++++++------ indra/llcommon/llwin32headers.h | 4 ++++ indra/llcommon/llwin32headerslean.h | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 9cadd70dd8..463048008f 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -30,7 +30,7 @@ #include "lltracethreadrecorder.h" #include "llfasttimer.h" -static bool sInitialized; +static S32 sInitializationCount = 0; namespace LLTrace { @@ -39,19 +39,24 @@ static MasterThreadRecorder* gMasterThreadRecorder = NULL; void init() { - gMasterThreadRecorder = new MasterThreadRecorder(); - sInitialized = true; + if (sInitializationCount++ == 0) + { + gMasterThreadRecorder = new MasterThreadRecorder(); + } } bool isInitialized() { - return sInitialized; + return sInitializationCount > 0; } void cleanup() { - delete gMasterThreadRecorder; - gMasterThreadRecorder = NULL; + if (--sInitializationCount == 0) + { + delete gMasterThreadRecorder; + gMasterThreadRecorder = NULL; + } } MasterThreadRecorder& getMasterThreadRecorder() diff --git a/indra/llcommon/llwin32headers.h b/indra/llcommon/llwin32headers.h index 9c89b6b280..8534ed6298 100644 --- a/indra/llcommon/llwin32headers.h +++ b/indra/llcommon/llwin32headers.h @@ -28,9 +28,13 @@ #define LL_LLWINDOWS_H #ifdef LL_WINDOWS +#ifndef NOMINMAX +#define NOMINMAX +#endif #undef WIN32_LEAN_AND_MEAN #include #include +#undef NOMINMAX #endif #endif diff --git a/indra/llcommon/llwin32headerslean.h b/indra/llcommon/llwin32headerslean.h index d3fb90d4b1..f7e71301a8 100644 --- a/indra/llcommon/llwin32headerslean.h +++ b/indra/llcommon/llwin32headerslean.h @@ -28,9 +28,13 @@ #define LL_LLWINDOWS_H #ifdef LL_WINDOWS +#ifndef NOMINMAX +#define NOMINMAX +#endif #define WIN32_LEAN_AND_MEAN #include #include +#undef NOMINMAX #endif #endif -- cgit v1.2.3 From 386e918583fe25532f401c6b50c49632d7410d39 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 9 Jan 2013 11:21:45 -0800 Subject: SH-3468 WIP add memory tracking base class fix for linux build issues --- indra/llcommon/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 28677b036d..7ed1671ca8 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -257,6 +257,8 @@ set(llcommon_HEADER_FILES lluuidhashmap.h llversionserver.h llversionviewer.h + llwin32headers.h + llwin32headerslean.h llworkerthread.h ll_template_cast.h metaclass.h -- cgit v1.2.3 From 1a888f786c274ee6eaed54272718eeef5e685dbf Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 9 Jan 2013 23:05:07 -0800 Subject: SH-3468 WIP add memory tracking base class made LLTrace::MemTrackable support custom alignment LLDrawable now uses MemTrackable new and delete operators --- indra/llcommon/llmemory.h | 14 ++++++++ indra/llcommon/lltrace.h | 85 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 14 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 4ead45679f..95500753e4 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -39,6 +39,20 @@ class LLMutex ; #define LL_CHECK_MEMORY #endif +#if LL_WINDOWS +#define LL_ALIGN_OF __alignof +#else +#define LL_ALIGN_OF __align_of__ +#endif + +#if LL_WINDOWS +#define LL_DEFAULT_HEAP_ALIGN 8 +#elif LL_DARWIN +#define LL_DEFAULT_HEAP_ALIGN 16 +#elif LL_LINUX +#define LL_DEFAULT_HEAP_ALIGN 8 +#endif + inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 1a156e583e..8ec0cdc4dc 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -660,7 +660,57 @@ struct MemFootprint > } }; -template +template +void* allocAligned(size_t size) +{ + llstatic_assert((ALIGNMENT > 0) && (ALIGNMENT & (ALIGNMENT - 1)) == 0, "Alignment must be a power of 2"); + + void* padded_allocation; + const size_t aligned_reserve = (RESERVE / ALIGNMENT) + + ((RESERVE % ALIGNMENT) ? ALIGNMENT : 0); + const size_t size_with_reserve = size + aligned_reserve; + if (ALIGNMENT <= LL_DEFAULT_HEAP_ALIGN) + { + padded_allocation = malloc(size_with_reserve); + } + else + { +#if LL_WINDOWS + padded_allocation = _aligned_malloc(size_with_reserve, ALIGNMENT); +#elif LL_DARWIN + padded_allocation = ll_aligned_malloc(size_with_reserve, ALIGNMENT); +#else + posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); +#endif + } + return (char*)padded_allocation + aligned_reserve; +} + +template +void deallocAligned(void* ptr) +{ + const size_t aligned_reserve = (RESERVE / ALIGNMENT) + + ((RESERVE % ALIGNMENT) ? ALIGNMENT : 0); + + void* original_allocation = (char*)ptr - aligned_reserve; + + if (ALIGNMENT <= LL_DEFAULT_HEAP_ALIGN) + { + free(original_allocation); + } + else + { +#if LL_WINDOWS + _aligned_free(original_allocation); +#elif LL_DARWIN + ll_aligned_free(original_allocation); +#else + free(original_allocation); +#endif + } +} + +template class MemTrackable { template @@ -676,44 +726,49 @@ public: memDisclaim(mMemFootprint); } - void* operator new(size_t allocation_size) + void* operator new(size_t size) { - // reserve 8 bytes for allocation size (and preserving 8 byte alignment of structs) - void* allocation = ::operator new(allocation_size + 8); - *(size_t*)allocation = allocation_size; MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize += allocation_size; + accumulator->mSize += size; accumulator->mAllocatedCount++; } - return (void*)((char*)allocation + 8); + + // reserve 4 bytes for allocation size (and preserving requested alignment) + void* allocation = allocAligned(size); + ((size_t*)allocation)[-1] = size; + + return allocation; } void operator delete(void* ptr) { - size_t* allocation_size = (size_t*)((char*)ptr - 8); + size_t allocation_size = ((size_t*)ptr)[-1]; MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= *allocation_size; + accumulator->mSize -= allocation_size; accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } - ::delete((char*)ptr - 8); + deallocAligned(ptr); } void *operator new [](size_t size) { - size_t* result = (size_t*)malloc(size + 8); - *result = size; MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize += size; accumulator->mAllocatedCount++; } - return (void*)((char*)result + 8); + + // reserve 4 bytes for allocation size (and preserving requested alignment) + void* allocation = allocAligned(size); + ((size_t*)allocation)[-1] = size; + + return allocation; } void operator delete[](void* ptr) @@ -726,7 +781,7 @@ public: accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } - ::delete[]((char*)ptr - 8); + deallocAligned(ptr); } // claim memory associated with other objects/data as our own, adding to our calculated footprint @@ -783,6 +838,8 @@ public: private: size_t mMemFootprint; + + template struct TrackMemImpl { -- cgit v1.2.3 From a891785f7a02098a53029311befd7083773d6ad8 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 10 Jan 2013 07:45:43 +0000 Subject: typo fix --- indra/llcommon/lltrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 8ec0cdc4dc..7694f65441 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -781,7 +781,7 @@ public: accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } - deallocAligned(ptr); + deallocAligned(ptr); } // claim memory associated with other objects/data as our own, adding to our calculated footprint -- cgit v1.2.3 From 8c73ff245cee8da2ca75c5651be88a36358a5dae Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 10 Jan 2013 00:12:25 -0800 Subject: SH-3468 WIP add memory tracking base class actually use return value of posix_memalign! --- indra/llcommon/lltrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 7694f65441..a9d5cc58de 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -680,7 +680,7 @@ void* allocAligned(size_t size) #elif LL_DARWIN padded_allocation = ll_aligned_malloc(size_with_reserve, ALIGNMENT); #else - posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); + padded_allocation = posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); #endif } return (char*)padded_allocation + aligned_reserve; -- cgit v1.2.3 From f8a2bca6526ea1eef61a9b8cf0fb2e78c2663d60 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 10 Jan 2013 08:47:29 +0000 Subject: fix for invalid use of posix_memalign --- indra/llcommon/lltrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index a9d5cc58de..7694f65441 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -680,7 +680,7 @@ void* allocAligned(size_t size) #elif LL_DARWIN padded_allocation = ll_aligned_malloc(size_with_reserve, ALIGNMENT); #else - padded_allocation = posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); + posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); #endif } return (char*)padded_allocation + aligned_reserve; -- cgit v1.2.3 From d89d9cd10ff1fbe6f1f86f0b282075e775ed1b51 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 11 Jan 2013 01:52:09 +0000 Subject: gcc fixes --- indra/llcommon/lltrace.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 7694f65441..ab4ad59e3d 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -680,7 +680,8 @@ void* allocAligned(size_t size) #elif LL_DARWIN padded_allocation = ll_aligned_malloc(size_with_reserve, ALIGNMENT); #else - posix_memalign(&padded_allocation, ALIGNMENT, size_with_reserve); + if (LL_UNLIKELY(0 != posix_memalign(&padded_allocation, 16, size))) + padded_allocation = NULL; #endif } return (char*)padded_allocation + aligned_reserve; -- cgit v1.2.3 From 62a9f557d2e91beb685843775e8f9fe73dab4b94 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 10:16:26 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system moved thread local storage to its own cpp file --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llapr.cpp | 71 ---------------------- indra/llcommon/llthreadlocalstorage.cpp | 101 ++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 indra/llcommon/llthreadlocalstorage.cpp (limited to 'indra/llcommon') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index 7ed1671ca8..f8f1c010f7 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -98,6 +98,7 @@ set(llcommon_SOURCE_FILES llstringtable.cpp llsys.cpp llthread.cpp + llthreadlocalstorage.cpp llthreadsafequeue.cpp lltimer.cpp lltrace.cpp diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 0556fadb26..47fa70614f 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -493,77 +493,6 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) return LLAPRFile::seek(mFile, where, offset) ; } -// -//LLThreadLocalPointerBase -// -bool LLThreadLocalPointerBase::sInitialized = false; - -void LLThreadLocalPointerBase::set( void* value ) -{ - llassert(sInitialized && mThreadKey); - - apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to set thread local data" << llendl; - } -} - -void LLThreadLocalPointerBase::initStorage( ) -{ - apr_status_t result = apr_threadkey_private_create(&mThreadKey, NULL, gAPRPoolp); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to allocate thread local data" << llendl; - } -} - -void LLThreadLocalPointerBase::destroyStorage() -{ - if (sInitialized) - { - if (mThreadKey) - { - apr_status_t result = apr_threadkey_private_delete(mThreadKey); - if (result != APR_SUCCESS) - { - ll_apr_warn_status(result); - llerrs << "Failed to delete thread local data" << llendl; - } - } - } -} - -void LLThreadLocalPointerBase::initAllThreadLocalStorage() -{ - if (!sInitialized) - { - for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); - it != end_it; - ++it) - { - (*it).initStorage(); - } - sInitialized = true; - } -} - -void LLThreadLocalPointerBase::destroyAllThreadLocalStorage() -{ - if (sInitialized) - { - //for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); - // it != end_it; - // ++it) - //{ - // (*it).destroyStorage(); - //} - sInitialized = false; - } -} - // //******************************************************************************************************************************* //static components of LLAPRFile diff --git a/indra/llcommon/llthreadlocalstorage.cpp b/indra/llcommon/llthreadlocalstorage.cpp new file mode 100644 index 0000000000..7858ee5429 --- /dev/null +++ b/indra/llcommon/llthreadlocalstorage.cpp @@ -0,0 +1,101 @@ +/** + * @file llthreadlocalstorage.cpp + * @author Richard + * @date 2013-1-11 + * @brief implementation of thread local storage utility classes + * + * $LicenseInfo:firstyear=2013&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "llthreadlocalstorage.h" + +// +//LLThreadLocalPointerBase +// +bool LLThreadLocalPointerBase::sInitialized = false; + +void LLThreadLocalPointerBase::set( void* value ) +{ + llassert(sInitialized && mThreadKey); + + apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to set thread local data" << llendl; + } +} + +void LLThreadLocalPointerBase::initStorage( ) +{ + apr_status_t result = apr_threadkey_private_create(&mThreadKey, NULL, gAPRPoolp); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to allocate thread local data" << llendl; + } +} + +void LLThreadLocalPointerBase::destroyStorage() +{ + if (sInitialized) + { + if (mThreadKey) + { + apr_status_t result = apr_threadkey_private_delete(mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to delete thread local data" << llendl; + } + } + } +} + +void LLThreadLocalPointerBase::initAllThreadLocalStorage() +{ + if (!sInitialized) + { + for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + it != end_it; + ++it) + { + (*it).initStorage(); + } + sInitialized = true; + } +} + +void LLThreadLocalPointerBase::destroyAllThreadLocalStorage() +{ + if (sInitialized) + { + //for (LLInstanceTracker::instance_iter it = beginInstances(), end_it = endInstances(); + // it != end_it; + // ++it) + //{ + // (*it).destroyStorage(); + //} + sInitialized = false; + } +} -- cgit v1.2.3 From 44cc14fbee8c9cb033dcb94d9c54f532427a5768 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 13:11:07 -0800 Subject: fix for mac builds --- indra/llcommon/llthreadlocalstorage.h | 69 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 5a38d54eea..91f45d4f5f 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -152,43 +152,48 @@ public: virtual ~LLThreadLocalSingleton() { sInstance = NULL; - sInitState = DELETED; + setInitState(DELETED); } static void deleteSingleton() { delete sInstance; sInstance = NULL; - sInitState = DELETED; + setInitState(DELETED); } static DERIVED_TYPE* getInstance() { - if (sInitState == CONSTRUCTING) + EInitState init_state = getInitState(); + if (init_state == CONSTRUCTING) { llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl; } - if (sInitState == DELETED) + if (init_state == DELETED) { llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; } - if (!sInstance) + if (!getIfExists()) { - sInitState = CONSTRUCTING; + setInitState(CONSTRUCTING); sInstance = new DERIVED_TYPE(); - sInitState = INITIALIZING; + setInitState(INITIALIZING); sInstance->initSingleton(); - sInitState = INITIALIZED; + setInitState(INITIALIZED); } - return sInstance; + return getIfExists(); } static DERIVED_TYPE* getIfExists() { +#if LL_DARWIN + return sInstance.get(); +#else return sInstance; +#endif } // Reference version of getInstance() @@ -202,16 +207,33 @@ public: // Use this to avoid accessing singletons before the can safely be constructed static bool instanceExists() { - return sInitState == INITIALIZED; + return getInitState() == INITIALIZED; } // Has this singleton already been deleted? // Use this to avoid accessing singletons from a static object's destructor static bool destroyed() { - return sInitState == DELETED; + return getInitState() == DELETED; } private: + static EInitState getInitState() + { +#if LL_DARWIN + return (EInitState)(int)sInitState.get(); +#else + return sInitState; +#endif + } + + static void setInitState(EInitState state) + { +#if LL_DARWIN + sInitState = (int*)state; +#else + sInitState = state; +#endif + } LLThreadLocalSingleton(const LLThreadLocalSingleton& other); virtual void initSingleton() {} @@ -221,10 +243,13 @@ private: #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; +#elif LL_DARWIN + static LLThreadLocalPointer sInstance; + static LLThreadLocalPointer sInitState; #endif }; -#ifdef LL_WINDOWS +#if LL_WINDOWS template __declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; @@ -236,6 +261,12 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#elif LL_DARWIN +template +LLThreadLocalPointer LLThreadLocalSingleton::sInstance; + +template +LLThreadLocalPointer LLThreadLocalSingleton::sInitState; #endif template @@ -249,7 +280,11 @@ public: LL_FORCE_INLINE static DERIVED_TYPE* getInstance() { +#if LL_DARWIN + return sInstance.get(); +#else return sInstance; +#endif } LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) @@ -258,18 +293,24 @@ public: } private: -#ifdef LL_WINDOWS +#if LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; +#elif LL_DARWIN + static LLThreadLocalPointer sInstance; #endif }; +#if LL_WINDOWS template -#ifdef LL_WINDOWS __declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; #elif LL_LINUX +template __thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#elif LL_DARWIN +template +LLThreadLocalPointer LLThreadLocalSingletonPointer::sInstance; #endif #endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3 From 85df1df3c34115efa0e18d116f7923b88ec1dadf Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 14:24:52 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system gcc 4.1 fixes --- indra/llcommon/llunit.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index c600883607..c43ca2ba18 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -75,9 +75,9 @@ struct LLUnit typedef LLUnit self_t; typedef STORAGE_TYPE storage_t; - // value initialization - LLUnit(storage_t value = storage_t()) - : mValue(value) + // default initialization + LLUnit() + : mValue(storage_t()) {} // unit initialization and conversion @@ -85,6 +85,12 @@ struct LLUnit LLUnit(LLUnit other) : mValue(convert(other)) {} + + // value initialization + template + LLUnit(CONVERTABLE_TYPE value) + : mValue(value) + {} // value assignment self_t& operator = (storage_t value) -- cgit v1.2.3 From 512d7381eca7bc53bb31e9528e5a7c5df189e82d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 15:45:20 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system gcc 4.1 fixes --- indra/llcommon/llunit.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index c43ca2ba18..f43df3753a 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -76,8 +76,8 @@ struct LLUnit typedef STORAGE_TYPE storage_t; // default initialization - LLUnit() - : mValue(storage_t()) + LLUnit(storage_t value = storage_t()) + : mValue(value) {} // unit initialization and conversion @@ -85,12 +85,6 @@ struct LLUnit LLUnit(LLUnit other) : mValue(convert(other)) {} - - // value initialization - template - LLUnit(CONVERTABLE_TYPE value) - : mValue(value) - {} // value assignment self_t& operator = (storage_t value) -- cgit v1.2.3 From 91a8383b4a0bbd2d48d2d84678f5bcc3701c2b9f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 16:30:05 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system gcc 4.1 fixes --- indra/llcommon/llunit.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index f43df3753a..c2a31b7604 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -75,7 +75,7 @@ struct LLUnit typedef LLUnit self_t; typedef STORAGE_TYPE storage_t; - // default initialization + // value initialization LLUnit(storage_t value = storage_t()) : mValue(value) {} @@ -301,13 +301,13 @@ LLUnitImplicit operator - (SCALAR_TYPE first, LLUnitImp template LLUnit operator * (SCALAR_TYPE first, LLUnit second) { - return LLUnit(first * second.value()); + return LLUnit((STORAGE_TYPE)(first * second.value())); } template LLUnit operator * (LLUnit first, SCALAR_TYPE second) { - return LLUnit(first.value() * second); + return LLUnit((STORAGE_TYPE)(first.value() * second)); } template @@ -350,7 +350,7 @@ SCALAR_TYPE operator / (SCALAR_TYPE first, LLUnit secon template LLUnit operator / (LLUnit first, SCALAR_TYPE second) { - return LLUnit(first.value() / second); + return LLUnit((STORAGE_TYPE)(first.value() / second)); } template @@ -363,7 +363,7 @@ STORAGE_TYPE1 operator / (LLUnit first, LLUnit LLUnitImplicit operator / (LLUnitImplicit first, SCALAR_TYPE second) { - return LLUnitImplicit(first.value() / second); + return LLUnitImplicit((STORAGE_TYPE)(first.value() / second)); } template -- cgit v1.2.3 From 20b2fa4052ae6789ec8894f33f4764a1f7233b24 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 14 Jan 2013 23:08:01 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved performance of fast timer stat gathering --- indra/llcommon/llfasttimer.cpp | 28 ++++++++++++++-------------- indra/llcommon/llfasttimer.h | 19 ++++++++++--------- indra/llcommon/lltrace.h | 5 +++-- indra/llcommon/lltracerecording.cpp | 4 ++-- indra/llcommon/lltracethreadrecorder.cpp | 6 ++++-- 5 files changed, 33 insertions(+), 29 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e6233a094e..37332da31c 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -199,10 +199,11 @@ void TimeBlock::processTimes() { TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - if (accumulator->mLastCaller) + if (accumulator->mLastAccumulator) { - timer.setParent(accumulator->mLastCaller); - accumulator->mParent = accumulator->mLastCaller; + TimeBlock* parent = accumulator->mLastAccumulator->mBlock; + timer.setParent(parent); + accumulator->mParent = parent; } // no need to push up tree on first use, flag can be set spuriously accumulator->mMoveUpTree = false; @@ -250,23 +251,22 @@ void TimeBlock::processTimes() // walk up stack of active timers and accumulate current time while leaving timing structures active BlockTimer* cur_timer = stack_record->mActiveTimer; - TimeBlockAccumulator* accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = stack_record->mAccumulator; // root defined by parent pointing to self while(cur_timer && cur_timer->mLastTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U64 self_time_delta = cumulative_time_delta - stack_record->mChildTime; + accumulator->mChildTimeCounter += stack_record->mChildTime; stack_record->mChildTime = 0; - accumulator->mSelfTimeCounter += self_time_delta; accumulator->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; stack_record = &cur_timer->mLastTimerData; stack_record->mChildTime += cumulative_time_delta; - if (stack_record->mTimeBlock) + if (stack_record->mAccumulator) { - accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); + accumulator = stack_record->mAccumulator; } cur_timer = cur_timer->mLastTimerData.mActiveTimer; @@ -282,7 +282,7 @@ void TimeBlock::processTimes() TimeBlock& timer = *it; TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - accumulator->mLastCaller = NULL; + accumulator->mLastAccumulator = NULL; accumulator->mMoveUpTree = false; } @@ -417,10 +417,10 @@ void TimeBlock::writeLog(std::ostream& os) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TimeBlockAccumulator::TimeBlockAccumulator() -: mSelfTimeCounter(0), +: mChildTimeCounter(0), mTotalTimeCounter(0), mCalls(0), - mLastCaller(NULL), + mLastAccumulator(NULL), mActiveCount(0), mMoveUpTree(false), mParent(NULL) @@ -428,10 +428,10 @@ TimeBlockAccumulator::TimeBlockAccumulator() void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) { - mSelfTimeCounter += other.mSelfTimeCounter; + mChildTimeCounter += other.mChildTimeCounter; mTotalTimeCounter += other.mTotalTimeCounter; mCalls += other.mCalls; - mLastCaller = other.mLastCaller; + mLastAccumulator = other.mLastAccumulator; mActiveCount = other.mActiveCount; mMoveUpTree = other.mMoveUpTree; mParent = other.mParent; @@ -440,7 +440,7 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) { mTotalTimeCounter = 0; - mSelfTimeCounter = 0; + mChildTimeCounter = 0; mCalls = 0; } diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index fb2868ff98..2d87629561 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -40,9 +40,9 @@ namespace LLTrace struct BlockTimerStackRecord { - class BlockTimer* mActiveTimer; - class TimeBlock* mTimeBlock; - U64 mChildTime; + class BlockTimer* mActiveTimer; + class TimeBlockAccumulator* mAccumulator; + U64 mChildTime; }; class ThreadTimerStack @@ -277,7 +277,7 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) mStartTime = TimeBlock::getCPUClockCount64(); BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); - TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -286,7 +286,7 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) mLastTimerData = *cur_timer_data; // push new information cur_timer_data->mActiveTimer = this; - cur_timer_data->mTimeBlock = &timer; + cur_timer_data->mAccumulator = accumulator; cur_timer_data->mChildTime = 0; #endif } @@ -296,21 +296,22 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() #if FAST_TIMER_ON U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); - TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); + TimeBlockAccumulator* accumulator = cur_timer_data->mAccumulator; accumulator->mCalls++; - accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; + accumulator->mChildTimeCounter += cur_timer_data->mChildTime; accumulator->mTotalTimeCounter += total_time; accumulator->mActiveCount--; // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator->mLastCaller = mLastTimerData.mTimeBlock; + accumulator->mLastAccumulator = mLastTimerData.mAccumulator; // we are only tracking self time, so subtract our total time delta from parents mLastTimerData.mChildTime += total_time; - *ThreadTimerStack::getIfExists() = mLastTimerData; + //pop stack + *cur_timer_data = mLastTimerData; #endif } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index ab4ad59e3d..1d3c376a58 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -446,11 +446,12 @@ namespace LLTrace // // members // - U64 mSelfTimeCounter, + U64 mChildTimeCounter, mTotalTimeCounter; U32 mCalls; + class TimeBlock* mBlock; // block associated with this accumulator class TimeBlock* mParent; // last acknowledged parent of this time block - class TimeBlock* mLastCaller; // used to bootstrap tree construction + TimeBlockAccumulator* mLastAccumulator; // used to bootstrap tree construction U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index c110e64380..ddd25bfe87 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -179,7 +179,7 @@ LLUnit Recording::getSum(const TraceType Recording::getSum(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); + return ((F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter - (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); } @@ -195,7 +195,7 @@ LLUnit Recording::getPerSec(const TraceType Recording::getPerSec(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); + return ((F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter - (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } F32 Recording::getPerSec(const TraceType& stat) const diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 7b493a651e..9375c7bea3 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -43,7 +43,7 @@ ThreadRecorder::ThreadRecorder() TimeBlock& root_time_block = TimeBlock::getRootTimeBlock(); ThreadTimerStack* timer_stack = ThreadTimerStack::getInstance(); - timer_stack->mTimeBlock = &root_time_block; + timer_stack->mAccumulator = root_time_block.getPrimaryAccumulator(); timer_stack->mActiveTimer = NULL; mNumTimeBlockTreeNodes = AccumulatorBuffer::getDefaultBuffer()->size(); @@ -61,7 +61,9 @@ ThreadRecorder::ThreadRecorder() tree_node.mBlock = &time_block; tree_node.mParent = &root_time_block; - it->getPrimaryAccumulator()->mParent = &root_time_block; + TimeBlockAccumulator* accumulator = it->getPrimaryAccumulator(); + accumulator->mParent = &root_time_block; + accumulator->mBlock = time_block; } mRootTimer = new BlockTimer(root_time_block); -- cgit v1.2.3 From 486743e77efaa3926ddc2c0d666a0a7192700475 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 14 Jan 2013 23:10:02 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved performance of fast timer stat gathering (fixed typo) --- indra/llcommon/lltracethreadrecorder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 9375c7bea3..bc1d19e72c 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -63,7 +63,7 @@ ThreadRecorder::ThreadRecorder() TimeBlockAccumulator* accumulator = it->getPrimaryAccumulator(); accumulator->mParent = &root_time_block; - accumulator->mBlock = time_block; + accumulator->mBlock = &time_block; } mRootTimer = new BlockTimer(root_time_block); -- cgit v1.2.3 From a74509355669d059d2645d3239c9499db6818b88 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 15 Jan 2013 10:12:23 -0800 Subject: Attempted fix for thread local storage on OS X --- indra/llcommon/llthreadlocalstorage.h | 58 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 91f45d4f5f..c8b7c5e229 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -151,15 +151,17 @@ public: virtual ~LLThreadLocalSingleton() { - sInstance = NULL; +#if LL_DARWIN + //pthread_setspecific(sInstanceKey, NULL); +#else + sInstance = NULL; +#endif setInitState(DELETED); } static void deleteSingleton() { - delete sInstance; - sInstance = NULL; - setInitState(DELETED); + delete getIfExists(); } static DERIVED_TYPE* getInstance() @@ -178,9 +180,24 @@ public: if (!getIfExists()) { setInitState(CONSTRUCTING); - sInstance = new DERIVED_TYPE(); + DERIVED_TYPE* instancep = new DERIVED_TYPE(); +#if LL_DARWIN + /*static S32 sKeyCreated = pthread_key_create(&sInstanceKey, NULL); + if (sKeyCreated != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + + S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); + if (result != 0) + { + llerrs << "Could not set thread local storage" << llendl; + }*/ +#else + sInstance = instancep; +#endif setInitState(INITIALIZING); - sInstance->initSingleton(); + instancep->initSingleton(); setInitState(INITIALIZED); } @@ -190,7 +207,7 @@ public: static DERIVED_TYPE* getIfExists() { #if LL_DARWIN - return sInstance.get(); + return NULL;//(DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -217,10 +234,23 @@ public: return getInitState() == DELETED; } private: +#if LL_DARWIN + static EInitState& threadLocalInitState() + { + /*static S32 sKeyCreated = pthread_key_create(&sInitStateKey, NULL); + if (sKeyCreated != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + return *(EInitState*)pthread_getspecific(sInitStateKey);*/ + static EInitState state; + return state; + } +#endif static EInitState getInitState() { #if LL_DARWIN - return (EInitState)(int)sInitState.get(); + return threadLocalInitState(); #else return sInitState; #endif @@ -229,7 +259,7 @@ private: static void setInitState(EInitState state) { #if LL_DARWIN - sInitState = (int*)state; + threadLocalInitState() = state; #else sInitState = state; #endif @@ -244,8 +274,8 @@ private: static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; #elif LL_DARWIN - static LLThreadLocalPointer sInstance; - static LLThreadLocalPointer sInitState; + //static pthread_key_t sInstanceKey; + //static pthread_key_t sInitStateKey; #endif }; @@ -262,11 +292,11 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; #elif LL_DARWIN -template -LLThreadLocalPointer LLThreadLocalSingleton::sInstance; +/*template +pthread_key_t LLThreadLocalSingleton::sInstanceKey; template -LLThreadLocalPointer LLThreadLocalSingleton::sInitState; +pthread_key_t LLThreadLocalSingleton::sInitStateKey;*/ #endif template -- cgit v1.2.3 From 670d03ceb83b92c9bb98d10bb37fba6f75971a2f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 15 Jan 2013 14:28:32 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed LLExtendableRecording to actually accumulator recording time period renamed and updated LLStopWatchControlsMixin::initTo to setPlayState --- indra/llcommon/lltracerecording.cpp | 42 ++++++++++++++++++++++--------------- indra/llcommon/lltracerecording.h | 21 +++++++++---------- 2 files changed, 35 insertions(+), 28 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index ddd25bfe87..f45226eb9a 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -60,7 +60,7 @@ Recording::Recording( const Recording& other ) mStackTimers = other.mStackTimers; mMemStats = other.mMemStats; - LLStopWatchControlsMixin::initTo(other.getPlayState()); + LLStopWatchControlsMixin::setPlayState(other.getPlayState()); } @@ -345,14 +345,14 @@ U32 Recording::getSampleCount( const TraceType >& st // PeriodicRecording /////////////////////////////////////////////////////////////////////// -PeriodicRecording::PeriodicRecording( S32 num_periods, EStopWatchState state) +PeriodicRecording::PeriodicRecording( S32 num_periods, EPlayState state) : mNumPeriods(num_periods), mCurPeriod(0), mTotalValid(false), mRecordingPeriods( new Recording[num_periods]) { llassert(mNumPeriods > 0); - initTo(state); + setPlayState(state); } PeriodicRecording::PeriodicRecording(PeriodicRecording& other) @@ -377,7 +377,7 @@ PeriodicRecording::~PeriodicRecording() void PeriodicRecording::nextPeriod() { - EStopWatchState play_state = getPlayState(); + EPlayState play_state = getPlayState(); Recording& old_recording = getCurRecordingPeriod(); mCurPeriod = (mCurPeriod + 1) % mNumPeriods; old_recording.splitTo(getCurRecordingPeriod()); @@ -458,8 +458,14 @@ void PeriodicRecording::splitFrom(PeriodicRecording& other) void ExtendableRecording::extend() { + // stop recording to get latest data + mPotentialRecording.stop(); + // push the data back to accepted recording mAcceptedRecording.appendRecording(mPotentialRecording); + // flush data, so we can start from scratch mPotentialRecording.reset(); + // go back to play state we were in initially + mPotentialRecording.setPlayState(getPlayState()); } void ExtendableRecording::start() @@ -514,7 +520,7 @@ PeriodicRecording& get_frame_recording() void LLStopWatchControlsMixinCommon::start() { - switch (mState) + switch (mPlayState) { case STOPPED: handleReset(); @@ -530,12 +536,12 @@ void LLStopWatchControlsMixinCommon::start() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::stop() { - switch (mState) + switch (mPlayState) { case STOPPED: break; @@ -549,12 +555,12 @@ void LLStopWatchControlsMixinCommon::stop() llassert(false); break; } - mState = STOPPED; + mPlayState = STOPPED; } void LLStopWatchControlsMixinCommon::pause() { - switch (mState) + switch (mPlayState) { case STOPPED: break; @@ -567,12 +573,12 @@ void LLStopWatchControlsMixinCommon::pause() llassert(false); break; } - mState = PAUSED; + mPlayState = PAUSED; } void LLStopWatchControlsMixinCommon::resume() { - switch (mState) + switch (mPlayState) { case STOPPED: handleStart(); @@ -586,12 +592,12 @@ void LLStopWatchControlsMixinCommon::resume() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::restart() { - switch (mState) + switch (mPlayState) { case STOPPED: handleReset(); @@ -608,7 +614,7 @@ void LLStopWatchControlsMixinCommon::restart() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::reset() @@ -616,21 +622,23 @@ void LLStopWatchControlsMixinCommon::reset() handleReset(); } -void LLStopWatchControlsMixinCommon::initTo( EStopWatchState state ) +void LLStopWatchControlsMixinCommon::setPlayState( EPlayState state ) { switch(state) { case STOPPED: + stop(); break; case PAUSED: + pause(); break; case STARTED: - handleStart(); + start(); break; default: llassert(false); break; } - mState = state; + mPlayState = state; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index aa3200e5ad..e6b5e85f90 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -39,7 +39,7 @@ class LLStopWatchControlsMixinCommon public: virtual ~LLStopWatchControlsMixinCommon() {} - enum EStopWatchState + enum EPlayState { STOPPED, PAUSED, @@ -53,19 +53,18 @@ public: virtual void restart(); virtual void reset(); - bool isStarted() const { return mState == STARTED; } - bool isPaused() const { return mState == PAUSED; } - bool isStopped() const { return mState == STOPPED; } - EStopWatchState getPlayState() const { return mState; } + bool isStarted() const { return mPlayState == STARTED; } + bool isPaused() const { return mPlayState == PAUSED; } + bool isStopped() const { return mPlayState == STOPPED; } + EPlayState getPlayState() const { return mPlayState; } + // force play state to specific value by calling appropriate handle* methods + void setPlayState(EPlayState state); protected: LLStopWatchControlsMixinCommon() - : mState(STOPPED) + : mPlayState(STOPPED) {} - // derived classes can call this from their copy constructor in order - // to duplicate play state of source - void initTo(EStopWatchState state); private: // trigger active behavior (without reset) virtual void handleStart(){}; @@ -74,7 +73,7 @@ private: // clear accumulated state, can be called while started virtual void handleReset(){}; - EStopWatchState mState; + EPlayState mPlayState; }; template @@ -245,7 +244,7 @@ namespace LLTrace : public LLStopWatchControlsMixin { public: - PeriodicRecording(S32 num_periods, EStopWatchState state = STOPPED); + PeriodicRecording(S32 num_periods, EPlayState state = STOPPED); PeriodicRecording(PeriodicRecording& recording); ~PeriodicRecording(); -- cgit v1.2.3 From a0413bdef71d804bbf008cf319f54a5a47efb29c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 17 Jan 2013 20:04:26 -0800 Subject: fix for mac thread local storage --- indra/llcommon/llthreadlocalstorage.h | 74 +++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 26 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index c8b7c5e229..fd44589299 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -152,7 +152,7 @@ public: virtual ~LLThreadLocalSingleton() { #if LL_DARWIN - //pthread_setspecific(sInstanceKey, NULL); + pthread_setspecific(sInstanceKey, NULL); #else sInstance = NULL; #endif @@ -182,17 +182,12 @@ public: setInitState(CONSTRUCTING); DERIVED_TYPE* instancep = new DERIVED_TYPE(); #if LL_DARWIN - /*static S32 sKeyCreated = pthread_key_create(&sInstanceKey, NULL); - if (sKeyCreated != 0) - { - llerrs << "Could not create thread local storage" << llendl; - } - + createTLSInstance(); S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); if (result != 0) { llerrs << "Could not set thread local storage" << llendl; - }*/ + } #else sInstance = instancep; #endif @@ -207,7 +202,7 @@ public: static DERIVED_TYPE* getIfExists() { #if LL_DARWIN - return NULL;//(DERIVED_TYPE*)pthread_getspecific(sInstanceKey); + return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -235,22 +230,29 @@ public: } private: #if LL_DARWIN - static EInitState& threadLocalInitState() + static void createTLSInitState() + { + static S32 key_created = pthread_key_create(&sInitStateKey, NULL); + if (key_created != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + } + + static void createTLSInstance() { - /*static S32 sKeyCreated = pthread_key_create(&sInitStateKey, NULL); - if (sKeyCreated != 0) + static S32 key_created = pthread_key_create(&sInstanceKey, NULL); + if (key_created != 0) { llerrs << "Could not create thread local storage" << llendl; } - return *(EInitState*)pthread_getspecific(sInitStateKey);*/ - static EInitState state; - return state; } #endif static EInitState getInitState() { #if LL_DARWIN - return threadLocalInitState(); + createTLSInitState(); + return (EInitState)(int)pthread_getspecific(sInitStateKey); #else return sInitState; #endif @@ -259,7 +261,8 @@ private: static void setInitState(EInitState state) { #if LL_DARWIN - threadLocalInitState() = state; + createTLSInitState(); + pthread_setspecific(sInitStateKey, (void*)state); #else sInitState = state; #endif @@ -274,8 +277,8 @@ private: static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; #elif LL_DARWIN - //static pthread_key_t sInstanceKey; - //static pthread_key_t sInitStateKey; + static pthread_key_t sInstanceKey; + static pthread_key_t sInitStateKey; #endif }; @@ -292,11 +295,12 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; #elif LL_DARWIN -/*template +template pthread_key_t LLThreadLocalSingleton::sInstanceKey; template -pthread_key_t LLThreadLocalSingleton::sInitStateKey;*/ +pthread_key_t LLThreadLocalSingleton::sInitStateKey; + #endif template @@ -305,13 +309,14 @@ class LLThreadLocalSingletonPointer public: void operator =(DERIVED_TYPE* value) { - sInstance = value; + setInstance(value); } - + LL_FORCE_INLINE static DERIVED_TYPE* getInstance() { #if LL_DARWIN - return sInstance.get(); + createTLSKey(); + return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -319,7 +324,12 @@ public: LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) { +#if LL_DARWIN + createTLSKey(); + pthread_setspecific(sInstanceKey, (void*)instance); +#else sInstance = instance; +#endif } private: @@ -328,7 +338,19 @@ private: #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; #elif LL_DARWIN - static LLThreadLocalPointer sInstance; + static void TLSError() + { + llerrs << "Could not create thread local storage" << llendl; + } + static void createTLSKey() + { + static S32 key_created = pthread_key_create(&sInstanceKey, NULL); + if (key_created != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + } + static pthread_key_t sInstanceKey; #endif }; @@ -340,7 +362,7 @@ template __thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; #elif LL_DARWIN template -LLThreadLocalPointer LLThreadLocalSingletonPointer::sInstance; +pthread_key_t LLThreadLocalSingletonPointer::sInstanceKey; #endif #endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3 From 43a92d01afdb4f1dd4003059b79f87e9687527a1 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 17 Jan 2013 20:11:43 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed some uninitialized variables root timer accumulator was being initialized to NULL --- indra/llcommon/llfasttimer.cpp | 30 +++++++++++++++++------------- indra/llcommon/llfasttimer.h | 11 ++++++----- indra/llcommon/lltracethreadrecorder.cpp | 6 ++++-- 3 files changed, 27 insertions(+), 20 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 37332da31c..b4a422816e 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -183,7 +183,6 @@ void TimeBlock::processTimes() { get_clock_count(); // good place to calculate clock frequency U64 cur_time = getCPUClockCount64(); - BlockTimerStackRecord* stack_record = ThreadTimerStack::getInstance(); // set up initial tree for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); @@ -202,6 +201,7 @@ void TimeBlock::processTimes() if (accumulator->mLastAccumulator) { TimeBlock* parent = accumulator->mLastAccumulator->mBlock; + llassert(parent); timer.setParent(parent); accumulator->mParent = parent; } @@ -250,26 +250,28 @@ void TimeBlock::processTimes() } // walk up stack of active timers and accumulate current time while leaving timing structures active - BlockTimer* cur_timer = stack_record->mActiveTimer; - TimeBlockAccumulator* accumulator = stack_record->mAccumulator; + BlockTimerStackRecord* stack_record = ThreadTimerStack::getInstance(); + BlockTimer* cur_timer = stack_record->mActiveTimer; + TimeBlockAccumulator* accumulator = stack_record->mAccumulator; + + llassert(accumulator); + // root defined by parent pointing to self - while(cur_timer && cur_timer->mLastTimerData.mActiveTimer != cur_timer) + while(cur_timer && cur_timer->mParentTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; + + accumulator->mTotalTimeCounter += cumulative_time_delta; accumulator->mChildTimeCounter += stack_record->mChildTime; stack_record->mChildTime = 0; - accumulator->mTotalTimeCounter += cumulative_time_delta; cur_timer->mStartTime = cur_time; - stack_record = &cur_timer->mLastTimerData; - stack_record->mChildTime += cumulative_time_delta; - if (stack_record->mAccumulator) - { - accumulator = stack_record->mAccumulator; - } + stack_record = &cur_timer->mParentTimerData; + accumulator = stack_record->mAccumulator; + cur_timer = stack_record->mActiveTimer; - cur_timer = cur_timer->mLastTimerData.mActiveTimer; + stack_record->mChildTime += cumulative_time_delta; } @@ -423,7 +425,8 @@ TimeBlockAccumulator::TimeBlockAccumulator() mLastAccumulator(NULL), mActiveCount(0), mMoveUpTree(false), - mParent(NULL) + mParent(NULL), + mBlock(NULL) {} void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) @@ -435,6 +438,7 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) mActiveCount = other.mActiveCount; mMoveUpTree = other.mMoveUpTree; mParent = other.mParent; + mBlock = other.mBlock; } void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 2d87629561..06de8ea6ee 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -74,7 +74,7 @@ public: private: U64 mStartTime; - BlockTimerStackRecord mLastTimerData; + BlockTimerStackRecord mParentTimerData; }; // stores a "named" timer instance to be reused via multiple BlockTimer stack instances @@ -280,10 +280,11 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; // keep current parent as long as it is active when we are + llassert(accumulator->mParent); accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); // store top of stack - mLastTimerData = *cur_timer_data; + mParentTimerData = *cur_timer_data; // push new information cur_timer_data->mActiveTimer = this; cur_timer_data->mAccumulator = accumulator; @@ -305,13 +306,13 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator->mLastAccumulator = mLastTimerData.mAccumulator; + accumulator->mLastAccumulator = mParentTimerData.mAccumulator; // we are only tracking self time, so subtract our total time delta from parents - mLastTimerData.mChildTime += total_time; + mParentTimerData.mChildTime += total_time; //pop stack - *cur_timer_data = mLastTimerData; + *cur_timer_data = mParentTimerData; #endif } diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index bc1d19e72c..7c5995a104 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -43,14 +43,16 @@ ThreadRecorder::ThreadRecorder() TimeBlock& root_time_block = TimeBlock::getRootTimeBlock(); ThreadTimerStack* timer_stack = ThreadTimerStack::getInstance(); - timer_stack->mAccumulator = root_time_block.getPrimaryAccumulator(); - timer_stack->mActiveTimer = NULL; mNumTimeBlockTreeNodes = AccumulatorBuffer::getDefaultBuffer()->size(); mTimeBlockTreeNodes = new TimeBlockTreeNode[mNumTimeBlockTreeNodes]; mThreadRecording.start(); + timer_stack->mAccumulator = root_time_block.getPrimaryAccumulator(); + timer_stack->mActiveTimer = NULL; + + // initialize time block parent pointers for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; -- cgit v1.2.3 From e975ae35ab57f56adfaed64bc108240a5013f040 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 18 Jan 2013 15:59:16 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed crash on startup --- indra/llcommon/llfasttimer.cpp | 26 ++++++++++---------------- indra/llcommon/llfasttimer.h | 15 +++++++-------- indra/llcommon/lltrace.h | 3 +-- indra/llcommon/lltracethreadrecorder.cpp | 10 +++------- 4 files changed, 21 insertions(+), 33 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index b4a422816e..ea4e1a89a2 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -198,12 +198,10 @@ void TimeBlock::processTimes() { TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - if (accumulator->mLastAccumulator) + if (accumulator->mLastCaller) { - TimeBlock* parent = accumulator->mLastAccumulator->mBlock; - llassert(parent); - timer.setParent(parent); - accumulator->mParent = parent; + timer.setParent(accumulator->mLastCaller); + accumulator->mParent = accumulator->mLastCaller; } // no need to push up tree on first use, flag can be set spuriously accumulator->mMoveUpTree = false; @@ -252,10 +250,8 @@ void TimeBlock::processTimes() // walk up stack of active timers and accumulate current time while leaving timing structures active BlockTimerStackRecord* stack_record = ThreadTimerStack::getInstance(); BlockTimer* cur_timer = stack_record->mActiveTimer; - TimeBlockAccumulator* accumulator = stack_record->mAccumulator; - - llassert(accumulator); - + TimeBlockAccumulator* accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); + // root defined by parent pointing to self while(cur_timer && cur_timer->mParentTimerData.mActiveTimer != cur_timer) { @@ -268,7 +264,7 @@ void TimeBlock::processTimes() cur_timer->mStartTime = cur_time; stack_record = &cur_timer->mParentTimerData; - accumulator = stack_record->mAccumulator; + accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); cur_timer = stack_record->mActiveTimer; stack_record->mChildTime += cumulative_time_delta; @@ -284,7 +280,7 @@ void TimeBlock::processTimes() TimeBlock& timer = *it; TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); - accumulator->mLastAccumulator = NULL; + accumulator->mLastCaller = NULL; accumulator->mMoveUpTree = false; } @@ -422,11 +418,10 @@ TimeBlockAccumulator::TimeBlockAccumulator() : mChildTimeCounter(0), mTotalTimeCounter(0), mCalls(0), - mLastAccumulator(NULL), + mLastCaller(NULL), mActiveCount(0), mMoveUpTree(false), - mParent(NULL), - mBlock(NULL) + mParent(NULL) {} void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) @@ -434,11 +429,10 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) mChildTimeCounter += other.mChildTimeCounter; mTotalTimeCounter += other.mTotalTimeCounter; mCalls += other.mCalls; - mLastAccumulator = other.mLastAccumulator; + mLastCaller = other.mLastCaller; mActiveCount = other.mActiveCount; mMoveUpTree = other.mMoveUpTree; mParent = other.mParent; - mBlock = other.mBlock; } void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 06de8ea6ee..726db70fbe 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -40,9 +40,9 @@ namespace LLTrace struct BlockTimerStackRecord { - class BlockTimer* mActiveTimer; - class TimeBlockAccumulator* mAccumulator; - U64 mChildTime; + class BlockTimer* mActiveTimer; + class TimeBlock* mTimeBlock; + U64 mChildTime; }; class ThreadTimerStack @@ -73,7 +73,7 @@ public: private: - U64 mStartTime; + U64 mStartTime; BlockTimerStackRecord mParentTimerData; }; @@ -280,14 +280,13 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; // keep current parent as long as it is active when we are - llassert(accumulator->mParent); accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); // store top of stack mParentTimerData = *cur_timer_data; // push new information cur_timer_data->mActiveTimer = this; - cur_timer_data->mAccumulator = accumulator; + cur_timer_data->mTimeBlock = &timer; cur_timer_data->mChildTime = 0; #endif } @@ -297,7 +296,7 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() #if FAST_TIMER_ON U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); - TimeBlockAccumulator* accumulator = cur_timer_data->mAccumulator; + TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); accumulator->mCalls++; accumulator->mChildTimeCounter += cur_timer_data->mChildTime; @@ -306,7 +305,7 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() // store last caller to bootstrap tree creation // do this in the destructor in case of recursion to get topmost caller - accumulator->mLastAccumulator = mParentTimerData.mAccumulator; + accumulator->mLastCaller = mParentTimerData.mTimeBlock; // we are only tracking self time, so subtract our total time delta from parents mParentTimerData.mChildTime += total_time; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 1d3c376a58..0f927bad53 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -449,9 +449,8 @@ namespace LLTrace U64 mChildTimeCounter, mTotalTimeCounter; U32 mCalls; - class TimeBlock* mBlock; // block associated with this accumulator class TimeBlock* mParent; // last acknowledged parent of this time block - TimeBlockAccumulator* mLastAccumulator; // used to bootstrap tree construction + class TimeBlock* mLastCaller; // used to bootstrap tree construction U16 mActiveCount; // number of timers with this ID active on stack bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 7c5995a104..7b493a651e 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -43,16 +43,14 @@ ThreadRecorder::ThreadRecorder() TimeBlock& root_time_block = TimeBlock::getRootTimeBlock(); ThreadTimerStack* timer_stack = ThreadTimerStack::getInstance(); + timer_stack->mTimeBlock = &root_time_block; + timer_stack->mActiveTimer = NULL; mNumTimeBlockTreeNodes = AccumulatorBuffer::getDefaultBuffer()->size(); mTimeBlockTreeNodes = new TimeBlockTreeNode[mNumTimeBlockTreeNodes]; mThreadRecording.start(); - timer_stack->mAccumulator = root_time_block.getPrimaryAccumulator(); - timer_stack->mActiveTimer = NULL; - - // initialize time block parent pointers for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); it != end_it; @@ -63,9 +61,7 @@ ThreadRecorder::ThreadRecorder() tree_node.mBlock = &time_block; tree_node.mParent = &root_time_block; - TimeBlockAccumulator* accumulator = it->getPrimaryAccumulator(); - accumulator->mParent = &root_time_block; - accumulator->mBlock = &time_block; + it->getPrimaryAccumulator()->mParent = &root_time_block; } mRootTimer = new BlockTimer(root_time_block); -- cgit v1.2.3 From 6fc355814f3dec7351fd629f4d263c46cfb0e160 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 22 Jan 2013 20:30:05 -0800 Subject: SH-3275 WIP Update viewer metrics system to be more flexible fix for mac unit tests failing --- indra/llcommon/llthreadlocalstorage.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index fd44589299..4873b2740d 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -177,12 +177,14 @@ public: llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; } +#if LL_DARWIN + createTLSInstance(); +#endif if (!getIfExists()) { setInitState(CONSTRUCTING); DERIVED_TYPE* instancep = new DERIVED_TYPE(); #if LL_DARWIN - createTLSInstance(); S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); if (result != 0) { -- cgit v1.2.3 From 3a555a2ff84d9b340e33673d7a03f37c966f06e6 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 24 Jan 2013 19:53:17 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible removed LLFastTimerView::getFrameTimer() dead code elimination fixed off by one array access crash --- indra/llcommon/llfasttimer.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index ea4e1a89a2..a144a8c94e 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -270,7 +270,6 @@ void TimeBlock::processTimes() stack_record->mChildTime += cumulative_time_delta; } - // reset for next frame for (LLInstanceTracker::instance_iter it = LLInstanceTracker::beginInstances(), end_it = LLInstanceTracker::endInstances(); @@ -283,20 +282,6 @@ void TimeBlock::processTimes() accumulator->mLastCaller = NULL; accumulator->mMoveUpTree = false; } - - // traverse tree in DFS post order, or bottom up - //for(timer_tree_bottom_up_iterator_t it = begin_timer_tree_bottom_up(TimeBlock::getRootTimer()); - // it != end_timer_tree_bottom_up(); - // ++it) - //{ - // TimeBlock* timerp = (*it); - // TimeBlockAccumulator& accumulator = timerp->getPrimaryAccumulator(); - // timerp->mTreeTimeCounter = accumulator.mSelfTimeCounter; - // for (child_const_iter child_it = timerp->beginChildren(); child_it != timerp->endChildren(); ++child_it) - // { - // timerp->mTreeTimeCounter += (*child_it)->mTreeTimeCounter; - // } - //} } -- cgit v1.2.3 From 09ee16c61d372c1eb620bc3ef3dbfeb798c0a82e Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 25 Jan 2013 16:15:19 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible fix for extendablerecording not having right state --- indra/llcommon/lltracerecording.cpp | 8 ++++++++ indra/llcommon/lltracerecording.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index f45226eb9a..913c4cbdad 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -470,43 +470,51 @@ void ExtendableRecording::extend() void ExtendableRecording::start() { + LLStopWatchControlsMixin::start(); mPotentialRecording.start(); } void ExtendableRecording::stop() { + LLStopWatchControlsMixin::stop(); mPotentialRecording.stop(); } void ExtendableRecording::pause() { + LLStopWatchControlsMixin::pause(); mPotentialRecording.pause(); } void ExtendableRecording::resume() { + LLStopWatchControlsMixin::resume(); mPotentialRecording.resume(); } void ExtendableRecording::restart() { + LLStopWatchControlsMixin::restart(); mAcceptedRecording.reset(); mPotentialRecording.restart(); } void ExtendableRecording::reset() { + LLStopWatchControlsMixin::reset(); mAcceptedRecording.reset(); mPotentialRecording.reset(); } void ExtendableRecording::splitTo(ExtendableRecording& other) { + LLStopWatchControlsMixin::splitTo(other); mPotentialRecording.splitTo(other.mPotentialRecording); } void ExtendableRecording::splitFrom(ExtendableRecording& other) { + LLStopWatchControlsMixin::splitFrom(other); mPotentialRecording.splitFrom(other.mPotentialRecording); } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index e6b5e85f90..f575fbd8b2 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -389,7 +389,9 @@ namespace LLTrace class ExtendableRecording : public LLStopWatchControlsMixin { + public: void extend(); + Recording& getAcceptedRecording() { return mAcceptedRecording; } // implementation for LLStopWatchControlsMixin /*virtual*/ void start(); -- cgit v1.2.3 From 2c68d5367c5c44aceb4ff23d9672c35642e030f7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 27 Jan 2013 21:35:20 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible fixed memory leak fixed glitching of fast timer display --- indra/llcommon/llfasttimer.cpp | 7 +++++++ indra/llcommon/lltrace.h | 18 +++++++++++++---- indra/llcommon/lltracerecording.cpp | 10 ++++++++++ indra/llcommon/lltracerecording.h | 11 +++++++---- indra/llcommon/lltracethreadrecorder.cpp | 33 +++++++++++++++++++------------- indra/llcommon/lltracethreadrecorder.h | 12 +++++++----- 6 files changed, 65 insertions(+), 26 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index a144a8c94e..e58c5c0f98 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -425,6 +425,13 @@ void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) mTotalTimeCounter = 0; mChildTimeCounter = 0; mCalls = 0; + if (other) + { + mLastCaller = other->mLastCaller; + mActiveCount = other->mActiveCount; + mMoveUpTree = other->mMoveUpTree; + mParent = other->mParent; + } } } // namespace LLTrace diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 0f927bad53..c38e92962b 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -243,8 +243,6 @@ namespace LLTrace : public LLInstanceTracker, std::string> { public: - typedef typename MeanValueType >::type mean_t; - TraceType(const char* name, const char* description = NULL) : LLInstanceTracker, std::string>(name), mName(name), @@ -468,25 +466,37 @@ namespace LLTrace : public TraceType { public: - typedef F32 mean_t; TraceType(const char* name, const char* description = "") : TraceType(name, description) {} }; + template<> + struct MeanValueType > + { + typedef F64 type; + }; + + template<> class TraceType : public TraceType { public: - typedef F32 mean_t; TraceType(const char* name, const char* description = "") : TraceType(name, description) {} }; + template<> + struct MeanValueType > + { + typedef LLUnit type; + }; + + class TimeBlock; class TimeBlockTreeNode { diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 913c4cbdad..737b95cdd5 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -109,8 +109,18 @@ void Recording::handleSplitTo(Recording& other) { stop(); other.restart(); + syncTo(other); +} + +void Recording::syncTo(Recording& other) +{ + other.mCountsFloat.write()->reset(mCountsFloat); other.mMeasurementsFloat.write()->reset(mMeasurementsFloat); + other.mCounts.write()->reset(mCounts); other.mMeasurements.write()->reset(mMeasurements); + other.mStackTimers.write()->reset(mStackTimers); + other.mMemStats.write()->reset(mMemStats); + //TODO: figure out how to get seamless handoff of timing stats } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index f575fbd8b2..af9ba02b29 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -119,6 +119,7 @@ namespace LLTrace // gather data from recording, ignoring time relationship (for example, pulling data from slave threads) void mergeRecording(const Recording& other); + // grab latest recorded data void update(); // Timer accessors @@ -217,6 +218,8 @@ namespace LLTrace LLUnit getDuration() const { return LLUnit(mElapsedSeconds); } + void syncTo(Recording& other); + private: friend class ThreadRecorder; @@ -337,9 +340,9 @@ namespace LLTrace } template - typename TraceType::mean_t getPeriodMean(const TraceType& stat) const + typename MeanValueType >::type getPeriodMean(const TraceType& stat) const { - typename TraceType::mean_t mean = 0.0; + typename MeanValueType >::type mean = 0.0; for (S32 i = 0; i < mNumPeriods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) @@ -352,9 +355,9 @@ namespace LLTrace } template - typename TraceType::mean_t getPeriodMeanPerSec(const TraceType& stat) const + typename MeanValueType >::type getPeriodMeanPerSec(const TraceType& stat) const { - typename TraceType::mean_t mean = 0.0; + typename MeanValueType >::type mean = 0.0; for (S32 i = 0; i < mNumPeriods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 7b493a651e..113febcca8 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -76,7 +76,7 @@ ThreadRecorder::~ThreadRecorder() while(mActiveRecordings.size()) { - mActiveRecordings.front().mTargetRecording->stop(); + mActiveRecordings.front()->mTargetRecording->stop(); } set_thread_recorder(NULL); delete[] mTimeBlockTreeNodes; @@ -94,31 +94,37 @@ TimeBlockTreeNode* ThreadRecorder::getTimeBlockTreeNode(S32 index) void ThreadRecorder::activate( Recording* recording ) { - mActiveRecordings.push_front(ActiveRecording(recording)); - mActiveRecordings.front().mBaseline.makePrimary(); + ActiveRecording* active_recording = new ActiveRecording(recording); + if (!mActiveRecordings.empty()) + { + mActiveRecordings.front()->mBaseline.syncTo(active_recording->mBaseline); + } + mActiveRecordings.push_front(active_recording); + + mActiveRecordings.front()->mBaseline.makePrimary(); } -std::list::iterator ThreadRecorder::update( Recording* recording ) +ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::update( Recording* recording ) { - std::list::iterator it, end_it; + active_recording_list_t::iterator it, end_it; for (it = mActiveRecordings.begin(), end_it = mActiveRecordings.end(); it != end_it; ++it) { - std::list::iterator next_it = it; + active_recording_list_t::iterator next_it = it; ++next_it; // if we have another recording further down in the stack... if (next_it != mActiveRecordings.end()) { // ...push our gathered data down to it - next_it->mBaseline.appendRecording(it->mBaseline); + (*next_it)->mBaseline.appendRecording((*it)->mBaseline); } // copy accumulated measurements into result buffer and clear accumulator (mBaseline) - it->moveBaselineToTarget(); + (*it)->moveBaselineToTarget(); - if (it->mTargetRecording == recording) + if ((*it)->mTargetRecording == recording) { // found the recording, so return it break; @@ -142,17 +148,18 @@ AccumulatorBuffer gMemStats; void ThreadRecorder::deactivate( Recording* recording ) { - std::list::iterator it = update(recording); + active_recording_list_t::iterator it = update(recording); if (it != mActiveRecordings.end()) { // and if we've found the recording we wanted to update - std::list::iterator next_it = it; + active_recording_list_t::iterator next_it = it; ++next_it; if (next_it != mActiveRecordings.end()) { - next_it->mTargetRecording->makePrimary(); + (*next_it)->mTargetRecording->makePrimary(); } + delete *it; mActiveRecordings.erase(it); } } @@ -244,7 +251,7 @@ void MasterThreadRecorder::pullFromSlaveThreads() LLMutexLock lock(&mSlaveListMutex); - Recording& target_recording = mActiveRecordings.front().mBaseline; + Recording& target_recording = mActiveRecordings.front()->mBaseline; for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 337035974c..0e6c091900 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -39,13 +39,14 @@ namespace LLTrace { protected: struct ActiveRecording; + typedef std::list active_recording_list_t; public: ThreadRecorder(); virtual ~ThreadRecorder(); void activate(Recording* recording); - std::list::iterator update(Recording* recording); + active_recording_list_t::iterator update(Recording* recording); void deactivate(Recording* recording); virtual void pushToMaster() = 0; @@ -63,11 +64,12 @@ namespace LLTrace void moveBaselineToTarget(); }; Recording mThreadRecording; - std::list mActiveRecordings; - class BlockTimer* mRootTimer; - TimeBlockTreeNode* mTimeBlockTreeNodes; - size_t mNumTimeBlockTreeNodes; + active_recording_list_t mActiveRecordings; + + class BlockTimer* mRootTimer; + TimeBlockTreeNode* mTimeBlockTreeNodes; + size_t mNumTimeBlockTreeNodes; }; class LL_COMMON_API MasterThreadRecorder : public ThreadRecorder -- cgit v1.2.3 From eb6c8959ca5b8b3c100114d4d659a48bb4d56b2c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 2 Feb 2013 01:09:52 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible fixed most fast timer display and interaction issues --- indra/llcommon/lltracerecording.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 737b95cdd5..29604f7155 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -530,7 +530,7 @@ void ExtendableRecording::splitFrom(ExtendableRecording& other) PeriodicRecording& get_frame_recording() { - static LLThreadLocalPointer sRecording(new PeriodicRecording(64, PeriodicRecording::STARTED)); + static LLThreadLocalPointer sRecording(new PeriodicRecording(200, PeriodicRecording::STARTED)); return *sRecording; } -- cgit v1.2.3 From 438cbfe489cc34261ac600bbb22983164e59b1d9 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 7 Feb 2013 20:07:31 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible fix for timings for recursive fast timers not being correct --- indra/llcommon/llfasttimer.cpp | 10 +++++----- indra/llcommon/llfasttimer.h | 14 ++++++++++++-- indra/llcommon/lltrace.h | 2 +- indra/llcommon/lltracerecording.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 12 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e58c5c0f98..809a0ef4bf 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -257,8 +257,8 @@ void TimeBlock::processTimes() { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - accumulator->mTotalTimeCounter += cumulative_time_delta; - accumulator->mChildTimeCounter += stack_record->mChildTime; + accumulator->mChildTimeCounter += stack_record->mChildTime - (accumulator->mSelfTimeCounter - cur_timer->mStartSelfTimeCount); + accumulator->mSelfTimeCounter += cumulative_time_delta - stack_record->mChildTime; stack_record->mChildTime = 0; cur_timer->mStartTime = cur_time; @@ -401,7 +401,7 @@ void TimeBlock::writeLog(std::ostream& os) TimeBlockAccumulator::TimeBlockAccumulator() : mChildTimeCounter(0), - mTotalTimeCounter(0), + mSelfTimeCounter(0), mCalls(0), mLastCaller(NULL), mActiveCount(0), @@ -412,7 +412,7 @@ TimeBlockAccumulator::TimeBlockAccumulator() void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) { mChildTimeCounter += other.mChildTimeCounter; - mTotalTimeCounter += other.mTotalTimeCounter; + mSelfTimeCounter += other.mSelfTimeCounter; mCalls += other.mCalls; mLastCaller = other.mLastCaller; mActiveCount = other.mActiveCount; @@ -422,7 +422,7 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) { - mTotalTimeCounter = 0; + mSelfTimeCounter = 0; mChildTimeCounter = 0; mCalls = 0; if (other) diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 726db70fbe..9402bb7267 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -71,9 +71,12 @@ public: BlockTimer(TimeBlock& timer); ~BlockTimer(); + void logCurrentTime(); + private: U64 mStartTime; + U64 mStartSelfTimeCount; BlockTimerStackRecord mParentTimerData; }; @@ -279,6 +282,7 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; + mStartSelfTimeCount = accumulator->mSelfTimeCounter; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -298,9 +302,10 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); + U64 child_time = cur_timer_data->mChildTime - (accumulator->mSelfTimeCounter - mStartSelfTimeCount); accumulator->mCalls++; - accumulator->mChildTimeCounter += cur_timer_data->mChildTime; - accumulator->mTotalTimeCounter += total_time; + accumulator->mChildTimeCounter += child_time; + accumulator->mSelfTimeCounter += total_time - child_time; accumulator->mActiveCount--; // store last caller to bootstrap tree creation @@ -315,6 +320,11 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() #endif } +inline void BlockTimer::logCurrentTime() +{ + U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; + llinfos << "Time elapsed: " << (1000.0 * (F64)total_time / (F64)TimeBlock::countsPerSecond()) << llendl; +} } typedef LLTrace::BlockTimer LLFastTimer; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index c38e92962b..9eadd8a2be 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -445,7 +445,7 @@ namespace LLTrace // members // U64 mChildTimeCounter, - mTotalTimeCounter; + mSelfTimeCounter; U32 mCalls; class TimeBlock* mParent; // last acknowledged parent of this time block class TimeBlock* mLastCaller; // used to bootstrap tree construction diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 29604f7155..69085ddcc2 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -184,12 +184,12 @@ void Recording::mergeRecording( const Recording& other) LLUnit Recording::getSum(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); + return ((F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter + (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); } LLUnit Recording::getSum(const TraceType& stat) const { - return ((F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter - (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); } @@ -200,12 +200,12 @@ U32 Recording::getSum(const TraceType& st LLUnit Recording::getPerSec(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); + return ((F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter + (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } LLUnit Recording::getPerSec(const TraceType& stat) const { - return ((F64)(*mStackTimers)[stat.getIndex()].mTotalTimeCounter - (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); + return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } F32 Recording::getPerSec(const TraceType& stat) const -- cgit v1.2.3 From e3700112f313f3570887047d5b56a661af0afac5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 8 Feb 2013 00:03:31 -0800 Subject: SH-3275 WIP interesting Update viewer metrics system to be more flexible added debug output to BlockTimer --- indra/llcommon/llfasttimer.cpp | 8 ++++++++ indra/llcommon/llfasttimer.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index e58c5c0f98..ba626bcc32 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -434,4 +434,12 @@ void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) } } +LLUnit BlockTimer::getElapsedTime() +{ + U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; + + return (F64)total_time / (F64)TimeBlock::countsPerSecond(); +} + + } // namespace LLTrace diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 726db70fbe..edbcb896b3 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -71,6 +71,8 @@ public: BlockTimer(TimeBlock& timer); ~BlockTimer(); + LLUnit getElapsedTime(); + private: U64 mStartTime; -- cgit v1.2.3 From 2e15e8fd4ba62204c76f6e2a91d3e50f62e6c1fc Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 9 Feb 2013 00:34:59 -0800 Subject: SH-3275 FIX interesting Update viewer metrics system to be more flexible fixed anamolous LLFastTimer timings --- indra/llcommon/llfasttimer.cpp | 28 +++++++++++++++++++++------- indra/llcommon/llfasttimer.h | 17 ++++++++--------- indra/llcommon/lltrace.h | 4 +++- indra/llcommon/lltracerecording.cpp | 19 +++++++++++++------ 4 files changed, 45 insertions(+), 23 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 4387218f5a..0ea91d7e51 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -256,12 +256,16 @@ void TimeBlock::processTimes() while(cur_timer && cur_timer->mParentTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - - accumulator->mChildTimeCounter += stack_record->mChildTime - (accumulator->mSelfTimeCounter - cur_timer->mStartSelfTimeCount); - accumulator->mSelfTimeCounter += cumulative_time_delta - stack_record->mChildTime; + U64 child_time = stack_record->mChildTime + - (accumulator->mSelfTimeCounter - cur_timer->mStartSelfTimeCounter) + - (accumulator->mChildTimeCounter - cur_timer->mStartChildTimeCounter); + accumulator->mChildTimeCounter += child_time; + accumulator->mSelfTimeCounter += cumulative_time_delta - child_time; stack_record->mChildTime = 0; cur_timer->mStartTime = cur_time; + cur_timer->mStartSelfTimeCounter = accumulator->mSelfTimeCounter; + cur_timer->mStartChildTimeCounter = accumulator->mChildTimeCounter; stack_record = &cur_timer->mParentTimerData; accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); @@ -402,6 +406,8 @@ void TimeBlock::writeLog(std::ostream& os) TimeBlockAccumulator::TimeBlockAccumulator() : mChildTimeCounter(0), mSelfTimeCounter(0), + mStartChildTimeCounter(0), + mStartSelfTimeCounter(0), mCalls(0), mLastCaller(NULL), mActiveCount(0), @@ -411,8 +417,8 @@ TimeBlockAccumulator::TimeBlockAccumulator() void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) { - mChildTimeCounter += other.mChildTimeCounter; - mSelfTimeCounter += other.mSelfTimeCounter; + mChildTimeCounter += other.mChildTimeCounter - other.mStartChildTimeCounter; + mSelfTimeCounter += other.mSelfTimeCounter - other.mStartSelfTimeCounter; mCalls += other.mCalls; mLastCaller = other.mLastCaller; mActiveCount = other.mActiveCount; @@ -422,16 +428,24 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) { - mSelfTimeCounter = 0; - mChildTimeCounter = 0; mCalls = 0; if (other) { + mStartSelfTimeCounter = other->mSelfTimeCounter; + mSelfTimeCounter = mStartSelfTimeCounter; + mStartChildTimeCounter = other->mChildTimeCounter; + mChildTimeCounter = mStartChildTimeCounter; + mLastCaller = other->mLastCaller; mActiveCount = other->mActiveCount; mMoveUpTree = other->mMoveUpTree; mParent = other->mParent; } + else + { + mStartSelfTimeCounter = mSelfTimeCounter; + mStartChildTimeCounter = mChildTimeCounter; + } } LLUnit BlockTimer::getElapsedTime() diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 2994b35e58..28e54a37de 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -76,7 +76,8 @@ public: private: U64 mStartTime; - U64 mStartSelfTimeCount; + U64 mStartSelfTimeCounter; + U64 mStartChildTimeCounter; BlockTimerStackRecord mParentTimerData; }; @@ -282,7 +283,8 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; - mStartSelfTimeCount = accumulator->mSelfTimeCounter; + mStartSelfTimeCounter = accumulator->mSelfTimeCounter; + mStartChildTimeCounter = accumulator->mChildTimeCounter; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -302,10 +304,12 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); - U64 child_time = cur_timer_data->mChildTime - (accumulator->mSelfTimeCounter - mStartSelfTimeCount); + U64 child_time = cur_timer_data->mChildTime + - (accumulator->mSelfTimeCounter - mStartSelfTimeCounter) + - (accumulator->mChildTimeCounter - mStartChildTimeCounter); accumulator->mCalls++; accumulator->mChildTimeCounter += child_time; - accumulator->mSelfTimeCounter += total_time - child_time; + accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator->mActiveCount--; // store last caller to bootstrap tree creation @@ -320,11 +324,6 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() #endif } -inline void BlockTimer::logCurrentTime() -{ - U64 total_time = TimeBlock::getCPUClockCount64() - mStartTime; - llinfos << "Time elapsed: " << (1000.0 * (F64)total_time / (F64)TimeBlock::countsPerSecond()) << llendl; -} } typedef LLTrace::BlockTimer LLFastTimer; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 9eadd8a2be..8c3259eea9 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -444,7 +444,9 @@ namespace LLTrace // // members // - U64 mChildTimeCounter, + U64 mStartChildTimeCounter, + mStartSelfTimeCounter, + mChildTimeCounter, mSelfTimeCounter; U32 mCalls; class TimeBlock* mParent; // last acknowledged parent of this time block diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 69085ddcc2..2af9041863 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -120,8 +120,6 @@ void Recording::syncTo(Recording& other) other.mMeasurements.write()->reset(mMeasurements); other.mStackTimers.write()->reset(mStackTimers); other.mMemStats.write()->reset(mMemStats); - - //TODO: figure out how to get seamless handoff of timing stats } void Recording::makePrimary() @@ -184,12 +182,15 @@ void Recording::mergeRecording( const Recording& other) LLUnit Recording::getSum(const TraceType& stat) const { - return ((F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter + (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); + const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; + return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter + accumulator.mChildTimeCounter - accumulator.mStartChildTimeCounter) + / (F64)LLTrace::TimeBlock::countsPerSecond(); } LLUnit Recording::getSum(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / (F64)LLTrace::TimeBlock::countsPerSecond(); + const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; + return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); } @@ -200,12 +201,18 @@ U32 Recording::getSum(const TraceType& st LLUnit Recording::getPerSec(const TraceType& stat) const { - return ((F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter + (F64)(*mStackTimers)[stat.getIndex()].mChildTimeCounter) / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); + const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; + + return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter + accumulator.mChildTimeCounter - accumulator.mStartChildTimeCounter) + / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } LLUnit Recording::getPerSec(const TraceType& stat) const { - return (F64)(*mStackTimers)[stat.getIndex()].mSelfTimeCounter / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); + const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; + + return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter) + / ((F64)LLTrace::TimeBlock::countsPerSecond() * mElapsedSeconds); } F32 Recording::getPerSec(const TraceType& stat) const -- cgit v1.2.3 From 67ac6e7a294bd7401c55ed1d7423166dda1c0ee6 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 10 Feb 2013 23:53:45 -0800 Subject: SH-3275 FIX interesting Update viewer metrics system to be more flexible streamlined fast timer delta tracking --- indra/llcommon/llfasttimer.cpp | 30 ++++++++++++------------------ indra/llcommon/llfasttimer.h | 11 +++-------- indra/llcommon/lltrace.h | 5 ++--- indra/llcommon/lltracerecording.cpp | 8 ++++---- 4 files changed, 21 insertions(+), 33 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 0ea91d7e51..f8837a7085 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -256,16 +256,12 @@ void TimeBlock::processTimes() while(cur_timer && cur_timer->mParentTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - U64 child_time = stack_record->mChildTime - - (accumulator->mSelfTimeCounter - cur_timer->mStartSelfTimeCounter) - - (accumulator->mChildTimeCounter - cur_timer->mStartChildTimeCounter); - accumulator->mChildTimeCounter += child_time; - accumulator->mSelfTimeCounter += cumulative_time_delta - child_time; + accumulator->mTotalTimeCounter += cumulative_time_delta - (accumulator->mTotalTimeCounter - accumulator->mStartTotalTimeCounter); + accumulator->mSelfTimeCounter += cumulative_time_delta - stack_record->mChildTime; stack_record->mChildTime = 0; cur_timer->mStartTime = cur_time; - cur_timer->mStartSelfTimeCounter = accumulator->mSelfTimeCounter; - cur_timer->mStartChildTimeCounter = accumulator->mChildTimeCounter; + cur_timer->mStartTotalTimeCounter = accumulator->mTotalTimeCounter; stack_record = &cur_timer->mParentTimerData; accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); @@ -404,10 +400,9 @@ void TimeBlock::writeLog(std::ostream& os) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TimeBlockAccumulator::TimeBlockAccumulator() -: mChildTimeCounter(0), +: mTotalTimeCounter(0), mSelfTimeCounter(0), - mStartChildTimeCounter(0), - mStartSelfTimeCounter(0), + mStartTotalTimeCounter(0), mCalls(0), mLastCaller(NULL), mActiveCount(0), @@ -417,8 +412,8 @@ TimeBlockAccumulator::TimeBlockAccumulator() void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) { - mChildTimeCounter += other.mChildTimeCounter - other.mStartChildTimeCounter; - mSelfTimeCounter += other.mSelfTimeCounter - other.mStartSelfTimeCounter; + mTotalTimeCounter += other.mTotalTimeCounter - other.mStartTotalTimeCounter; + mSelfTimeCounter += other.mSelfTimeCounter; mCalls += other.mCalls; mLastCaller = other.mLastCaller; mActiveCount = other.mActiveCount; @@ -429,12 +424,12 @@ void TimeBlockAccumulator::addSamples( const TimeBlockAccumulator& other ) void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) { mCalls = 0; + mSelfTimeCounter = 0; + if (other) { - mStartSelfTimeCounter = other->mSelfTimeCounter; - mSelfTimeCounter = mStartSelfTimeCounter; - mStartChildTimeCounter = other->mChildTimeCounter; - mChildTimeCounter = mStartChildTimeCounter; + mStartTotalTimeCounter = other->mTotalTimeCounter; + mTotalTimeCounter = mStartTotalTimeCounter; mLastCaller = other->mLastCaller; mActiveCount = other->mActiveCount; @@ -443,8 +438,7 @@ void TimeBlockAccumulator::reset( const TimeBlockAccumulator* other ) } else { - mStartSelfTimeCounter = mSelfTimeCounter; - mStartChildTimeCounter = mChildTimeCounter; + mStartTotalTimeCounter = mTotalTimeCounter; } } diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 28e54a37de..ec1720d2df 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -76,8 +76,7 @@ public: private: U64 mStartTime; - U64 mStartSelfTimeCounter; - U64 mStartChildTimeCounter; + U64 mStartTotalTimeCounter; BlockTimerStackRecord mParentTimerData; }; @@ -283,8 +282,7 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; - mStartSelfTimeCounter = accumulator->mSelfTimeCounter; - mStartChildTimeCounter = accumulator->mChildTimeCounter; + mStartTotalTimeCounter = accumulator->mTotalTimeCounter; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -304,11 +302,8 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); - U64 child_time = cur_timer_data->mChildTime - - (accumulator->mSelfTimeCounter - mStartSelfTimeCounter) - - (accumulator->mChildTimeCounter - mStartChildTimeCounter); accumulator->mCalls++; - accumulator->mChildTimeCounter += child_time; + accumulator->mTotalTimeCounter += total_time - (accumulator->mTotalTimeCounter - mStartTotalTimeCounter); accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator->mActiveCount--; diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 8c3259eea9..5d57327a14 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -444,9 +444,8 @@ namespace LLTrace // // members // - U64 mStartChildTimeCounter, - mStartSelfTimeCounter, - mChildTimeCounter, + U64 mStartTotalTimeCounter, + mTotalTimeCounter, mSelfTimeCounter; U32 mCalls; class TimeBlock* mParent; // last acknowledged parent of this time block diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 2af9041863..ab8dbce2ce 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -183,14 +183,14 @@ void Recording::mergeRecording( const Recording& other) LLUnit Recording::getSum(const TraceType& stat) const { const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; - return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter + accumulator.mChildTimeCounter - accumulator.mStartChildTimeCounter) + return (F64)(accumulator.mTotalTimeCounter - accumulator.mStartTotalTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); } LLUnit Recording::getSum(const TraceType& stat) const { const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; - return (F64)(accumulator.mSelfTimeCounter - accumulator.mStartSelfTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); + return (F64)(accumulator.mSelfTimeCounter) / (F64)LLTrace::TimeBlock::countsPerSecond(); } @@ -203,7 +203,7 @@ LLUnit Recording::getPerSec(const TraceType Recording::getPerSec(const TraceType Date: Wed, 13 Feb 2013 15:21:20 -0800 Subject: SH-3275 FIX interesting Update viewer metrics system to be more flexible fix for inaccurate optimization of full block time calculations --- indra/llcommon/llfasttimer.cpp | 6 +++--- indra/llcommon/llfasttimer.h | 6 +++--- indra/llcommon/llunit.h | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index f8837a7085..5baf049c03 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -256,12 +256,12 @@ void TimeBlock::processTimes() while(cur_timer && cur_timer->mParentTimerData.mActiveTimer != cur_timer) { U64 cumulative_time_delta = cur_time - cur_timer->mStartTime; - accumulator->mTotalTimeCounter += cumulative_time_delta - (accumulator->mTotalTimeCounter - accumulator->mStartTotalTimeCounter); + accumulator->mTotalTimeCounter += cumulative_time_delta - (accumulator->mTotalTimeCounter - cur_timer->mBlockStartTotalTimeCounter); accumulator->mSelfTimeCounter += cumulative_time_delta - stack_record->mChildTime; stack_record->mChildTime = 0; cur_timer->mStartTime = cur_time; - cur_timer->mStartTotalTimeCounter = accumulator->mTotalTimeCounter; + cur_timer->mBlockStartTotalTimeCounter = accumulator->mTotalTimeCounter; stack_record = &cur_timer->mParentTimerData; accumulator = stack_record->mTimeBlock->getPrimaryAccumulator(); @@ -376,7 +376,7 @@ void TimeBlock::dumpCurTimes() } out_str << timerp->getName() << " " - << std::setprecision(3) << total_time_ms.as().value() << " ms, " + << std::setprecision(3) << total_time_ms.as().value() << " ms, " << num_calls << " calls"; llinfos << out_str.str() << llendl; diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index ec1720d2df..32a0629a87 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -76,7 +76,7 @@ public: private: U64 mStartTime; - U64 mStartTotalTimeCounter; + U64 mBlockStartTotalTimeCounter; BlockTimerStackRecord mParentTimerData; }; @@ -282,7 +282,7 @@ LL_FORCE_INLINE BlockTimer::BlockTimer(TimeBlock& timer) BlockTimerStackRecord* cur_timer_data = ThreadTimerStack::getIfExists(); TimeBlockAccumulator* accumulator = timer.getPrimaryAccumulator(); accumulator->mActiveCount++; - mStartTotalTimeCounter = accumulator->mTotalTimeCounter; + mBlockStartTotalTimeCounter = accumulator->mTotalTimeCounter; // keep current parent as long as it is active when we are accumulator->mMoveUpTree |= (accumulator->mParent->getPrimaryAccumulator()->mActiveCount == 0); @@ -303,7 +303,7 @@ LL_FORCE_INLINE BlockTimer::~BlockTimer() TimeBlockAccumulator* accumulator = cur_timer_data->mTimeBlock->getPrimaryAccumulator(); accumulator->mCalls++; - accumulator->mTotalTimeCounter += total_time - (accumulator->mTotalTimeCounter - mStartTotalTimeCounter); + accumulator->mTotalTimeCounter += total_time - (accumulator->mTotalTimeCounter - mBlockStartTotalTimeCounter); accumulator->mSelfTimeCounter += total_time - cur_timer_data->mChildTime; accumulator->mActiveCount--; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index c2a31b7604..823550db5d 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -106,11 +106,12 @@ struct LLUnit return mValue; } - template LLUnit as() + template LLUnit as() { - return LLUnit(*this); + return LLUnit(*this); } + void operator += (storage_t value) { mValue += value; -- cgit v1.2.3 From f07b9c2c69f1f6882dcf249aacf33cdfacf878ab Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 6 Mar 2013 11:08:25 -0800 Subject: renamed LLTrace stat gathering classes/methods to make the structure of LLTrace clearer Count becomes CountStatHandle Count.sum becomes sum(Count, value), etc. --- indra/llcommon/lltrace.h | 832 +++++++++++++++++++------------------- indra/llcommon/lltracerecording.h | 23 +- 2 files changed, 429 insertions(+), 426 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 5d57327a14..44da1939c6 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -42,517 +42,519 @@ namespace LLTrace { - class Recording; - - typedef LLUnit Bytes; - typedef LLUnit Kilobytes; - typedef LLUnit Megabytes; - typedef LLUnit Gigabytes; - typedef LLUnit Bits; - typedef LLUnit Kilobits; - typedef LLUnit Megabits; - typedef LLUnit Gigabits; - - typedef LLUnit Seconds; - typedef LLUnit Milliseconds; - typedef LLUnit Minutes; - typedef LLUnit Hours; - typedef LLUnit Milliseconds; - typedef LLUnit Microseconds; - typedef LLUnit Nanoseconds; - - typedef LLUnit Meters; - typedef LLUnit Kilometers; - typedef LLUnit Centimeters; - typedef LLUnit Millimeters; - - void init(); - void cleanup(); - bool isInitialized(); - - const LLThreadLocalPointer& get_thread_recorder(); - void set_thread_recorder(class ThreadRecorder*); - - class MasterThreadRecorder& getMasterThreadRecorder(); - - // one per thread per type - template - class AccumulatorBuffer : public LLRefCount - { - typedef AccumulatorBuffer self_t; - static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; - private: - struct StaticAllocationMarker { }; - - AccumulatorBuffer(StaticAllocationMarker m) - : mStorageSize(0), - mStorage(NULL), - mNextStorageSlot(0) - { - } +class Recording; + +typedef LLUnit Bytes; +typedef LLUnit Kilobytes; +typedef LLUnit Megabytes; +typedef LLUnit Gigabytes; +typedef LLUnit Bits; +typedef LLUnit Kilobits; +typedef LLUnit Megabits; +typedef LLUnit Gigabits; + +typedef LLUnit Seconds; +typedef LLUnit Milliseconds; +typedef LLUnit Minutes; +typedef LLUnit Hours; +typedef LLUnit Milliseconds; +typedef LLUnit Microseconds; +typedef LLUnit Nanoseconds; + +typedef LLUnit Meters; +typedef LLUnit Kilometers; +typedef LLUnit Centimeters; +typedef LLUnit Millimeters; + +void init(); +void cleanup(); +bool isInitialized(); + +const LLThreadLocalPointer& get_thread_recorder(); +void set_thread_recorder(class ThreadRecorder*); + +class MasterThreadRecorder& getMasterThreadRecorder(); + +// one per thread per type +template +class AccumulatorBuffer : public LLRefCount +{ + typedef AccumulatorBuffer self_t; + static const U32 DEFAULT_ACCUMULATOR_BUFFER_SIZE = 64; +private: + struct StaticAllocationMarker { }; - public: + AccumulatorBuffer(StaticAllocationMarker m) + : mStorageSize(0), + mStorage(NULL), + mNextStorageSlot(0) + { + } - AccumulatorBuffer(const AccumulatorBuffer& other = *getDefaultBuffer()) - : mStorageSize(0), - mStorage(NULL), - mNextStorageSlot(other.mNextStorageSlot) - { - resize(other.mStorageSize); - for (S32 i = 0; i < mNextStorageSlot; i++) - { - mStorage[i] = other.mStorage[i]; - } - } +public: - ~AccumulatorBuffer() + AccumulatorBuffer(const AccumulatorBuffer& other = *getDefaultBuffer()) + : mStorageSize(0), + mStorage(NULL), + mNextStorageSlot(other.mNextStorageSlot) + { + resize(other.mStorageSize); + for (S32 i = 0; i < mNextStorageSlot; i++) { - if (LLThreadLocalSingletonPointer::getInstance() == mStorage) - { - LLThreadLocalSingletonPointer::setInstance(getDefaultBuffer()->mStorage); - } - delete[] mStorage; + mStorage[i] = other.mStorage[i]; } + } - LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) - { - return mStorage[index]; + ~AccumulatorBuffer() + { + if (LLThreadLocalSingletonPointer::getInstance() == mStorage) + { + LLThreadLocalSingletonPointer::setInstance(getDefaultBuffer()->mStorage); } + delete[] mStorage; + } - LL_FORCE_INLINE const ACCUMULATOR& operator[](size_t index) const - { - return mStorage[index]; - } + LL_FORCE_INLINE ACCUMULATOR& operator[](size_t index) + { + return mStorage[index]; + } - void addSamples(const AccumulatorBuffer& other) - { - llassert(mNextStorageSlot == other.mNextStorageSlot); + LL_FORCE_INLINE const ACCUMULATOR& operator[](size_t index) const + { + return mStorage[index]; + } - for (size_t i = 0; i < mNextStorageSlot; i++) - { - mStorage[i].addSamples(other.mStorage[i]); - } - } + void addSamples(const AccumulatorBuffer& other) + { + llassert(mNextStorageSlot == other.mNextStorageSlot); - void copyFrom(const AccumulatorBuffer& other) + for (size_t i = 0; i < mNextStorageSlot; i++) { - for (size_t i = 0; i < mNextStorageSlot; i++) - { - mStorage[i] = other.mStorage[i]; - } + mStorage[i].addSamples(other.mStorage[i]); } + } - void reset(const AccumulatorBuffer* other = NULL) + void copyFrom(const AccumulatorBuffer& other) + { + for (size_t i = 0; i < mNextStorageSlot; i++) { - for (size_t i = 0; i < mNextStorageSlot; i++) - { - mStorage[i].reset(other ? &other->mStorage[i] : NULL); - } + mStorage[i] = other.mStorage[i]; } + } - void makePrimary() + void reset(const AccumulatorBuffer* other = NULL) + { + for (size_t i = 0; i < mNextStorageSlot; i++) { - LLThreadLocalSingletonPointer::setInstance(mStorage); + mStorage[i].reset(other ? &other->mStorage[i] : NULL); } + } - bool isPrimary() const - { - return LLThreadLocalSingletonPointer::getInstance() == mStorage; - } + void makePrimary() + { + LLThreadLocalSingletonPointer::setInstance(mStorage); + } - LL_FORCE_INLINE static ACCUMULATOR* getPrimaryStorage() - { - return LLThreadLocalSingletonPointer::getInstance(); - } + bool isPrimary() const + { + return LLThreadLocalSingletonPointer::getInstance() == mStorage; + } - // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned - size_t reserveSlot() + LL_FORCE_INLINE static ACCUMULATOR* getPrimaryStorage() + { + return LLThreadLocalSingletonPointer::getInstance(); + } + + // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned + size_t reserveSlot() + { + if (LLTrace::isInitialized()) { - if (LLTrace::isInitialized()) - { - llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; - } - size_t next_slot = mNextStorageSlot++; - if (next_slot >= mStorageSize) - { - resize(mStorageSize + (mStorageSize >> 2)); - } - llassert(mStorage && next_slot < mStorageSize); - return next_slot; + llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; } - - void resize(size_t new_size) + size_t next_slot = mNextStorageSlot++; + if (next_slot >= mStorageSize) { - if (new_size <= mStorageSize) return; + resize(mStorageSize + (mStorageSize >> 2)); + } + llassert(mStorage && next_slot < mStorageSize); + return next_slot; + } - ACCUMULATOR* old_storage = mStorage; - mStorage = new ACCUMULATOR[new_size]; - if (old_storage) - { - for (S32 i = 0; i < mStorageSize; i++) - { - mStorage[i] = old_storage[i]; - } - } - mStorageSize = new_size; - delete[] old_storage; + void resize(size_t new_size) + { + if (new_size <= mStorageSize) return; - self_t* default_buffer = getDefaultBuffer(); - if (this != default_buffer - && new_size > default_buffer->size()) + ACCUMULATOR* old_storage = mStorage; + mStorage = new ACCUMULATOR[new_size]; + if (old_storage) + { + for (S32 i = 0; i < mStorageSize; i++) { - //NB: this is not thread safe, but we assume that all resizing occurs during static initialization - default_buffer->resize(new_size); + mStorage[i] = old_storage[i]; } } + mStorageSize = new_size; + delete[] old_storage; - size_t size() const + self_t* default_buffer = getDefaultBuffer(); + if (this != default_buffer + && new_size > default_buffer->size()) { - return mNextStorageSlot; + //NB: this is not thread safe, but we assume that all resizing occurs during static initialization + default_buffer->resize(new_size); } + } + + size_t size() const + { + return mNextStorageSlot; + } - static self_t* getDefaultBuffer() + static self_t* getDefaultBuffer() + { + // this buffer is allowed to leak so that trace calls from global destructors have somewhere to put their data + // so as not to trigger an access violation + static self_t* sBuffer = new AccumulatorBuffer(StaticAllocationMarker()); + static bool sInitialized = false; + if (!sInitialized) { - // this buffer is allowed to leak so that trace calls from global destructors have somewhere to put their data - // so as not to trigger an access violation - static self_t* sBuffer = new AccumulatorBuffer(StaticAllocationMarker()); - static bool sInitialized = false; - if (!sInitialized) - { - sBuffer->resize(DEFAULT_ACCUMULATOR_BUFFER_SIZE); - sInitialized = true; - } - return sBuffer; + sBuffer->resize(DEFAULT_ACCUMULATOR_BUFFER_SIZE); + sInitialized = true; } + return sBuffer; + } - private: - ACCUMULATOR* mStorage; - size_t mStorageSize; - size_t mNextStorageSlot; - }; +private: + ACCUMULATOR* mStorage; + size_t mStorageSize; + size_t mNextStorageSlot; +}; - //TODO: replace with decltype when C++11 is enabled - template - struct MeanValueType - { - typedef F64 type; - }; +//TODO: replace with decltype when C++11 is enabled +template +struct MeanValueType +{ + typedef F64 type; +}; - template - class TraceType - : public LLInstanceTracker, std::string> +template +class TraceType +: public LLInstanceTracker, std::string> +{ +public: + TraceType(const char* name, const char* description = NULL) + : LLInstanceTracker, std::string>(name), + mName(name), + mDescription(description ? description : ""), + mAccumulatorIndex(AccumulatorBuffer::getDefaultBuffer()->reserveSlot()) + {} + + LL_FORCE_INLINE ACCUMULATOR* getPrimaryAccumulator() const { - public: - TraceType(const char* name, const char* description = NULL) - : LLInstanceTracker, std::string>(name), - mName(name), - mDescription(description ? description : ""), - mAccumulatorIndex(AccumulatorBuffer::getDefaultBuffer()->reserveSlot()) - {} + ACCUMULATOR* accumulator_storage = AccumulatorBuffer::getPrimaryStorage(); + return &accumulator_storage[mAccumulatorIndex]; + } - LL_FORCE_INLINE ACCUMULATOR* getPrimaryAccumulator() const - { - ACCUMULATOR* accumulator_storage = AccumulatorBuffer::getPrimaryStorage(); - return &accumulator_storage[mAccumulatorIndex]; - } + size_t getIndex() const { return mAccumulatorIndex; } - size_t getIndex() const { return mAccumulatorIndex; } + const std::string& getName() const { return mName; } - const std::string& getName() const { return mName; } +protected: + const std::string mName; + const std::string mDescription; + const size_t mAccumulatorIndex; +}; - protected: - const std::string mName; - const std::string mDescription; - const size_t mAccumulatorIndex; - }; +template +class MeasurementAccumulator +{ +public: + typedef T value_t; + typedef MeasurementAccumulator self_t; + + MeasurementAccumulator() + : mSum(0), + mMin((std::numeric_limits::max)()), + mMax((std::numeric_limits::min)()), + mMean(0), + mVarianceSum(0), + mNumSamples(0), + mLastValue(0) + {} - template - class MeasurementAccumulator + void sample(T value) { - public: - typedef T value_t; - typedef MeasurementAccumulator self_t; - - MeasurementAccumulator() - : mSum(0), - mMin((std::numeric_limits::max)()), - mMax((std::numeric_limits::min)()), - mMean(0), - mVarianceSum(0), - mNumSamples(0), - mLastValue(0) - {} + mNumSamples++; + mSum += value; + if (value < mMin) + { + mMin = value; + } + if (value > mMax) + { + mMax = value; + } + F64 old_mean = mMean; + mMean += ((F64)value - old_mean) / (F64)mNumSamples; + mVarianceSum += ((F64)value - old_mean) * ((F64)value - mMean); + mLastValue = value; + } - LL_FORCE_INLINE void sample(T value) + void addSamples(const self_t& other) + { + if (other.mNumSamples) { - T storage_value(value); - mNumSamples++; - mSum += storage_value; - if (storage_value < mMin) + mSum += other.mSum; + if (other.mMin < mMin) { - mMin = storage_value; + mMin = other.mMin; } - if (storage_value > mMax) + if (other.mMax > mMax) { - mMax = storage_value; + mMax = other.mMax; } - F64 old_mean = mMean; - mMean += ((F64)storage_value - old_mean) / (F64)mNumSamples; - mVarianceSum += ((F64)storage_value - old_mean) * ((F64)storage_value - mMean); - mLastValue = storage_value; - } - - void addSamples(const self_t& other) - { - if (other.mNumSamples) + F64 weight = (F64)mNumSamples / (F64)(mNumSamples + other.mNumSamples); + mNumSamples += other.mNumSamples; + mMean = mMean * weight + other.mMean * (1.f - weight); + + // combine variance (and hence standard deviation) of 2 different sized sample groups using + // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm + F64 n_1 = (F64)mNumSamples, + n_2 = (F64)other.mNumSamples; + F64 m_1 = mMean, + m_2 = other.mMean; + F64 v_1 = mVarianceSum / mNumSamples, + v_2 = other.mVarianceSum / other.mNumSamples; + if (n_1 == 0) + { + mVarianceSum = other.mVarianceSum; + } + else if (n_2 == 0) { - mSum += other.mSum; - if (other.mMin < mMin) - { - mMin = other.mMin; - } - if (other.mMax > mMax) - { - mMax = other.mMax; - } - F64 weight = (F64)mNumSamples / (F64)(mNumSamples + other.mNumSamples); - mNumSamples += other.mNumSamples; - mMean = mMean * weight + other.mMean * (1.f - weight); - - // combine variance (and hence standard deviation) of 2 different sized sample groups using - // the following formula: http://www.mrc-bsu.cam.ac.uk/cochrane/handbook/chapter_7/7_7_3_8_combining_groups.htm - F64 n_1 = (F64)mNumSamples, - n_2 = (F64)other.mNumSamples; - F64 m_1 = mMean, - m_2 = other.mMean; - F64 sd_1 = getStandardDeviation(), - sd_2 = other.getStandardDeviation(); - if (n_1 == 0) - { - mVarianceSum = other.mVarianceSum; - } - else if (n_2 == 0) - { - // don't touch variance - // mVarianceSum = mVarianceSum; - } - else - { - mVarianceSum = (F64)mNumSamples - * ((((n_1 - 1.f) * sd_1 * sd_1) - + ((n_2 - 1.f) * sd_2 * sd_2) - + (((n_1 * n_2) / (n_1 + n_2)) - * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) - / (n_1 + n_2 - 1.f)); - } - mLastValue = other.mLastValue; + // don't touch variance + // mVarianceSum = mVarianceSum; } + else + { + mVarianceSum = (F64)mNumSamples + * ((((n_1 - 1.f) * v_1) + + ((n_2 - 1.f) * v_2) + + (((n_1 * n_2) / (n_1 + n_2)) + * ((m_1 * m_1) + (m_2 * m_2) - (2.f * m_1 * m_2)))) + / (n_1 + n_2 - 1.f)); + } + mLastValue = other.mLastValue; } + } - void reset(const self_t* other) - { - mNumSamples = 0; - mSum = 0; - mMin = 0; - mMax = 0; - mMean = 0; - mVarianceSum = 0; - mLastValue = other ? other->mLastValue : 0; - } + void reset(const self_t* other) + { + mNumSamples = 0; + mSum = 0; + mMin = 0; + mMax = 0; + mMean = 0; + mVarianceSum = 0; + mLastValue = other ? other->mLastValue : 0; + } - T getSum() const { return (T)mSum; } - T getMin() const { return (T)mMin; } - T getMax() const { return (T)mMax; } - T getLastValue() const { return (T)mLastValue; } - F64 getMean() const { return mMean; } - F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } - U32 getSampleCount() const { return mNumSamples; } + T getSum() const { return (T)mSum; } + T getMin() const { return (T)mMin; } + T getMax() const { return (T)mMax; } + T getLastValue() const { return (T)mLastValue; } + F64 getMean() const { return mMean; } + F64 getStandardDeviation() const { return sqrtf(mVarianceSum / mNumSamples); } + U32 getSampleCount() const { return mNumSamples; } - private: - T mSum, - mMin, - mMax, - mLastValue; +private: + T mSum, + mMin, + mMax, + mLastValue; - F64 mMean, - mVarianceSum; + F64 mMean, + mVarianceSum; - U32 mNumSamples; - }; + U32 mNumSamples; +}; + +template +class CountAccumulator +{ +public: + typedef CountAccumulator self_t; + typedef T value_t; + + CountAccumulator() + : mSum(0), + mNumSamples(0) + {} - template - class CountAccumulator + void add(T value) { - public: - typedef CountAccumulator self_t; - typedef T value_t; + mNumSamples++; + mSum += value; + } - CountAccumulator() - : mSum(0), - mNumSamples(0) - {} + void addSamples(const CountAccumulator& other) + { + mSum += other.mSum; + mNumSamples += other.mNumSamples; + } - LL_FORCE_INLINE void add(T value) - { - mNumSamples++; - mSum += value; - } + void reset(const self_t* other) + { + mNumSamples = 0; + mSum = 0; + } - void addSamples(const CountAccumulator& other) - { - mSum += other.mSum; - mNumSamples += other.mNumSamples; - } + T getSum() const { return (T)mSum; } - void reset(const self_t* other) - { - mNumSamples = 0; - mSum = 0; - } + U32 getSampleCount() const { return mNumSamples; } - T getSum() const { return (T)mSum; } +private: + T mSum; - U32 getSampleCount() const { return mNumSamples; } + U32 mNumSamples; +}; - private: - T mSum; +class TimeBlockAccumulator +{ +public: + typedef LLUnit value_t; + typedef TimeBlockAccumulator self_t; - U32 mNumSamples; + // fake class that allows us to view call count aspect of timeblock accumulator + struct CallCountAspect + { + typedef U32 value_t; }; - class TimeBlockAccumulator + struct SelfTimeAspect { - public: typedef LLUnit value_t; - typedef TimeBlockAccumulator self_t; + }; - // fake class that allows us to view call count aspect of timeblock accumulator - struct CallCountAspect - { - typedef U32 value_t; - }; + TimeBlockAccumulator(); + void addSamples(const self_t& other); + void reset(const self_t* other); + + // + // members + // + U64 mStartTotalTimeCounter, + mTotalTimeCounter, + mSelfTimeCounter; + U32 mCalls; + class TimeBlock* mParent; // last acknowledged parent of this time block + class TimeBlock* mLastCaller; // used to bootstrap tree construction + U16 mActiveCount; // number of timers with this ID active on stack + bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame - struct SelfTimeAspect - { - typedef LLUnit value_t; - }; - - TimeBlockAccumulator(); - void addSamples(const self_t& other); - void reset(const self_t* other); - - // - // members - // - U64 mStartTotalTimeCounter, - mTotalTimeCounter, - mSelfTimeCounter; - U32 mCalls; - class TimeBlock* mParent; // last acknowledged parent of this time block - class TimeBlock* mLastCaller; // used to bootstrap tree construction - U16 mActiveCount; // number of timers with this ID active on stack - bool mMoveUpTree; // needs to be moved up the tree of timers at the end of frame +}; - }; +template<> +struct MeanValueType > +{ + typedef LLUnit type; +}; - template<> - struct MeanValueType > - { - typedef LLUnit type; - }; +template<> +class TraceType +: public TraceType +{ +public: - template<> - class TraceType + TraceType(const char* name, const char* description = "") + : TraceType(name, description) + {} +}; + +template<> +struct MeanValueType > +{ + typedef F64 type; +}; + + +template<> +class TraceType : public TraceType - { - public: +{ +public: - TraceType(const char* name, const char* description = "") + TraceType(const char* name, const char* description = "") : TraceType(name, description) - {} - }; - - template<> - struct MeanValueType > - { - typedef F64 type; - }; + {} +}; +template<> +struct MeanValueType > +{ + typedef LLUnit type; +}; - template<> - class TraceType - : public TraceType - { - public: - TraceType(const char* name, const char* description = "") - : TraceType(name, description) - {} - }; +class TimeBlock; +class TimeBlockTreeNode +{ +public: + TimeBlockTreeNode(); - template<> - struct MeanValueType > - { - typedef LLUnit type; - }; + void setParent(TimeBlock* parent); + TimeBlock* getParent() { return mParent; } + TimeBlock* mBlock; + TimeBlock* mParent; + std::vector mChildren; + bool mNeedsSorting; +}; - class TimeBlock; - class TimeBlockTreeNode - { - public: - TimeBlockTreeNode(); - void setParent(TimeBlock* parent); - TimeBlock* getParent() { return mParent; } +template +class MeasurementStatHandle +: public TraceType::type_t> > +{ +public: + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; + typedef TraceType::type_t> > trace_t; - TimeBlock* mBlock; - TimeBlock* mParent; - std::vector mChildren; - bool mNeedsSorting; - }; + MeasurementStatHandle(const char* name, const char* description = NULL) + : trace_t(name, description) + {} +}; +template +void sample(MeasurementStatHandle& measurement, VALUE_T value) +{ + T converted_value(value); + measurement.getPrimaryAccumulator()->sample(LLUnits::rawValue(converted_value)); +} - template - class Measurement - : public TraceType::type_t> > - { - public: - typedef typename LLUnits::HighestPrecisionType::type_t storage_t; - typedef TraceType::type_t> > trace_t; - Measurement(const char* name, const char* description = NULL) - : trace_t(name, description) - {} +template +class CountStatHandle +: public TraceType::type_t> > +{ +public: + typedef typename LLUnits::HighestPrecisionType::type_t storage_t; + typedef TraceType::type_t> > trace_t; - template - void sample(UNIT_T value) - { - T converted_value(value); - trace_t::getPrimaryAccumulator()->sample(LLUnits::rawValue(converted_value)); - } - }; + CountStatHandle(const char* name, const char* description = NULL) + : trace_t(name) + {} - template - class Count - : public TraceType::type_t> > - { - public: - typedef typename LLUnits::HighestPrecisionType::type_t storage_t; - typedef TraceType::type_t> > trace_t; +}; - Count(const char* name, const char* description = NULL) - : trace_t(name) - {} +template +void add(CountStatHandle& count, VALUE_T value) +{ + T converted_value(value); + count.getPrimaryAccumulator()->add(LLUnits::rawValue(converted_value)); +} - template - void add(UNIT_T value) - { - T converted_value(value); - trace_t::getPrimaryAccumulator()->add(LLUnits::rawValue(converted_value)); - } - }; struct MemStatAccumulator { @@ -585,11 +587,11 @@ struct MemStatAccumulator mDeallocatedCount; }; -class MemStat : public TraceType +class MemStatHandle : public TraceType { public: typedef TraceType trace_t; - MemStat(const char* name) + MemStatHandle(const char* name) : trace_t(name) {} }; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index af9ba02b29..6b4d4357db 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -135,11 +135,11 @@ namespace LLTrace LLUnit getSum(const TraceType& stat) const; LLUnit getPerSec(const TraceType& stat) const; - // Count accessors + // CountStatHandle accessors F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; template - T getSum(const Count& stat) const + T getSum(const CountStatHandle& stat) const { return (T)getSum(static_cast::type_t> >&> (stat)); } @@ -147,7 +147,7 @@ namespace LLTrace F64 getPerSec(const TraceType >& stat) const; F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const Count& stat) const + T getPerSec(const CountStatHandle& stat) const { return (T)getPerSec(static_cast::type_t> >&> (stat)); } @@ -156,11 +156,11 @@ namespace LLTrace U32 getSampleCount(const TraceType >& stat) const; - // Measurement accessors + // MeasurementStatHandle accessors F64 getSum(const TraceType >& stat) const; S64 getSum(const TraceType >& stat) const; template - T getSum(const Measurement& stat) const + T getSum(const MeasurementStatHandle& stat) const { return (T)getSum(static_cast::type_t> >&> (stat)); } @@ -168,7 +168,7 @@ namespace LLTrace F64 getPerSec(const TraceType >& stat) const; F64 getPerSec(const TraceType >& stat) const; template - T getPerSec(const Measurement& stat) const + T getPerSec(const MeasurementStatHandle& stat) const { return (T)getPerSec(static_cast::type_t> >&> (stat)); } @@ -176,7 +176,7 @@ namespace LLTrace F64 getMin(const TraceType >& stat) const; S64 getMin(const TraceType >& stat) const; template - T getMin(const Measurement& stat) const + T getMin(const MeasurementStatHandle& stat) const { return (T)getMin(static_cast::type_t> >&> (stat)); } @@ -184,7 +184,7 @@ namespace LLTrace F64 getMax(const TraceType >& stat) const; S64 getMax(const TraceType >& stat) const; template - T getMax(const Measurement& stat) const + T getMax(const MeasurementStatHandle& stat) const { return (T)getMax(static_cast::type_t> >&> (stat)); } @@ -192,7 +192,7 @@ namespace LLTrace F64 getMean(const TraceType >& stat) const; F64 getMean(const TraceType >& stat) const; template - T getMean(Measurement& stat) const + T getMean(MeasurementStatHandle& stat) const { return (T)getMean(static_cast::type_t> >&> (stat)); } @@ -200,7 +200,7 @@ namespace LLTrace F64 getStandardDeviation(const TraceType >& stat) const; F64 getStandardDeviation(const TraceType >& stat) const; template - T getStandardDeviation(const Measurement& stat) const + T getStandardDeviation(const MeasurementStatHandle& stat) const { return (T)getMean(static_cast::type_t> >&> (stat)); } @@ -208,7 +208,7 @@ namespace LLTrace F64 getLastValue(const TraceType >& stat) const; S64 getLastValue(const TraceType >& stat) const; template - T getLastValue(const Measurement& stat) const + T getLastValue(const MeasurementStatHandle& stat) const { return (T)getLastValue(static_cast::type_t> >&> (stat)); } @@ -394,6 +394,7 @@ namespace LLTrace { public: void extend(); + Recording& getAcceptedRecording() { return mAcceptedRecording; } // implementation for LLStopWatchControlsMixin -- cgit v1.2.3 From 1a256eca280e41a672fc87e083db851ab180612c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 11 Mar 2013 00:37:50 -0700 Subject: renamed some variables/methods in LLTrace to make things clearer --- indra/llcommon/lltrace.h | 1 + indra/llcommon/lltracerecording.cpp | 4 ++-- indra/llcommon/lltracerecording.h | 2 +- indra/llcommon/lltracethreadrecorder.cpp | 30 +++++++++++++++--------------- indra/llcommon/lltracethreadrecorder.h | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 44da1939c6..9bca3625b6 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -287,6 +287,7 @@ public: { mNumSamples++; mSum += value; + // NOTE: both conditions will hold on first pass through if (value < mMin) { mMin = value; diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index ab8dbce2ce..3df06c5172 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -109,10 +109,10 @@ void Recording::handleSplitTo(Recording& other) { stop(); other.restart(); - syncTo(other); + handOffTo(other); } -void Recording::syncTo(Recording& other) +void Recording::handOffTo(Recording& other) { other.mCountsFloat.write()->reset(mCountsFloat); other.mMeasurementsFloat.write()->reset(mMeasurementsFloat); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 6b4d4357db..7dd3b98187 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -218,7 +218,7 @@ namespace LLTrace LLUnit getDuration() const { return LLUnit(mElapsedSeconds); } - void syncTo(Recording& other); + void handOffTo(Recording& other); private: friend class ThreadRecorder; diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 113febcca8..d540a60308 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -97,11 +97,11 @@ void ThreadRecorder::activate( Recording* recording ) ActiveRecording* active_recording = new ActiveRecording(recording); if (!mActiveRecordings.empty()) { - mActiveRecordings.front()->mBaseline.syncTo(active_recording->mBaseline); + mActiveRecordings.front()->mPartialRecording.handOffTo(active_recording->mPartialRecording); } mActiveRecordings.push_front(active_recording); - mActiveRecordings.front()->mBaseline.makePrimary(); + mActiveRecordings.front()->mPartialRecording.makePrimary(); } ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::update( Recording* recording ) @@ -118,10 +118,10 @@ ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::update( Record if (next_it != mActiveRecordings.end()) { // ...push our gathered data down to it - (*next_it)->mBaseline.appendRecording((*it)->mBaseline); + (*next_it)->mPartialRecording.appendRecording((*it)->mPartialRecording); } - // copy accumulated measurements into result buffer and clear accumulator (mBaseline) + // copy accumulated measurements into result buffer and clear accumulator (mPartialRecording) (*it)->moveBaselineToTarget(); if ((*it)->mTargetRecording == recording) @@ -171,16 +171,16 @@ ThreadRecorder::ActiveRecording::ActiveRecording( Recording* target ) void ThreadRecorder::ActiveRecording::moveBaselineToTarget() { - mTargetRecording->mMeasurementsFloat.write()->addSamples(*mBaseline.mMeasurementsFloat); - mTargetRecording->mCountsFloat.write()->addSamples(*mBaseline.mCountsFloat); - mTargetRecording->mMeasurements.write()->addSamples(*mBaseline.mMeasurements); - mTargetRecording->mCounts.write()->addSamples(*mBaseline.mCounts); - mTargetRecording->mStackTimers.write()->addSamples(*mBaseline.mStackTimers); - mBaseline.mMeasurementsFloat.write()->reset(); - mBaseline.mCountsFloat.write()->reset(); - mBaseline.mMeasurements.write()->reset(); - mBaseline.mCounts.write()->reset(); - mBaseline.mStackTimers.write()->reset(); + mTargetRecording->mMeasurementsFloat.write()->addSamples(*mPartialRecording.mMeasurementsFloat); + mTargetRecording->mCountsFloat.write()->addSamples(*mPartialRecording.mCountsFloat); + mTargetRecording->mMeasurements.write()->addSamples(*mPartialRecording.mMeasurements); + mTargetRecording->mCounts.write()->addSamples(*mPartialRecording.mCounts); + mTargetRecording->mStackTimers.write()->addSamples(*mPartialRecording.mStackTimers); + mPartialRecording.mMeasurementsFloat.write()->reset(); + mPartialRecording.mCountsFloat.write()->reset(); + mPartialRecording.mMeasurements.write()->reset(); + mPartialRecording.mCounts.write()->reset(); + mPartialRecording.mStackTimers.write()->reset(); } @@ -251,7 +251,7 @@ void MasterThreadRecorder::pullFromSlaveThreads() LLMutexLock lock(&mSlaveListMutex); - Recording& target_recording = mActiveRecordings.front()->mBaseline; + Recording& target_recording = mActiveRecordings.front()->mPartialRecording; for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index 0e6c091900..ee2e04236a 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -59,7 +59,7 @@ namespace LLTrace ActiveRecording(Recording* target); Recording* mTargetRecording; - Recording mBaseline; + Recording mPartialRecording; void moveBaselineToTarget(); }; -- cgit v1.2.3 From 24a1ceb25de2b9573eb369a6e0d1811fe594aabb Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 11 Mar 2013 01:08:51 -0700 Subject: separated RecordingBuffers from Recording to make active recording stack more safe --- indra/llcommon/lltracerecording.cpp | 166 +++++++++++++++++++----------------- indra/llcommon/lltracerecording.h | 38 +++++---- 2 files changed, 111 insertions(+), 93 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 3df06c5172..ef0a633c9c 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -34,13 +34,13 @@ namespace LLTrace { + /////////////////////////////////////////////////////////////////////// -// Recording +// RecordingBuffers /////////////////////////////////////////////////////////////////////// -Recording::Recording() -: mElapsedSeconds(0), - mCountsFloat(new AccumulatorBuffer >()), +RecordingBuffers::RecordingBuffers() +: mCountsFloat(new AccumulatorBuffer >()), mMeasurementsFloat(new AccumulatorBuffer >()), mCounts(new AccumulatorBuffer >()), mMeasurements(new AccumulatorBuffer >()), @@ -48,71 +48,7 @@ Recording::Recording() mMemStats(new AccumulatorBuffer()) {} -Recording::Recording( const Recording& other ) -{ - llassert(other.mCountsFloat.notNull()); - mSamplingTimer = other.mSamplingTimer; - mElapsedSeconds = other.mElapsedSeconds; - mCountsFloat = other.mCountsFloat; - mMeasurementsFloat = other.mMeasurementsFloat; - mCounts = other.mCounts; - mMeasurements = other.mMeasurements; - mStackTimers = other.mStackTimers; - mMemStats = other.mMemStats; - - LLStopWatchControlsMixin::setPlayState(other.getPlayState()); -} - - -Recording::~Recording() -{ - stop(); - llassert(isStopped()); -} - -void Recording::update() -{ - if (isStarted()) - { - LLTrace::get_thread_recorder()->update(this); - mSamplingTimer.reset(); - } -} - -void Recording::handleReset() -{ - mCountsFloat.write()->reset(); - mMeasurementsFloat.write()->reset(); - mCounts.write()->reset(); - mMeasurements.write()->reset(); - mStackTimers.write()->reset(); - mMemStats.write()->reset(); - - mElapsedSeconds = 0.0; - mSamplingTimer.reset(); -} - -void Recording::handleStart() -{ - mSamplingTimer.reset(); - LLTrace::get_thread_recorder()->activate(this); -} - -void Recording::handleStop() -{ - mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); - LLTrace::TimeBlock::processTimes(); - LLTrace::get_thread_recorder()->deactivate(this); -} - -void Recording::handleSplitTo(Recording& other) -{ - stop(); - other.restart(); - handOffTo(other); -} - -void Recording::handOffTo(Recording& other) +void RecordingBuffers::handOffTo(RecordingBuffers& other) { other.mCountsFloat.write()->reset(mCountsFloat); other.mMeasurementsFloat.write()->reset(mMeasurementsFloat); @@ -122,7 +58,7 @@ void Recording::handOffTo(Recording& other) other.mMemStats.write()->reset(mMemStats); } -void Recording::makePrimary() +void RecordingBuffers::makePrimary() { mCountsFloat.write()->makePrimary(); mMeasurementsFloat.write()->makePrimary(); @@ -144,12 +80,12 @@ void Recording::makePrimary() } } -bool Recording::isPrimary() const +bool RecordingBuffers::isPrimary() const { return mCounts->isPrimary(); } -void Recording::makeUnique() +void RecordingBuffers::makeUnique() { mCountsFloat.makeUnique(); mMeasurementsFloat.makeUnique(); @@ -159,19 +95,17 @@ void Recording::makeUnique() mMemStats.makeUnique(); } -void Recording::appendRecording( const Recording& other ) +void RecordingBuffers::appendBuffers( const RecordingBuffers& other ) { mCountsFloat.write()->addSamples(*other.mCountsFloat); mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); mCounts.write()->addSamples(*other.mCounts); mMeasurements.write()->addSamples(*other.mMeasurements); mMemStats.write()->addSamples(*other.mMemStats); - mStackTimers.write()->addSamples(*other.mStackTimers); - mElapsedSeconds += other.mElapsedSeconds; } -void Recording::mergeRecording( const Recording& other) +void RecordingBuffers::mergeBuffers( const RecordingBuffers& other) { mCountsFloat.write()->addSamples(*other.mCountsFloat); mMeasurementsFloat.write()->addSamples(*other.mMeasurementsFloat); @@ -180,6 +114,84 @@ void Recording::mergeRecording( const Recording& other) mMemStats.write()->addSamples(*other.mMemStats); } +void RecordingBuffers::resetBuffers(RecordingBuffers* other) +{ + mCountsFloat.write()->reset(other ? other->mCountsFloat : NULL); + mMeasurementsFloat.write()->reset(other ? other->mMeasurementsFloat : NULL); + mCounts.write()->reset(other ? other->mCounts : NULL); + mMeasurements.write()->reset(other ? other->mMeasurements : NULL); + mStackTimers.write()->reset(other ? other->mStackTimers : NULL); + mMemStats.write()->reset(other ? other->mMemStats : NULL); +} + +/////////////////////////////////////////////////////////////////////// +// Recording +/////////////////////////////////////////////////////////////////////// + +Recording::Recording() +: mElapsedSeconds(0) +{} + +Recording::Recording( const Recording& other ) +{ + LLStopWatchControlsMixin::setPlayState(other.getPlayState()); +} + + +Recording::~Recording() +{ + stop(); + llassert(isStopped()); +} + +void Recording::update() +{ + if (isStarted()) + { + LLTrace::get_thread_recorder()->update(this); + mSamplingTimer.reset(); + } +} + +void Recording::handleReset() +{ + resetBuffers(); + + mElapsedSeconds = 0.0; + mSamplingTimer.reset(); +} + +void Recording::handleStart() +{ + mSamplingTimer.reset(); + LLTrace::get_thread_recorder()->activate(this); +} + +void Recording::handleStop() +{ + mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); + LLTrace::TimeBlock::processTimes(); + LLTrace::get_thread_recorder()->deactivate(this); +} + +void Recording::handleSplitTo(Recording& other) +{ + stop(); + other.restart(); + handOffTo(other); +} + +void Recording::appendRecording( const Recording& other ) +{ + appendBuffers(other); + mElapsedSeconds += other.mElapsedSeconds; +} + +void Recording::mergeRecording( const Recording& other) +{ + mergeBuffers(other); +} + LLUnit Recording::getSum(const TraceType& stat) const { const TimeBlockAccumulator& accumulator = (*mStackTimers)[stat.getIndex()]; @@ -356,8 +368,6 @@ U32 Recording::getSampleCount( const TraceType >& st return (*mMeasurements)[stat.getIndex()].getSampleCount(); } - - /////////////////////////////////////////////////////////////////////// // PeriodicRecording /////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 7dd3b98187..a5edcb857a 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -100,19 +100,36 @@ private: namespace LLTrace { - class Recording : public LLStopWatchControlsMixin + struct RecordingBuffers { - public: - Recording(); - - Recording(const Recording& other); - ~Recording(); + RecordingBuffers(); + LLCopyOnWritePointer > > mCountsFloat; + LLCopyOnWritePointer > > mMeasurementsFloat; + LLCopyOnWritePointer > > mCounts; + LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > mStackTimers; + LLCopyOnWritePointer > mMemStats; + void handOffTo(RecordingBuffers& other); void makePrimary(); bool isPrimary() const; void makeUnique(); + void appendBuffers(const RecordingBuffers& other); + void mergeBuffers(const RecordingBuffers& other); + void resetBuffers(RecordingBuffers* other = NULL); + + }; + + class Recording : public LLStopWatchControlsMixin, public RecordingBuffers + { + public: + Recording(); + + Recording(const Recording& other); + ~Recording(); + // accumulate data from subsequent, non-overlapping recording void appendRecording(const Recording& other); @@ -218,8 +235,6 @@ namespace LLTrace LLUnit getDuration() const { return LLUnit(mElapsedSeconds); } - void handOffTo(Recording& other); - private: friend class ThreadRecorder; @@ -232,13 +247,6 @@ namespace LLTrace // returns data for current thread class ThreadRecorder* getThreadRecorder(); - LLCopyOnWritePointer > > mCountsFloat; - LLCopyOnWritePointer > > mMeasurementsFloat; - LLCopyOnWritePointer > > mCounts; - LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimers; - LLCopyOnWritePointer > mMemStats; - LLTimer mSamplingTimer; F64 mElapsedSeconds; }; -- cgit v1.2.3 From b9c78533ae701fe6af5263e902f8df93c558e493 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 11 Mar 2013 01:09:48 -0700 Subject: separated RecordingBuffers from Recording to make active recording stack more safe (part 2) --- indra/llcommon/lltracethreadrecorder.cpp | 26 +++++++++----------------- indra/llcommon/lltracethreadrecorder.h | 6 +++--- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index d540a60308..9bef040cf7 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -118,7 +118,7 @@ ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::update( Record if (next_it != mActiveRecordings.end()) { // ...push our gathered data down to it - (*next_it)->mPartialRecording.appendRecording((*it)->mPartialRecording); + (*next_it)->mPartialRecording.appendBuffers((*it)->mPartialRecording); } // copy accumulated measurements into result buffer and clear accumulator (mPartialRecording) @@ -171,16 +171,8 @@ ThreadRecorder::ActiveRecording::ActiveRecording( Recording* target ) void ThreadRecorder::ActiveRecording::moveBaselineToTarget() { - mTargetRecording->mMeasurementsFloat.write()->addSamples(*mPartialRecording.mMeasurementsFloat); - mTargetRecording->mCountsFloat.write()->addSamples(*mPartialRecording.mCountsFloat); - mTargetRecording->mMeasurements.write()->addSamples(*mPartialRecording.mMeasurements); - mTargetRecording->mCounts.write()->addSamples(*mPartialRecording.mCounts); - mTargetRecording->mStackTimers.write()->addSamples(*mPartialRecording.mStackTimers); - mPartialRecording.mMeasurementsFloat.write()->reset(); - mPartialRecording.mCountsFloat.write()->reset(); - mPartialRecording.mMeasurements.write()->reset(); - mPartialRecording.mCounts.write()->reset(); - mPartialRecording.mStackTimers.write()->reset(); + mTargetRecording->appendBuffers(mPartialRecording); + mPartialRecording.resetBuffers(); } @@ -220,16 +212,16 @@ void SlaveThreadRecorder::SharedData::appendTo( Recording& sink ) sink.appendRecording(mRecording); } -void SlaveThreadRecorder::SharedData::mergeFrom( const Recording& source ) +void SlaveThreadRecorder::SharedData::mergeFrom( const RecordingBuffers& source ) { LLMutexLock lock(&mRecordingMutex); - mRecording.mergeRecording(source); + mRecording.mergeBuffers(source); } -void SlaveThreadRecorder::SharedData::mergeTo( Recording& sink ) +void SlaveThreadRecorder::SharedData::mergeTo( RecordingBuffers& sink ) { LLMutexLock lock(&mRecordingMutex); - sink.mergeRecording(mRecording); + sink.mergeBuffers(mRecording); } void SlaveThreadRecorder::SharedData::reset() @@ -251,13 +243,13 @@ void MasterThreadRecorder::pullFromSlaveThreads() LLMutexLock lock(&mSlaveListMutex); - Recording& target_recording = mActiveRecordings.front()->mPartialRecording; + RecordingBuffers& target_recording_buffers = mActiveRecordings.front()->mPartialRecording; for (slave_thread_recorder_list_t::iterator it = mSlaveThreadRecorders.begin(), end_it = mSlaveThreadRecorders.end(); it != end_it; ++it) { // ignore block timing info for now - (*it)->mSharedData.mergeTo(target_recording); + (*it)->mSharedData.mergeTo(target_recording_buffers); (*it)->mSharedData.reset(); } } diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index ee2e04236a..3e24303d92 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -59,7 +59,7 @@ namespace LLTrace ActiveRecording(Recording* target); Recording* mTargetRecording; - Recording mPartialRecording; + RecordingBuffers mPartialRecording; void moveBaselineToTarget(); }; @@ -111,8 +111,8 @@ namespace LLTrace public: void appendFrom(const Recording& source); void appendTo(Recording& sink); - void mergeFrom(const Recording& source); - void mergeTo(Recording& sink); + void mergeFrom(const RecordingBuffers& source); + void mergeTo(RecordingBuffers& sink); void reset(); private: LLMutex mRecordingMutex; -- cgit v1.2.3 From 7b4d27ecbcb5ac702459be97cbf6b81354850658 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 14 Mar 2013 19:36:50 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics collapsed Orientation enums to all use LLView::EOrientation added ability to display stat bar horizontally --- indra/llcommon/lltracerecording.cpp | 2 +- indra/llcommon/lltracerecording.h | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index ef0a633c9c..6695ebeaca 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -547,7 +547,7 @@ void ExtendableRecording::splitFrom(ExtendableRecording& other) PeriodicRecording& get_frame_recording() { - static LLThreadLocalPointer sRecording(new PeriodicRecording(200, PeriodicRecording::STARTED)); + static LLThreadLocalPointer sRecording(new PeriodicRecording(1000, PeriodicRecording::STARTED)); return *sRecording; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index a5edcb857a..70afe51d6e 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -100,15 +100,10 @@ private: namespace LLTrace { - struct RecordingBuffers + class RecordingBuffers { + public: RecordingBuffers(); - LLCopyOnWritePointer > > mCountsFloat; - LLCopyOnWritePointer > > mMeasurementsFloat; - LLCopyOnWritePointer > > mCounts; - LLCopyOnWritePointer > > mMeasurements; - LLCopyOnWritePointer > mStackTimers; - LLCopyOnWritePointer > mMemStats; void handOffTo(RecordingBuffers& other); void makePrimary(); @@ -120,6 +115,13 @@ namespace LLTrace void mergeBuffers(const RecordingBuffers& other); void resetBuffers(RecordingBuffers* other = NULL); + protected: + LLCopyOnWritePointer > > mCountsFloat; + LLCopyOnWritePointer > > mMeasurementsFloat; + LLCopyOnWritePointer > > mCounts; + LLCopyOnWritePointer > > mMeasurements; + LLCopyOnWritePointer > mStackTimers; + LLCopyOnWritePointer > mMemStats; }; class Recording : public LLStopWatchControlsMixin, public RecordingBuffers -- cgit v1.2.3 From 8de397b19ec9e2f6206fd5ae57dba96c70e78b74 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 18 Mar 2013 08:43:03 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics changed LLCriticalDamp to LLSmoothInterpolation and sped up interpolator lookup improvements to stats display of llstatbar added scene load stats floater accessed with ctrl|shift|2 --- indra/llcommon/llcriticaldamp.cpp | 77 ++++++++++++++++++++++++++----------- indra/llcommon/llcriticaldamp.h | 32 ++++++++++++--- indra/llcommon/lltracerecording.cpp | 17 -------- indra/llcommon/lltracerecording.h | 8 ---- 4 files changed, 80 insertions(+), 54 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp index 87d79b1ee0..59a31bf9df 100644 --- a/indra/llcommon/llcriticaldamp.cpp +++ b/indra/llcommon/llcriticaldamp.cpp @@ -27,18 +27,38 @@ #include "linden_common.h" #include "llcriticaldamp.h" +#include //----------------------------------------------------------------------------- // static members //----------------------------------------------------------------------------- -LLFrameTimer LLCriticalDamp::sInternalTimer; -std::map LLCriticalDamp::sInterpolants; -F32 LLCriticalDamp::sTimeDelta; +LLFrameTimer LLSmoothInterpolation::sInternalTimer; +std::vector LLSmoothInterpolation::sInterpolants; +F32 LLSmoothInterpolation::sTimeDelta; + +// helper functors +struct LLSmoothInterpolation::CompareTimeConstants +{ + bool operator()(const F32& a, const LLSmoothInterpolation::Interpolant& b) const + { + return a < b.mTimeScale; + } + + bool operator()(const LLSmoothInterpolation::Interpolant& a, const F32& b) const + { + return a.mTimeScale < b; // bottom of a is higher than bottom of b + } + + bool operator()(const LLSmoothInterpolation::Interpolant& a, const LLSmoothInterpolation::Interpolant& b) const + { + return a.mTimeScale < b.mTimeScale; // bottom of a is higher than bottom of b + } +}; //----------------------------------------------------------------------------- -// LLCriticalDamp() +// LLSmoothInterpolation() //----------------------------------------------------------------------------- -LLCriticalDamp::LLCriticalDamp() +LLSmoothInterpolation::LLSmoothInterpolation() { sTimeDelta = 0.f; } @@ -47,43 +67,54 @@ LLCriticalDamp::LLCriticalDamp() //----------------------------------------------------------------------------- // updateInterpolants() //----------------------------------------------------------------------------- -void LLCriticalDamp::updateInterpolants() +void LLSmoothInterpolation::updateInterpolants() { sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32(); - F32 time_constant; - - for (std::map::iterator iter = sInterpolants.begin(); - iter != sInterpolants.end(); iter++) + for (S32 i = 0; i < sInterpolants.size(); i++) { - time_constant = iter->first; - F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); - new_interpolant = llclamp(new_interpolant, 0.f, 1.f); - sInterpolants[time_constant] = new_interpolant; + Interpolant& interp = sInterpolants[i]; + interp.mInterpolant = calcInterpolant(interp.mTimeScale); } } //----------------------------------------------------------------------------- // getInterpolant() //----------------------------------------------------------------------------- -F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache) +F32 LLSmoothInterpolation::getInterpolant(LLUnit time_constant, bool use_cache) { if (time_constant == 0.f) { return 1.f; } - if (use_cache && sInterpolants.count(time_constant)) + if (use_cache) { - return sInterpolants[time_constant]; + interpolant_vec_t::iterator find_it = std::lower_bound(sInterpolants.begin(), sInterpolants.end(), time_constant.value(), CompareTimeConstants()); + if (find_it != sInterpolants.end() && find_it->mTimeScale == time_constant) + { + return find_it->mInterpolant; + } + else + { + Interpolant interp; + interp.mTimeScale = time_constant.value(); + interp.mInterpolant = calcInterpolant(time_constant.value()); + sInterpolants.insert(find_it, interp); + return interp.mInterpolant; + } } - - F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); - interpolant = llclamp(interpolant, 0.f, 1.f); - if (use_cache) + else { - sInterpolants[time_constant] = interpolant; + return calcInterpolant(time_constant.value()); + } +} - return interpolant; +//----------------------------------------------------------------------------- +// getInterpolant() +//----------------------------------------------------------------------------- +F32 LLSmoothInterpolation::calcInterpolant(F32 time_constant) +{ + return llclamp(1.f - pow(2.f, -sTimeDelta / time_constant), 0.f, 1.f); } diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h index 52f052ae25..ab5d4ba6e2 100644 --- a/indra/llcommon/llcriticaldamp.h +++ b/indra/llcommon/llcriticaldamp.h @@ -28,26 +28,46 @@ #ifndef LL_LLCRITICALDAMP_H #define LL_LLCRITICALDAMP_H -#include +#include #include "llframetimer.h" +#include "llunit.h" -class LL_COMMON_API LLCriticalDamp +class LL_COMMON_API LLSmoothInterpolation { public: - LLCriticalDamp(); + LLSmoothInterpolation(); // MANIPULATORS static void updateInterpolants(); // ACCESSORS - static F32 getInterpolant(const F32 time_constant, BOOL use_cache = TRUE); + static F32 getInterpolant(LLUnit time_constant, bool use_cache = true); -protected: + template + static T lerp(T a, T b, LLUnit time_constant, bool use_cache = true) + { + F32 interpolant = getInterpolant(time_constant, use_cache); + return ((a * (1.f - interpolant)) + + (b * interpolant)); + } + +protected: + static F32 calcInterpolant(F32 time_constant); + + struct CompareTimeConstants; static LLFrameTimer sInternalTimer; // frame timer for calculating deltas - static std::map sInterpolants; + struct Interpolant + { + F32 mTimeScale; + F32 mInterpolant; + }; + typedef std::vector interpolant_vec_t; + static interpolant_vec_t sInterpolants; static F32 sTimeDelta; }; +typedef LLSmoothInterpolation LLCriticalDamp; + #endif // LL_LLCRITICALDAMP_H diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 6695ebeaca..259f5a7a27 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -291,23 +291,6 @@ U32 Recording::getSampleCount( const TraceType >& stat ) c return (*mMeasurementsFloat)[stat.getIndex()].getSampleCount(); } - -F64 Recording::getPerSec( const TraceType >& stat ) const -{ - F64 sum = (*mMeasurementsFloat)[stat.getIndex()].getSum(); - return (sum != 0.0) - ? (sum / mElapsedSeconds) - : 0.0; -} - -F64 Recording::getPerSec( const TraceType >& stat ) const -{ - S64 sum = (*mMeasurements)[stat.getIndex()].getSum(); - return (sum != 0) - ? ((F64)sum / mElapsedSeconds) - : 0.0; -} - F64 Recording::getMin( const TraceType >& stat ) const { return (*mMeasurementsFloat)[stat.getIndex()].getMin(); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 70afe51d6e..751ff298ce 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -184,14 +184,6 @@ namespace LLTrace return (T)getSum(static_cast::type_t> >&> (stat)); } - F64 getPerSec(const TraceType >& stat) const; - F64 getPerSec(const TraceType >& stat) const; - template - T getPerSec(const MeasurementStatHandle& stat) const - { - return (T)getPerSec(static_cast::type_t> >&> (stat)); - } - F64 getMin(const TraceType >& stat) const; S64 getMin(const TraceType >& stat) const; template -- cgit v1.2.3 From 78f60fad0e4608cb996ee9cba8e4d10d3893f54d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 18 Mar 2013 23:37:57 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics cleaned up MemTrackable stats to not use special padded allocation --- indra/llcommon/lltrace.h | 81 ++++++------------------------------------------ 1 file changed, 9 insertions(+), 72 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 9bca3625b6..71bf1e53e4 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -674,57 +674,6 @@ struct MemFootprint > } }; -template -void* allocAligned(size_t size) -{ - llstatic_assert((ALIGNMENT > 0) && (ALIGNMENT & (ALIGNMENT - 1)) == 0, "Alignment must be a power of 2"); - - void* padded_allocation; - const size_t aligned_reserve = (RESERVE / ALIGNMENT) - + ((RESERVE % ALIGNMENT) ? ALIGNMENT : 0); - const size_t size_with_reserve = size + aligned_reserve; - if (ALIGNMENT <= LL_DEFAULT_HEAP_ALIGN) - { - padded_allocation = malloc(size_with_reserve); - } - else - { -#if LL_WINDOWS - padded_allocation = _aligned_malloc(size_with_reserve, ALIGNMENT); -#elif LL_DARWIN - padded_allocation = ll_aligned_malloc(size_with_reserve, ALIGNMENT); -#else - if (LL_UNLIKELY(0 != posix_memalign(&padded_allocation, 16, size))) - padded_allocation = NULL; -#endif - } - return (char*)padded_allocation + aligned_reserve; -} - -template -void deallocAligned(void* ptr) -{ - const size_t aligned_reserve = (RESERVE / ALIGNMENT) - + ((RESERVE % ALIGNMENT) ? ALIGNMENT : 0); - - void* original_allocation = (char*)ptr - aligned_reserve; - - if (ALIGNMENT <= LL_DEFAULT_HEAP_ALIGN) - { - free(original_allocation); - } - else - { -#if LL_WINDOWS - _aligned_free(original_allocation); -#elif LL_DARWIN - ll_aligned_free(original_allocation); -#else - free(original_allocation); -#endif - } -} - template class MemTrackable { @@ -736,7 +685,7 @@ class MemTrackable public: typedef void mem_trackable_tag_t; - ~MemTrackable() + virtual ~MemTrackable() { memDisclaim(mMemFootprint); } @@ -750,24 +699,19 @@ public: accumulator->mAllocatedCount++; } - // reserve 4 bytes for allocation size (and preserving requested alignment) - void* allocation = allocAligned(size); - ((size_t*)allocation)[-1] = size; - - return allocation; + return ::operator new(size); } - void operator delete(void* ptr) + void operator delete(void* ptr, size_t size) { - size_t allocation_size = ((size_t*)ptr)[-1]; MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= allocation_size; + accumulator->mSize -= size; accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } - deallocAligned(ptr); + ::operator delete(ptr); } void *operator new [](size_t size) @@ -779,24 +723,19 @@ public: accumulator->mAllocatedCount++; } - // reserve 4 bytes for allocation size (and preserving requested alignment) - void* allocation = allocAligned(size); - ((size_t*)allocation)[-1] = size; - - return allocation; + return ::operator new[](size); } - void operator delete[](void* ptr) + void operator delete[](void* ptr, size_t size) { - size_t* allocation_size = (size_t*)((char*)ptr - 8); MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); if (accumulator) { - accumulator->mSize -= *allocation_size; + accumulator->mSize -= size; accumulator->mAllocatedCount--; accumulator->mDeallocatedCount++; } - deallocAligned(ptr); + ::operator delete[](ptr); } // claim memory associated with other objects/data as our own, adding to our calculated footprint @@ -853,8 +792,6 @@ public: private: size_t mMemFootprint; - - template struct TrackMemImpl { -- cgit v1.2.3 From 1f507c3cfca0c7722ebeaf71883fbaa83988e1a9 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 21 Mar 2013 00:37:20 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics copied over scene load frame differencing changes from viewer-interesting made periodicrecording flexible enough to allow for indefinite number of periods added scene loading stats floater fixed collapsing behavior of container views --- indra/llcommon/lltracerecording.cpp | 55 +++++++++++++++++++------------------ indra/llcommon/lltracerecording.h | 51 +++++++++++++++++++--------------- indra/llcommon/llunit.h | 8 +++--- 3 files changed, 61 insertions(+), 53 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 259f5a7a27..5d74ea32df 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -355,41 +355,30 @@ U32 Recording::getSampleCount( const TraceType >& st // PeriodicRecording /////////////////////////////////////////////////////////////////////// -PeriodicRecording::PeriodicRecording( S32 num_periods, EPlayState state) -: mNumPeriods(num_periods), +PeriodicRecording::PeriodicRecording( U32 num_periods, EPlayState state) +: mAutoResize(num_periods == 0), mCurPeriod(0), - mTotalValid(false), - mRecordingPeriods( new Recording[num_periods]) + mTotalValid(false) { - llassert(mNumPeriods > 0); - setPlayState(state); -} - -PeriodicRecording::PeriodicRecording(PeriodicRecording& other) -: mNumPeriods(other.mNumPeriods), - mCurPeriod(other.mCurPeriod), - mTotalValid(other.mTotalValid), - mTotalRecording(other.mTotalRecording) -{ - mRecordingPeriods = new Recording[mNumPeriods]; - for (S32 i = 0; i < mNumPeriods; i++) + if (num_periods) { - mRecordingPeriods[i] = other.mRecordingPeriods[i]; + mRecordingPeriods.resize(num_periods); } + setPlayState(state); } - -PeriodicRecording::~PeriodicRecording() -{ - delete[] mRecordingPeriods; -} - - void PeriodicRecording::nextPeriod() { EPlayState play_state = getPlayState(); Recording& old_recording = getCurRecordingPeriod(); - mCurPeriod = (mCurPeriod + 1) % mNumPeriods; + if (mAutoResize) + { + mRecordingPeriods.push_back(Recording()); + } + U32 num_periods = mRecordingPeriods.size(); + mCurPeriod = (num_periods > 0) + ? (mCurPeriod + 1) % num_periods + : mCurPeriod + 1; old_recording.splitTo(getCurRecordingPeriod()); switch(play_state) @@ -412,9 +401,21 @@ Recording& PeriodicRecording::getTotalRecording() if (!mTotalValid) { mTotalRecording.reset(); - for (S32 i = mCurPeriod + 1; i < mCurPeriod + mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + + if (num_periods) + { + for (S32 i = mCurPeriod + 1; i < mCurPeriod + num_periods; i++) + { + mTotalRecording.appendRecording(mRecordingPeriods[i % num_periods]); + } + } + else { - mTotalRecording.appendRecording(mRecordingPeriods[i % mNumPeriods]); + for (S32 i = 0; i < mCurPeriod; i++) + { + mTotalRecording.appendRecording(mRecordingPeriods[i]); + } } } mTotalValid = true; diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 751ff298ce..3e7ed2b592 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -249,16 +249,15 @@ namespace LLTrace : public LLStopWatchControlsMixin { public: - PeriodicRecording(S32 num_periods, EPlayState state = STOPPED); - PeriodicRecording(PeriodicRecording& recording); - ~PeriodicRecording(); + PeriodicRecording(U32 num_periods, EPlayState state = STOPPED); void nextPeriod(); - S32 getNumPeriods() { return mNumPeriods; } + U32 getNumPeriods() { return mRecordingPeriods.size(); } Recording& getLastRecordingPeriod() { - return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; + U32 num_periods = mRecordingPeriods.size(); + return mRecordingPeriods[(mCurPeriod + num_periods - 1) % num_periods]; } const Recording& getLastRecordingPeriod() const @@ -276,16 +275,18 @@ namespace LLTrace return mRecordingPeriods[mCurPeriod]; } - Recording& getPrevRecordingPeriod(S32 offset) + Recording& getPrevRecordingPeriod(U32 offset) { - offset = llclamp(offset, 0, mNumPeriods - 1); - return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; + U32 num_periods = mRecordingPeriods.size(); + offset = llclamp(offset, 0u, num_periods - 1); + return mRecordingPeriods[(mCurPeriod + num_periods - offset) % num_periods]; } - const Recording& getPrevRecordingPeriod(S32 offset) const + const Recording& getPrevRecordingPeriod(U32 offset) const { - offset = llclamp(offset, 0, mNumPeriods - 1); - return mRecordingPeriods[(mCurPeriod + mNumPeriods - offset) % mNumPeriods]; + U32 num_periods = mRecordingPeriods.size(); + offset = llclamp(offset, 0u, num_periods - 1); + return mRecordingPeriods[(mCurPeriod + num_periods - offset) % num_periods]; } Recording snapshotCurRecordingPeriod() const @@ -301,7 +302,8 @@ namespace LLTrace typename T::value_t getPeriodMin(const TraceType& stat) const { typename T::value_t min_val = (std::numeric_limits::max)(); - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { min_val = llmin(min_val, mRecordingPeriods[i].getSum(stat)); } @@ -312,7 +314,8 @@ namespace LLTrace F64 getPeriodMinPerSec(const TraceType& stat) const { F64 min_val = (std::numeric_limits::max)(); - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { min_val = llmin(min_val, mRecordingPeriods[i].getPerSec(stat)); } @@ -323,7 +326,8 @@ namespace LLTrace typename T::value_t getPeriodMax(const TraceType& stat) const { typename T::value_t max_val = (std::numeric_limits::min)(); - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { max_val = llmax(max_val, mRecordingPeriods[i].getSum(stat)); } @@ -334,7 +338,8 @@ namespace LLTrace F64 getPeriodMaxPerSec(const TraceType& stat) const { F64 max_val = (std::numeric_limits::min)(); - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { max_val = llmax(max_val, mRecordingPeriods[i].getPerSec(stat)); } @@ -345,14 +350,15 @@ namespace LLTrace typename MeanValueType >::type getPeriodMean(const TraceType& stat) const { typename MeanValueType >::type mean = 0.0; - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) { mean += mRecordingPeriods[i].getSum(stat); } } - mean /= mNumPeriods; + mean /= num_periods; return mean; } @@ -360,14 +366,15 @@ namespace LLTrace typename MeanValueType >::type getPeriodMeanPerSec(const TraceType& stat) const { typename MeanValueType >::type mean = 0.0; - for (S32 i = 0; i < mNumPeriods; i++) + U32 num_periods = mRecordingPeriods.size(); + for (S32 i = 0; i < num_periods; i++) { if (mRecordingPeriods[i].getDuration() > 0.f) { mean += mRecordingPeriods[i].getPerSec(stat); } } - mean /= mNumPeriods; + mean /= num_periods; return mean; } @@ -382,11 +389,11 @@ namespace LLTrace /*virtual*/ void splitFrom(PeriodicRecording& other); private: - Recording* mRecordingPeriods; + std::vector mRecordingPeriods; Recording mTotalRecording; bool mTotalValid; - S32 mNumPeriods, - mCurPeriod; + const bool mAutoResize; + S32 mCurPeriod; }; PeriodicRecording& get_frame_recording(); diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 823550db5d..f86f111b90 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -143,7 +143,7 @@ struct LLUnit void operator *= (LLUnit multiplicand) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert_template(OTHER_UNIT, 0, "Multiplication of unit types not supported."); + llstatic_assert_template(OTHER_UNIT, false, "Multiplication of unit types not supported."); } void operator /= (storage_t divisor) @@ -155,7 +155,7 @@ struct LLUnit void operator /= (LLUnit divisor) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert_template(OTHER_UNIT, 0, "Illegal in-place division of unit types."); + llstatic_assert_template(OTHER_UNIT, false, "Illegal in-place division of unit types."); } template @@ -315,7 +315,7 @@ template operator * (LLUnit, LLUnit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert_template(STORAGE_TYPE1, 0, "Multiplication of unit types results in new unit type - not supported."); + llstatic_assert_template(STORAGE_TYPE1, false, "Multiplication of unit types results in new unit type - not supported."); return LLUnit(); } @@ -335,7 +335,7 @@ template operator * (LLUnitImplicit, LLUnitImplicit) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert_template(STORAGE_TYPE1, 0, "Multiplication of unit types results in new unit type - not supported."); + llstatic_assert_template(STORAGE_TYPE1, false, "Multiplication of unit types results in new unit type - not supported."); return LLUnitImplicit(); } -- cgit v1.2.3 From 0c63f95b9e1368607126b8d2edbcd91172e61db5 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 21 Mar 2013 17:26:43 -0700 Subject: BUILDFIX fix for gcc build --- indra/llcommon/llcriticaldamp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp index 59a31bf9df..e47ab35641 100644 --- a/indra/llcommon/llcriticaldamp.cpp +++ b/indra/llcommon/llcriticaldamp.cpp @@ -116,5 +116,5 @@ F32 LLSmoothInterpolation::getInterpolant(LLUnit time_con //----------------------------------------------------------------------------- F32 LLSmoothInterpolation::calcInterpolant(F32 time_constant) { - return llclamp(1.f - pow(2.f, -sTimeDelta / time_constant), 0.f, 1.f); + return llclamp(1.f - powf(2.f, -sTimeDelta / time_constant), 0.f, 1.f); } -- cgit v1.2.3 From 368dd542bec7c31e14673b83d3342c35717d2920 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 21 Mar 2013 19:07:48 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics fix for broken pause button on fast timer view --- indra/llcommon/llcriticaldamp.cpp | 2 +- indra/llcommon/lltracerecording.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp index e47ab35641..2f013fe255 100644 --- a/indra/llcommon/llcriticaldamp.cpp +++ b/indra/llcommon/llcriticaldamp.cpp @@ -112,7 +112,7 @@ F32 LLSmoothInterpolation::getInterpolant(LLUnit time_con } //----------------------------------------------------------------------------- -// getInterpolant() +// calcInterpolant() //----------------------------------------------------------------------------- F32 LLSmoothInterpolation::calcInterpolant(F32 time_constant) { diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 5d74ea32df..b70d42b082 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -133,6 +133,9 @@ Recording::Recording() {} Recording::Recording( const Recording& other ) +: RecordingBuffers(other), + mElapsedSeconds(other.mElapsedSeconds), + mSamplingTimer(other.mSamplingTimer) { LLStopWatchControlsMixin::setPlayState(other.getPlayState()); } -- cgit v1.2.3