summaryrefslogtreecommitdiff
path: root/indra/llcommon/lltracethreadrecorder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/lltracethreadrecorder.cpp')
-rw-r--r--indra/llcommon/lltracethreadrecorder.cpp71
1 files changed, 45 insertions, 26 deletions
diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp
index e131af5f16..9dac4f6771 100644
--- a/indra/llcommon/lltracethreadrecorder.cpp
+++ b/indra/llcommon/lltracethreadrecorder.cpp
@@ -27,9 +27,11 @@
#include "lltracethreadrecorder.h"
#include "llfasttimer.h"
+#include "lltrace.h"
namespace LLTrace
{
+extern MemStatHandle gTraceMemStat;
static ThreadRecorder* sMasterThreadRecorder = NULL;
@@ -55,6 +57,7 @@ void ThreadRecorder::init()
timer_stack->mActiveTimer = NULL;
mNumTimeBlockTreeNodes = AccumulatorBuffer<TimeBlockAccumulator>::getDefaultBuffer()->size();
+
mTimeBlockTreeNodes = new TimeBlockTreeNode[mNumTimeBlockTreeNodes];
activate(&mThreadRecordingBuffers);
@@ -76,10 +79,14 @@ void ThreadRecorder::init()
timer_stack->mActiveTimer = mRootTimer;
TimeBlock::getRootTimeBlock().getCurrentAccumulator().mActiveCount = 1;
+
+ claim_alloc(gTraceMemStat, this);
+ claim_alloc(gTraceMemStat, sizeof(BlockTimer));
+ claim_alloc(gTraceMemStat, sizeof(TimeBlockTreeNode) * mNumTimeBlockTreeNodes);
}
-ThreadRecorder::ThreadRecorder(ThreadRecorder& master)
+ThreadRecorder::ThreadRecorder( ThreadRecorder& master )
: mMasterRecorder(&master)
{
init();
@@ -91,6 +98,10 @@ ThreadRecorder::~ThreadRecorder()
{
LLThreadLocalSingletonPointer<BlockTimerStackRecord>::setInstance(NULL);
+ disclaim_alloc(gTraceMemStat, this);
+ disclaim_alloc(gTraceMemStat, sizeof(BlockTimer));
+ disclaim_alloc(gTraceMemStat, sizeof(TimeBlockTreeNode) * mNumTimeBlockTreeNodes);
+
deactivate(&mThreadRecordingBuffers);
delete mRootTimer;
@@ -135,9 +146,9 @@ void ThreadRecorder::activate( AccumulatorBufferGroup* recording, bool from_hand
mActiveRecordings.back()->mPartialRecording.makeCurrent();
}
-ThreadRecorder::active_recording_list_t::reverse_iterator ThreadRecorder::bringUpToDate( AccumulatorBufferGroup* recording )
+ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::bringUpToDate( AccumulatorBufferGroup* recording )
{
- if (mActiveRecordings.empty()) return mActiveRecordings.rend();
+ if (mActiveRecordings.empty()) return mActiveRecordings.end();
mActiveRecordings.back()->mPartialRecording.sync();
TimeBlock::updateTimes();
@@ -174,19 +185,18 @@ ThreadRecorder::active_recording_list_t::reverse_iterator ThreadRecorder::bringU
LL_WARNS() << "Recording not active on this thread" << LL_ENDL;
}
- return it;
+ return (++it).base();
}
void ThreadRecorder::deactivate( AccumulatorBufferGroup* recording )
{
- active_recording_list_t::reverse_iterator it = bringUpToDate(recording);
- if (it != mActiveRecordings.rend())
+ active_recording_list_t::iterator recording_it = bringUpToDate(recording);
+ if (recording_it != mActiveRecordings.end())
{
- active_recording_list_t::iterator recording_to_remove = (++it).base();
- bool was_current = (*recording_to_remove)->mPartialRecording.isCurrent();
- llassert((*recording_to_remove)->mTargetRecording == recording);
- delete *recording_to_remove;
- mActiveRecordings.erase(recording_to_remove);
+ ActiveRecording* recording_to_remove = *recording_it;
+ bool was_current = recording_to_remove->mPartialRecording.isCurrent();
+ llassert(recording_to_remove->mTargetRecording == recording);
+ mActiveRecordings.erase(recording_it);
if (was_current)
{
if (mActiveRecordings.empty())
@@ -198,6 +208,7 @@ void ThreadRecorder::deactivate( AccumulatorBufferGroup* recording )
mActiveRecordings.back()->mPartialRecording.makeCurrent();
}
}
+ delete recording_to_remove;
}
}
@@ -216,25 +227,33 @@ void ThreadRecorder::ActiveRecording::movePartialToTarget()
// called by child thread
void ThreadRecorder::addChildRecorder( class ThreadRecorder* child )
-{ LLMutexLock lock(&mChildListMutex);
- mChildThreadRecorders.push_back(child);
+{
+ { LLMutexLock lock(&mChildListMutex);
+ mChildThreadRecorders.push_back(child);
+ }
}
// called by child thread
void ThreadRecorder::removeChildRecorder( class ThreadRecorder* child )
-{ LLMutexLock lock(&mChildListMutex);
-
-for (child_thread_recorder_list_t::iterator it = mChildThreadRecorders.begin(), end_it = mChildThreadRecorders.end();
- it != end_it;
- ++it)
-{
- if ((*it) == child)
- {
- mChildThreadRecorders.erase(it);
- break;
+{
+ { LLMutexLock lock(&mChildListMutex);
+ for (child_thread_recorder_list_t::iterator it = mChildThreadRecorders.begin(), end_it = mChildThreadRecorders.end();
+ it != end_it;
+ ++it)
+ {
+ if ((*it) == child)
+ {
+ // FIXME: this won't do any good, as the child stores the "pushed" values internally
+ // and it is in the process of being deleted.
+ // We need a way to finalize the stats from the outgoing thread, but the storage
+ // for those stats needs to be outside the child's thread recorder
+ //(*it)->pushToParent();
+ mChildThreadRecorders.erase(it);
+ break;
+ }
+ }
}
}
-}
void ThreadRecorder::pushToParent()
{
@@ -269,7 +288,7 @@ void ThreadRecorder::pullFromChildren()
}
-void set_master_thread_recorder(ThreadRecorder* recorder)
+void set_master_thread_recorder( ThreadRecorder* recorder )
{
sMasterThreadRecorder = recorder;
}
@@ -291,7 +310,7 @@ const LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder()
return get_thread_recorder_ptr();
}
-void set_thread_recorder(ThreadRecorder* recorder)
+void set_thread_recorder( ThreadRecorder* recorder )
{
get_thread_recorder_ptr() = recorder;
}