Cache ThreadData pointer for current thread context.

This commit is contained in:
Bartosz Taudul 2019-11-10 17:17:07 +01:00
parent ded49edf4c
commit b1c88cd1f2
2 changed files with 11 additions and 19 deletions

View File

@ -2841,7 +2841,8 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
CountZoneStatistics( zone );
#endif
auto td = NoticeThread( thread );
auto td = m_threadCtxData;
if( !td ) td = m_threadCtxData = NoticeThread( thread );
td->count++;
if( td->stack.empty() )
{
@ -3519,8 +3520,12 @@ bool Worker::Process( const QueueItem& ev )
void Worker::ProcessThreadContext( const QueueThreadContext& ev )
{
m_threadCtx = ev.thread;
m_refTimeThread = 0;
if( m_threadCtx != ev.thread )
{
m_threadCtx = ev.thread;
m_threadCtxData = RetrieveThread( ev.thread );
}
}
void Worker::ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev )
@ -3594,12 +3599,8 @@ void Worker::ProcessZoneBeginAllocSrcLocCallstack( const QueueZoneBegin& ev )
void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
{
auto td = RetrieveThread( m_threadCtx );
if( !td )
{
ZoneEndFailure( m_threadCtx );
return;
}
auto td = m_threadCtxData;
assert( td );
auto zoneId = td->zoneIdStack.back_and_pop();
if( zoneId != td->nextZoneId )
@ -3669,13 +3670,6 @@ void Worker::ZoneStackFailure( uint64_t thread, const ZoneEvent* ev )
m_failureData.srcloc = ev->SrcLoc();
}
void Worker::ZoneEndFailure( uint64_t thread )
{
m_failure = Failure::ZoneEnd;
m_failureData.thread = thread;
m_failureData.srcloc = 0;
}
void Worker::ZoneTextFailure( uint64_t thread )
{
m_failure = Failure::ZoneText;
@ -3699,7 +3693,7 @@ void Worker::MemFreeFailure( uint64_t thread )
void Worker::FrameEndFailure()
{
m_failure = Failure::ZoneEnd;
m_failure = Failure::FrameEnd;
m_failureData.thread = 0;
m_failureData.srcloc = 0;
}
@ -5941,7 +5935,6 @@ void Worker::WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime, in
static const char* s_failureReasons[] = {
"<unknown reason>",
"Invalid order of zone begin and end events.",
"Received zone end event without a matching zone begin event.",
"Zone text transfer destination doesn't match active zone.",
"Zone name transfer destination doesn't match active zone.",
"Memory free event without a matching allocation.",

View File

@ -275,7 +275,6 @@ public:
{
None,
ZoneStack,
ZoneEnd,
ZoneText,
ZoneName,
MemFree,
@ -481,7 +480,6 @@ private:
tracy_force_inline void ProcessGpuZoneBeginImpl( GpuEvent* zone, const QueueGpuZoneBegin& ev, bool serial );
void ZoneStackFailure( uint64_t thread, const ZoneEvent* ev );
void ZoneEndFailure( uint64_t thread );
void ZoneTextFailure( uint64_t thread );
void ZoneNameFailure( uint64_t thread );
void MemFreeFailure( uint64_t thread );
@ -680,6 +678,7 @@ private:
size_t m_frameImageCompressedBufferSize = 0;
uint64_t m_threadCtx = 0;
ThreadData* m_threadCtxData = nullptr;
int64_t m_refTimeThread = 0;
int64_t m_refTimeSerial = 0;
int64_t m_refTimeCtx = 0;