Skip to content
Snippets Groups Projects
Commit a712aab6 authored by Richard Linden's avatar Richard Linden
Browse files

added some defensive asserts in lltrace to make cases of misuse more obvious when it crashes

parent 3455bf95
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,9 @@ Recording::~Recording() ...@@ -88,6 +88,9 @@ Recording::~Recording()
disclaim_alloc(gTraceMemStat, this); disclaim_alloc(gTraceMemStat, this);
disclaim_alloc(gTraceMemStat, mBuffers); disclaim_alloc(gTraceMemStat, mBuffers);
// allow recording destruction without thread recorder running,
// otherwise thread shutdown could crash if a recording outlives the thread recorder
// besides, recording construction and destruction is fine without a recorder...just don't attempt to start one
if (isStarted() && LLTrace::get_thread_recorder().notNull()) if (isStarted() && LLTrace::get_thread_recorder().notNull())
{ {
LLTrace::get_thread_recorder()->deactivate(mBuffers.write()); LLTrace::get_thread_recorder()->deactivate(mBuffers.write());
...@@ -101,7 +104,10 @@ void Recording::update() ...@@ -101,7 +104,10 @@ void Recording::update()
{ {
mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); mElapsedSeconds += mSamplingTimer.getElapsedTimeF64();
llassert(mActiveBuffers); // must have
llassert(mActiveBuffers != NULL
&& LLTrace::get_thread_recorder().notNull());
if(!mActiveBuffers->isCurrent()) if(!mActiveBuffers->isCurrent())
{ {
AccumulatorBufferGroup* buffers = mBuffers.write(); AccumulatorBufferGroup* buffers = mBuffers.write();
...@@ -125,12 +131,16 @@ void Recording::handleStart() ...@@ -125,12 +131,16 @@ void Recording::handleStart()
{ {
mSamplingTimer.reset(); mSamplingTimer.reset();
mBuffers.setStayUnique(true); mBuffers.setStayUnique(true);
// must have thread recorder running on this thread
llassert(LLTrace::get_thread_recorder().notNull());
mActiveBuffers = LLTrace::get_thread_recorder()->activate(mBuffers.write()); mActiveBuffers = LLTrace::get_thread_recorder()->activate(mBuffers.write());
} }
void Recording::handleStop() void Recording::handleStop()
{ {
mElapsedSeconds += mSamplingTimer.getElapsedTimeF64(); mElapsedSeconds += mSamplingTimer.getElapsedTimeF64();
// must have thread recorder running on this thread
llassert(LLTrace::get_thread_recorder().notNull());
LLTrace::get_thread_recorder()->deactivate(mBuffers.write()); LLTrace::get_thread_recorder()->deactivate(mBuffers.write());
mActiveBuffers = NULL; mActiveBuffers = NULL;
mBuffers.setStayUnique(false); mBuffers.setStayUnique(false);
......
...@@ -191,25 +191,25 @@ ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::bringUpToDate( ...@@ -191,25 +191,25 @@ ThreadRecorder::active_recording_list_t::iterator ThreadRecorder::bringUpToDate(
void ThreadRecorder::deactivate( AccumulatorBufferGroup* recording ) void ThreadRecorder::deactivate( AccumulatorBufferGroup* recording )
{ {
active_recording_list_t::iterator recording_it = bringUpToDate(recording); active_recording_list_t::iterator recording_it = bringUpToDate(recording);
if (recording_it != mActiveRecordings.end()) // this method should only be called on a thread where the recorder is active
llassert_always(recording_it != mActiveRecordings.end());
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)
{ {
ActiveRecording* recording_to_remove = *recording_it; if (mActiveRecordings.empty())
bool was_current = recording_to_remove->mPartialRecording.isCurrent();
llassert(recording_to_remove->mTargetRecording == recording);
mActiveRecordings.erase(recording_it);
if (was_current)
{ {
if (mActiveRecordings.empty()) AccumulatorBufferGroup::clearCurrent();
{ }
AccumulatorBufferGroup::clearCurrent(); else
} {
else mActiveRecordings.back()->mPartialRecording.makeCurrent();
{
mActiveRecordings.back()->mPartialRecording.makeCurrent();
}
} }
delete recording_to_remove;
} }
delete recording_to_remove;
} }
ThreadRecorder::ActiveRecording::ActiveRecording( AccumulatorBufferGroup* target ) ThreadRecorder::ActiveRecording::ActiveRecording( AccumulatorBufferGroup* target )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment