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