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

Load globals to local variables.

This commit is contained in:
Bartosz Taudul 2022-08-18 01:08:22 +02:00
parent d62f7d5d13
commit 07a56f1148
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -1128,16 +1128,19 @@ void SysTraceWorker( void* ptr )
InitRpmalloc(); InitRpmalloc();
sched_param sp = { 99 }; sched_param sp = { 99 };
if( pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp ) != 0 ) TracyDebug( "Failed to increase SysTraceWorker thread priority!\n" ); if( pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp ) != 0 ) TracyDebug( "Failed to increase SysTraceWorker thread priority!\n" );
for( int i=0; i<s_numBuffers; i++ ) s_ring[i].Enable(); auto ctxBufferIdx = s_ctxBufferIdx;
auto ringArray = s_ring;
auto numBuffers = s_numBuffers;
for( int i=0; i<numBuffers; i++ ) ringArray[i].Enable();
for(;;) for(;;)
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) if( !GetProfiler().IsConnected() )
{ {
if( !traceActive.load( std::memory_order_relaxed ) ) break; if( !traceActive.load( std::memory_order_relaxed ) ) break;
for( int i=0; i<s_numBuffers; i++ ) for( int i=0; i<numBuffers; i++ )
{ {
auto& ring = s_ring[i]; auto& ring = ringArray[i];
const auto head = ring.LoadHead(); const auto head = ring.LoadHead();
const auto tail = ring.GetTail(); const auto tail = ring.GetTail();
if( head != tail ) if( head != tail )
@ -1153,10 +1156,10 @@ void SysTraceWorker( void* ptr )
#endif #endif
bool hadData = false; bool hadData = false;
for( int i=0; i<s_ctxBufferIdx; i++ ) for( int i=0; i<ctxBufferIdx; i++ )
{ {
if( !traceActive.load( std::memory_order_relaxed ) ) break; if( !traceActive.load( std::memory_order_relaxed ) ) break;
auto& ring = s_ring[i]; auto& ring = ringArray[i];
const auto head = ring.LoadHead(); const auto head = ring.LoadHead();
const auto tail = ring.GetTail(); const auto tail = ring.GetTail();
if( head == tail ) continue; if( head == tail ) continue;
@ -1273,9 +1276,9 @@ void SysTraceWorker( void* ptr )
} }
if( !traceActive.load( std::memory_order_relaxed ) ) break; if( !traceActive.load( std::memory_order_relaxed ) ) break;
if( s_ctxBufferIdx != s_numBuffers ) if( ctxBufferIdx != numBuffers )
{ {
const auto ctxBufNum = s_numBuffers - s_ctxBufferIdx; const auto ctxBufNum = numBuffers - ctxBufferIdx;
int activeNum = 0; int activeNum = 0;
bool active[512]; bool active[512];
@ -1283,9 +1286,9 @@ void SysTraceWorker( void* ptr )
uint32_t pos[512]; uint32_t pos[512];
for( int i=0; i<ctxBufNum; i++ ) for( int i=0; i<ctxBufNum; i++ )
{ {
const auto rbIdx = s_ctxBufferIdx + i; const auto rbIdx = ctxBufferIdx + i;
const auto rbHead = s_ring[rbIdx].LoadHead(); const auto rbHead = ringArray[rbIdx].LoadHead();
const auto rbTail = s_ring[rbIdx].GetTail(); const auto rbTail = ringArray[rbIdx].GetTail();
const auto rbActive = rbHead != rbTail; const auto rbActive = rbHead != rbTail;
active[i] = rbActive; active[i] = rbActive;
@ -1312,13 +1315,13 @@ void SysTraceWorker( void* ptr )
if( !active[i] ) continue; if( !active[i] ) continue;
auto rbPos = pos[i]; auto rbPos = pos[i];
assert( rbPos < end[i] ); assert( rbPos < end[i] );
const auto rbIdx = s_ctxBufferIdx + i; const auto rbIdx = ctxBufferIdx + i;
perf_event_header hdr; perf_event_header hdr;
s_ring[rbIdx].Read( &hdr, rbPos, sizeof( perf_event_header ) ); ringArray[rbIdx].Read( &hdr, rbPos, sizeof( perf_event_header ) );
if( hdr.type == PERF_RECORD_SAMPLE ) if( hdr.type == PERF_RECORD_SAMPLE )
{ {
int64_t rbTime; int64_t rbTime;
s_ring[rbIdx].Read( &rbTime, rbPos + sizeof( perf_event_header ), sizeof( int64_t ) ); ringArray[rbIdx].Read( &rbTime, rbPos + sizeof( perf_event_header ), sizeof( int64_t ) );
if( rbTime < t0 ) if( rbTime < t0 )
{ {
t0 = rbTime; t0 = rbTime;
@ -1341,7 +1344,7 @@ void SysTraceWorker( void* ptr )
} }
if( sel >= 0 ) if( sel >= 0 )
{ {
auto& ring = s_ring[s_ctxBufferIdx + sel]; auto& ring = ringArray[ctxBufferIdx + sel];
auto rbPos = pos[sel]; auto rbPos = pos[sel];
auto offset = rbPos; auto offset = rbPos;
perf_event_header hdr; perf_event_header hdr;
@ -1492,7 +1495,7 @@ void SysTraceWorker( void* ptr )
} }
for( int i=0; i<ctxBufNum; i++ ) for( int i=0; i<ctxBufNum; i++ )
{ {
if( end[i] != 0 ) s_ring[s_ctxBufferIdx + i].Advance( end[i] ); if( end[i] != 0 ) ringArray[ctxBufferIdx + i].Advance( end[i] );
} }
} }
} }
@ -1503,8 +1506,8 @@ void SysTraceWorker( void* ptr )
} }
} }
for( int i=0; i<s_numBuffers; i++ ) s_ring[i].~RingBuffer(); for( int i=0; i<numBuffers; i++ ) ringArray[i].~RingBuffer();
tracy_free_fast( s_ring ); tracy_free_fast( ringArray );
} }
void SysTraceGetExternalName( uint64_t thread, const char*& threadName, const char*& name ) void SysTraceGetExternalName( uint64_t thread, const char*& threadName, const char*& name )