diff options
author | Richard Linden <none@none> | 2012-10-01 19:39:04 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2012-10-01 19:39:04 -0700 |
commit | 14b1b0b2bb6bac5bc688cc4d14c33f1b680dd3b4 (patch) | |
tree | 74942f4fef955b5a55031650146e745bbc4ccd6f /indra/llcommon/lltrace.cpp | |
parent | b1baf982b1bd41a150233d0a28d3601226924c65 (diff) |
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
Diffstat (limited to 'indra/llcommon/lltrace.cpp')
-rw-r--r-- | indra/llcommon/lltrace.cpp | 108 |
1 files changed, 47 insertions, 61 deletions
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<ThreadTrace>& get_thread_trace() +{ + static LLThreadLocalPointer<ThreadTrace> 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<Sampler*>::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<Sampler*>::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<Sampler*>::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; -} - } |