diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index a99a5588..59ee5f7a 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -666,6 +666,7 @@ static const char TracePipe[] = "trace_pipe"; static std::atomic traceActive { false }; static Thread* s_threadSampling = nullptr; static int s_numCpus = 0; +static int s_numBuffers = 0; static constexpr size_t RingBufSize = 64*1024; static RingBuffer* s_ring = nullptr; @@ -690,6 +691,7 @@ static void SetupSampling( int64_t& samplingPeriod ) s_numCpus = (int)std::thread::hardware_concurrency(); s_ring = (RingBuffer*)tracy_malloc( sizeof( RingBuffer ) * s_numCpus ); + s_numBuffers = 0; perf_event_attr pe = {}; @@ -716,11 +718,12 @@ static void SetupSampling( int64_t& samplingPeriod ) const int fd = perf_event_open( &pe, -1, i, -1, 0 ); if( fd == -1 ) { - for( int j=0; j(); + for( int j=0; j(); tracy_free( s_ring ); return; } - new( s_ring+i ) RingBuffer( fd, EventCallstack ); + new( s_ring+s_numBuffers ) RingBuffer( fd, EventCallstack ); + s_numBuffers++; } s_threadSampling = (Thread*)tracy_malloc( sizeof( Thread ) ); @@ -731,11 +734,11 @@ static void SetupSampling( int64_t& samplingPeriod ) pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp ); uint32_t currentPid = (uint32_t)getpid(); #if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) - for( int i=0; i(); + for( int j=0; j(); tracy_free( s_ring ); const char* err = "Tracy Profiler: sampling is disabled due to non-native scheduler clock. Are you running under a VM?"; Profiler::MessageAppInfo( err, strlen( err ) ); @@ -743,11 +746,11 @@ static void SetupSampling( int64_t& samplingPeriod ) } } #endif - for( int i=0; i(); + for( int i=0; i(); tracy_free( s_ring ); }, nullptr ); }