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

RingBuffer has const size, so use template.

This eliminates division.
This commit is contained in:
Bartosz Taudul
2020-08-15 02:43:18 +02:00
parent caa1b1a792
commit 28aae73f74
2 changed files with 17 additions and 16 deletions
+8 -6
View File
@@ -620,7 +620,9 @@ static const char TracePipe[] = "trace_pipe";
static std::atomic<bool> traceActive { false };
static Thread* s_threadSampling = nullptr;
static int s_numCpus = 0;
static RingBuffer* s_ring = nullptr;
static constexpr size_t RingBufSize = 64*1024;
static RingBuffer<RingBufSize>* s_ring = nullptr;
static int perf_event_open( struct perf_event_attr* hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags )
{
@@ -636,7 +638,7 @@ static void SetupSampling( int64_t& samplingPeriod )
samplingPeriod = 100*1000;
s_numCpus = (int)std::thread::hardware_concurrency();
s_ring = (RingBuffer*)tracy_malloc( sizeof( RingBuffer ) * s_numCpus );
s_ring = (RingBuffer<RingBufSize>*)tracy_malloc( sizeof( RingBuffer<RingBufSize> ) * s_numCpus );
perf_event_attr pe = {};
@@ -661,11 +663,11 @@ 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<i; j++ ) s_ring[j].~RingBuffer();
for( int j=0; j<i; j++ ) s_ring[j].~RingBuffer<RingBufSize>();
tracy_free( s_ring );
return;
}
new( s_ring+i ) RingBuffer( 64*1024, fd );
new( s_ring+i ) RingBuffer<RingBufSize>( fd );
}
s_threadSampling = (Thread*)tracy_malloc( sizeof( Thread ) );
@@ -680,7 +682,7 @@ static void SetupSampling( int64_t& samplingPeriod )
{
if( !s_ring[i].CheckTscCaps() )
{
for( int j=0; j<s_numCpus; j++ ) s_ring[j].~RingBuffer();
for( int j=0; j<s_numCpus; j++ ) s_ring[j].~RingBuffer<RingBufSize>();
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 ) );
@@ -760,7 +762,7 @@ static void SetupSampling( int64_t& samplingPeriod )
}
}
for( int i=0; i<s_numCpus; i++ ) s_ring[i].~RingBuffer();
for( int i=0; i<s_numCpus; i++ ) s_ring[i].~RingBuffer<RingBufSize>();
tracy_free( s_ring );
}, nullptr );
}