1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Don't write reference time to memory in each iteration.

This commit is contained in:
Bartosz Taudul 2020-02-22 16:54:02 +01:00
parent ca39c9877e
commit e270603117

View File

@ -1687,6 +1687,9 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
m_refTimeThread = 0; m_refTimeThread = 0;
} }
int64_t refThread = m_refTimeThread;
int64_t refCtx = m_refTimeCtx;
int64_t refGpu = m_refTimeGpu;
auto end = m_itemBuf + sz; auto end = m_itemBuf + sz;
auto item = m_itemBuf; auto item = m_itemBuf;
while( item != end ) while( item != end )
@ -1722,8 +1725,8 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
case QueueType::ZoneBeginAllocSrcLocCallstack: case QueueType::ZoneBeginAllocSrcLocCallstack:
{ {
int64_t t = MemRead<int64_t>( &item->zoneBegin.time ); int64_t t = MemRead<int64_t>( &item->zoneBegin.time );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->zoneBegin.time, dt ); MemWrite( &item->zoneBegin.time, dt );
ptr = MemRead<uint64_t>( &item->zoneBegin.srcloc ); ptr = MemRead<uint64_t>( &item->zoneBegin.srcloc );
SendSourceLocationPayload( ptr ); SendSourceLocationPayload( ptr );
@ -1753,8 +1756,8 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
SendCallstackPayload64( ptr ); SendCallstackPayload64( ptr );
tracy_free( (void*)ptr ); tracy_free( (void*)ptr );
int64_t t = MemRead<int64_t>( &item->callstackSample.time ); int64_t t = MemRead<int64_t>( &item->callstackSample.time );
int64_t dt = t - m_refTimeCtx; int64_t dt = t - refCtx;
m_refTimeCtx = t; refCtx = t;
MemWrite( &item->callstackSample.time, dt ); MemWrite( &item->callstackSample.time, dt );
break; break;
} }
@ -1772,16 +1775,16 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
case QueueType::ZoneBeginCallstack: case QueueType::ZoneBeginCallstack:
{ {
int64_t t = MemRead<int64_t>( &item->zoneBegin.time ); int64_t t = MemRead<int64_t>( &item->zoneBegin.time );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->zoneBegin.time, dt ); MemWrite( &item->zoneBegin.time, dt );
break; break;
} }
case QueueType::ZoneEnd: case QueueType::ZoneEnd:
{ {
int64_t t = MemRead<int64_t>( &item->zoneEnd.time ); int64_t t = MemRead<int64_t>( &item->zoneEnd.time );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->zoneEnd.time, dt ); MemWrite( &item->zoneEnd.time, dt );
break; break;
} }
@ -1789,48 +1792,48 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
case QueueType::GpuZoneBeginCallstack: case QueueType::GpuZoneBeginCallstack:
{ {
int64_t t = MemRead<int64_t>( &item->gpuZoneBegin.cpuTime ); int64_t t = MemRead<int64_t>( &item->gpuZoneBegin.cpuTime );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->gpuZoneBegin.cpuTime, dt ); MemWrite( &item->gpuZoneBegin.cpuTime, dt );
break; break;
} }
case QueueType::GpuZoneEnd: case QueueType::GpuZoneEnd:
{ {
int64_t t = MemRead<int64_t>( &item->gpuZoneEnd.cpuTime ); int64_t t = MemRead<int64_t>( &item->gpuZoneEnd.cpuTime );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->gpuZoneEnd.cpuTime, dt ); MemWrite( &item->gpuZoneEnd.cpuTime, dt );
break; break;
} }
case QueueType::PlotData: case QueueType::PlotData:
{ {
int64_t t = MemRead<int64_t>( &item->plotData.time ); int64_t t = MemRead<int64_t>( &item->plotData.time );
int64_t dt = t - m_refTimeThread; int64_t dt = t - refThread;
m_refTimeThread = t; refThread = t;
MemWrite( &item->plotData.time, dt ); MemWrite( &item->plotData.time, dt );
break; break;
} }
case QueueType::ContextSwitch: case QueueType::ContextSwitch:
{ {
int64_t t = MemRead<int64_t>( &item->contextSwitch.time ); int64_t t = MemRead<int64_t>( &item->contextSwitch.time );
int64_t dt = t - m_refTimeCtx; int64_t dt = t - refCtx;
m_refTimeCtx = t; refCtx = t;
MemWrite( &item->contextSwitch.time, dt ); MemWrite( &item->contextSwitch.time, dt );
break; break;
} }
case QueueType::ThreadWakeup: case QueueType::ThreadWakeup:
{ {
int64_t t = MemRead<int64_t>( &item->threadWakeup.time ); int64_t t = MemRead<int64_t>( &item->threadWakeup.time );
int64_t dt = t - m_refTimeCtx; int64_t dt = t - refCtx;
m_refTimeCtx = t; refCtx = t;
MemWrite( &item->threadWakeup.time, dt ); MemWrite( &item->threadWakeup.time, dt );
break; break;
} }
case QueueType::GpuTime: case QueueType::GpuTime:
{ {
int64_t t = MemRead<int64_t>( &item->gpuTime.gpuTime ); int64_t t = MemRead<int64_t>( &item->gpuTime.gpuTime );
int64_t dt = t - m_refTimeGpu; int64_t dt = t - refGpu;
m_refTimeGpu = t; refGpu = t;
MemWrite( &item->gpuTime.gpuTime, dt ); MemWrite( &item->gpuTime.gpuTime, dt );
break; break;
} }
@ -1842,6 +1845,9 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
if( !AppendData( item, QueueDataSize[idx] ) ) return DequeueStatus::ConnectionLost; if( !AppendData( item, QueueDataSize[idx] ) ) return DequeueStatus::ConnectionLost;
item++; item++;
} }
m_refTimeThread = refThread;
m_refTimeCtx = refCtx;
m_refTimeGpu = refGpu;
} }
else else
{ {
@ -1855,6 +1861,7 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con
const auto sz = GetQueue().try_dequeue_bulk( token, m_itemBuf, BulkSize ); const auto sz = GetQueue().try_dequeue_bulk( token, m_itemBuf, BulkSize );
if( sz > 0 ) if( sz > 0 )
{ {
int64_t refCtx = m_refTimeCtx;
auto end = m_itemBuf + sz; auto end = m_itemBuf + sz;
auto item = m_itemBuf; auto item = m_itemBuf;
while( item != end ) while( item != end )
@ -1869,8 +1876,8 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con
timeStop = -1; timeStop = -1;
return DequeueStatus::DataDequeued; return DequeueStatus::DataDequeued;
} }
int64_t dt = csTime - m_refTimeCtx; int64_t dt = csTime - refCtx;
m_refTimeCtx = csTime; refCtx = csTime;
MemWrite( &item->contextSwitch.time, dt ); MemWrite( &item->contextSwitch.time, dt );
if( !AppendData( item, QueueDataSize[(int)QueueType::ContextSwitch] ) ) return DequeueStatus::ConnectionLost; if( !AppendData( item, QueueDataSize[(int)QueueType::ContextSwitch] ) ) return DequeueStatus::ConnectionLost;
} }
@ -1882,13 +1889,14 @@ Profiler::DequeueStatus Profiler::DequeueContextSwitches( tracy::moodycamel::Con
timeStop = -1; timeStop = -1;
return DequeueStatus::DataDequeued; return DequeueStatus::DataDequeued;
} }
int64_t dt = csTime - m_refTimeCtx; int64_t dt = csTime - refCtx;
m_refTimeCtx = csTime; refCtx = csTime;
MemWrite( &item->threadWakeup.time, dt ); MemWrite( &item->threadWakeup.time, dt );
if( !AppendData( item, QueueDataSize[(int)QueueType::ThreadWakeup] ) ) return DequeueStatus::ConnectionLost; if( !AppendData( item, QueueDataSize[(int)QueueType::ThreadWakeup] ) ) return DequeueStatus::ConnectionLost;
} }
item++; item++;
} }
m_refTimeCtx = refCtx;
} }
else else
{ {
@ -1919,6 +1927,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
const auto sz = m_serialDequeue.size(); const auto sz = m_serialDequeue.size();
if( sz > 0 ) if( sz > 0 )
{ {
int64_t refSerial = m_refTimeSerial;
int64_t refGpu = m_refTimeGpu;
auto item = m_serialDequeue.data(); auto item = m_serialDequeue.data();
auto end = item + sz; auto end = item + sz;
while( item != end ) while( item != end )
@ -1938,8 +1948,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::LockSharedWait: case QueueType::LockSharedWait:
{ {
int64_t t = MemRead<int64_t>( &item->lockWait.time ); int64_t t = MemRead<int64_t>( &item->lockWait.time );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->lockWait.time, dt ); MemWrite( &item->lockWait.time, dt );
break; break;
} }
@ -1947,8 +1957,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::LockSharedObtain: case QueueType::LockSharedObtain:
{ {
int64_t t = MemRead<int64_t>( &item->lockObtain.time ); int64_t t = MemRead<int64_t>( &item->lockObtain.time );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->lockObtain.time, dt ); MemWrite( &item->lockObtain.time, dt );
break; break;
} }
@ -1956,8 +1966,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::LockSharedRelease: case QueueType::LockSharedRelease:
{ {
int64_t t = MemRead<int64_t>( &item->lockRelease.time ); int64_t t = MemRead<int64_t>( &item->lockRelease.time );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->lockRelease.time, dt ); MemWrite( &item->lockRelease.time, dt );
break; break;
} }
@ -1965,8 +1975,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::MemAllocCallstack: case QueueType::MemAllocCallstack:
{ {
int64_t t = MemRead<int64_t>( &item->memAlloc.time ); int64_t t = MemRead<int64_t>( &item->memAlloc.time );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->memAlloc.time, dt ); MemWrite( &item->memAlloc.time, dt );
break; break;
} }
@ -1974,8 +1984,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::MemFreeCallstack: case QueueType::MemFreeCallstack:
{ {
int64_t t = MemRead<int64_t>( &item->memFree.time ); int64_t t = MemRead<int64_t>( &item->memFree.time );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->memFree.time, dt ); MemWrite( &item->memFree.time, dt );
break; break;
} }
@ -1983,24 +1993,24 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
case QueueType::GpuZoneBeginCallstackSerial: case QueueType::GpuZoneBeginCallstackSerial:
{ {
int64_t t = MemRead<int64_t>( &item->gpuZoneBegin.cpuTime ); int64_t t = MemRead<int64_t>( &item->gpuZoneBegin.cpuTime );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->gpuZoneBegin.cpuTime, dt ); MemWrite( &item->gpuZoneBegin.cpuTime, dt );
break; break;
} }
case QueueType::GpuZoneEndSerial: case QueueType::GpuZoneEndSerial:
{ {
int64_t t = MemRead<int64_t>( &item->gpuZoneEnd.cpuTime ); int64_t t = MemRead<int64_t>( &item->gpuZoneEnd.cpuTime );
int64_t dt = t - m_refTimeSerial; int64_t dt = t - refSerial;
m_refTimeSerial = t; refSerial = t;
MemWrite( &item->gpuZoneEnd.cpuTime, dt ); MemWrite( &item->gpuZoneEnd.cpuTime, dt );
break; break;
} }
case QueueType::GpuTime: case QueueType::GpuTime:
{ {
int64_t t = MemRead<int64_t>( &item->gpuTime.gpuTime ); int64_t t = MemRead<int64_t>( &item->gpuTime.gpuTime );
int64_t dt = t - m_refTimeGpu; int64_t dt = t - refGpu;
m_refTimeGpu = t; refGpu = t;
MemWrite( &item->gpuTime.gpuTime, dt ); MemWrite( &item->gpuTime.gpuTime, dt );
break; break;
} }
@ -2012,6 +2022,8 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
if( !AppendData( item, QueueDataSize[idx] ) ) return DequeueStatus::ConnectionLost; if( !AppendData( item, QueueDataSize[idx] ) ) return DequeueStatus::ConnectionLost;
item++; item++;
} }
m_refTimeSerial = refSerial;
m_refTimeGpu = refGpu;
m_serialDequeue.clear(); m_serialDequeue.clear();
} }
else else