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 -------------------- indra/llui/llstatbar.cpp | 20 ++-- indra/llui/llstatgraph.cpp | 8 +- indra/newview/llappviewer.cpp | 2 +- indra/newview/llviewerstats.cpp | 3 +- indra/newview/llviewerstats.h | 7 +- indra/newview/llviewertexturelist.cpp | 4 +- 17 files changed, 419 insertions(+), 427 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') 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 diff --git a/indra/llui/llstatbar.cpp b/indra/llui/llstatbar.cpp index 1f8be3da62..bc9603804b 100644 --- a/indra/llui/llstatbar.cpp +++ b/indra/llui/llstatbar.cpp @@ -36,7 +36,7 @@ #include "llstat.h" #include "lluictrlfactory.h" -#include "lltracesampler.h" +#include "lltracerecording.h" /////////////////////////////////////////////////////////////////////////////////// @@ -111,20 +111,20 @@ void LLStatBar::draw() } else if (mFloatStatp) { - LLTrace::Sampler* sampler = LLTrace::get_thread_trace()->getPrimarySampler(); + LLTrace::Recording* recording = LLTrace::get_thread_recorder()->getPrimaryRecording(); if (mPerSec) { - current = sampler->getSum(*mFloatStatp) / sampler->getSampleTime(); - //min = sampler->getMin(*mFloatStatp) / sampler->getSampleTime(); - //max = sampler->getMax(*mFloatStatp) / sampler->getSampleTime(); - //mean = sampler->getMean(*mFloatStatp) / sampler->getSampleTime(); + current = recording->getSum(*mFloatStatp) / recording->getSampleTime(); + //min = recording->getMin(*mFloatStatp) / recording->getSampleTime(); + //max = recording->getMax(*mFloatStatp) / recording->getSampleTime(); + //mean = recording->getMean(*mFloatStatp) / recording->getSampleTime(); } else { - current = sampler->getSum(*mFloatStatp); - //min = sampler->getMin(*mFloatStatp); - //max = sampler->getMax(*mFloatStatp); - //mean = sampler->getMean(*mFloatStatp); + current = recording->getSum(*mFloatStatp); + //min = recording->getMin(*mFloatStatp); + //max = recording->getMax(*mFloatStatp); + //mean = recording->getMean(*mFloatStatp); } } diff --git a/indra/llui/llstatgraph.cpp b/indra/llui/llstatgraph.cpp index e0d7623999..aed9e4ec93 100644 --- a/indra/llui/llstatgraph.cpp +++ b/indra/llui/llstatgraph.cpp @@ -35,7 +35,7 @@ #include "llstat.h" #include "llgl.h" #include "llglheaders.h" -#include "lltracesampler.h" +#include "lltracerecording.h" //#include "llviewercontrol.h" /////////////////////////////////////////////////////////////////////////////////// @@ -85,15 +85,15 @@ void LLStatGraph::draw() } else if (mF32Statp) { - LLTrace::Sampler* sampler = LLTrace::get_thread_trace()->getPrimarySampler(); + LLTrace::Recording* recording = LLTrace::get_thread_recorder()->getPrimaryRecording(); if (mPerSec) { - mValue = sampler->getSum(*mF32Statp) / sampler->getSampleTime(); + mValue = recording->getSum(*mF32Statp) / recording->getSampleTime(); } else { - mValue = sampler->getSum(*mF32Statp); + mValue = recording->getSum(*mF32Statp); } } diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 0bb87dfa6c..22f3cce9e8 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -1222,7 +1222,7 @@ bool LLAppViewer::mainLoop() { LLFastTimer _(FTM_FRAME); LLFastTimer::nextFrame(); - LLTrace::getMasterThreadTrace().pullFromSlaveThreads(); + LLTrace::getMasterThreadRecorder().pullFromSlaveThreads(); //clear call stack records llclearcallstacks; diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp index e2b09a1902..a6e9643edd 100755 --- a/indra/newview/llviewerstats.cpp +++ b/indra/newview/llviewerstats.cpp @@ -276,12 +276,11 @@ LLViewerStats::LLViewerStats() : } mAgentPositionSnaps.reset(); - mSampler->start(); + mRecording.start(); } LLViewerStats::~LLViewerStats() { - delete mSampler; } void LLViewerStats::resetStats() diff --git a/indra/newview/llviewerstats.h b/indra/newview/llviewerstats.h index 9e809dd08c..ca5f6c6821 100755 --- a/indra/newview/llviewerstats.h +++ b/indra/newview/llviewerstats.h @@ -29,7 +29,8 @@ #include "llstat.h" #include "lltextureinfo.h" -#include "lltracesampler.h" +#include "lltracerecording.h" +#include "lltrace.h" extern LLTrace::Rate STAT_KBIT, STAT_LAYERS_KBIT, @@ -297,11 +298,11 @@ public: static void recordPhaseStat(const std::string& phase_name, F32 value); }; - LLTrace::Sampler* getSampler() { return mSampler; } + LLTrace::Recording& getRecording() { return mRecording; } private: F64 mStats[ST_COUNT]; - LLTrace::Sampler* mSampler; + LLTrace::Recording mRecording; F64 mLastTimeDiff; // used for time stat updates }; diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index 21a83b1676..4e62cbd714 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -622,9 +622,9 @@ void LLViewerTextureList::updateImages(F32 max_time) } cleared = FALSE; - LLTrace::Sampler* sampler = LLTrace::getThreadTrace()->getPrimarySampler(); + LLTrace::Recording* recording = LLTrace::get_thread_recorder()->getPrimaryRecording(); - LLAppViewer::getTextureFetch()->setTextureBandwidth(sampler->getMean(STAT_TEXTURE_KBIT) / sampler->getSampleTime()); + LLAppViewer::getTextureFetch()->setTextureBandwidth(recording->getPerSec(STAT_TEXTURE_KBIT)); LLViewerStats::getInstance()->mNumImagesStat.addValue(sNumImages); LLViewerStats::getInstance()->mNumRawImagesStat.addValue(LLImageRaw::sRawImageCount); -- cgit v1.2.3