Don't require time to be available for samples.

This commit is contained in:
Bartosz Taudul 2021-12-02 01:29:22 +01:00
parent 051b1ba8f5
commit 74e2a63516
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -928,20 +928,6 @@ static void SetupSampling( int64_t& samplingPeriod )
InitRpmalloc(); InitRpmalloc();
sched_param sp = { 5 }; sched_param sp = { 5 };
pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp ); pthread_setschedparam( pthread_self(), SCHED_FIFO, &sp );
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
for( int i=0; i<s_numBuffers; i++ )
{
if( s_ring[i].GetId() == EventCallstack && !s_ring[i].CheckTscCaps() )
{
for( int j=0; j<s_numBuffers; j++ ) s_ring[j].~RingBuffer<RingBufSize>();
tracy_free_fast( s_ring );
const char* err = "Tracy Profiler: sampling is disabled due to non-native scheduler clock. Are you running under a VM?";
TracyDebug( err );
Profiler::MessageAppInfo( err, strlen( err ) );
return;
}
}
#endif
for( int i=0; i<s_numBuffers; i++ ) s_ring[i].Enable(); for( int i=0; i<s_numBuffers; i++ ) s_ring[i].Enable();
for(;;) for(;;)
{ {
@ -990,48 +976,45 @@ static void SetupSampling( int64_t& samplingPeriod )
{ {
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) #if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
t0 = ring.ConvertTimeToTsc( t0 ); t0 = ring.ConvertTimeToTsc( t0 );
if( t0 != 0 )
#endif #endif
{ auto trace = (uint64_t*)tracy_malloc_fast( ( 1 + cnt ) * sizeof( uint64_t ) );
auto trace = (uint64_t*)tracy_malloc_fast( ( 1 + cnt ) * sizeof( uint64_t ) ); ring.Read( trace+1, offset, sizeof( uint64_t ) * cnt );
ring.Read( trace+1, offset, sizeof( uint64_t ) * cnt );
#if defined __x86_64__ || defined _M_X64 #if defined __x86_64__ || defined _M_X64
// remove non-canonical pointers // remove non-canonical pointers
do do
{ {
const auto test = (int64_t)trace[cnt]; const auto test = (int64_t)trace[cnt];
const auto m1 = test >> 63; const auto m1 = test >> 63;
const auto m2 = test >> 47; const auto m2 = test >> 47;
if( m1 == m2 ) break; if( m1 == m2 ) break;
} }
while( --cnt > 0 ); while( --cnt > 0 );
for( uint64_t j=1; j<cnt; j++ ) for( uint64_t j=1; j<cnt; j++ )
{ {
const auto test = (int64_t)trace[j]; const auto test = (int64_t)trace[j];
const auto m1 = test >> 63; const auto m1 = test >> 63;
const auto m2 = test >> 47; const auto m2 = test >> 47;
if( m1 != m2 ) trace[j] = 0; if( m1 != m2 ) trace[j] = 0;
} }
#endif #endif
for( uint64_t j=1; j<=cnt; j++ ) for( uint64_t j=1; j<=cnt; j++ )
{
if( trace[j] >= (uint64_t)-4095 ) // PERF_CONTEXT_MAX
{ {
if( trace[j] >= (uint64_t)-4095 ) // PERF_CONTEXT_MAX memmove( trace+j, trace+j+1, sizeof( uint64_t ) * ( cnt - j ) );
{ cnt--;
memmove( trace+j, trace+j+1, sizeof( uint64_t ) * ( cnt - j ) );
cnt--;
}
} }
memcpy( trace, &cnt, sizeof( uint64_t ) );
TracyLfqPrepare( QueueType::CallstackSample );
MemWrite( &item->callstackSampleFat.time, t0 );
MemWrite( &item->callstackSampleFat.thread, tid );
MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace );
TracyLfqCommit;
} }
memcpy( trace, &cnt, sizeof( uint64_t ) );
TracyLfqPrepare( QueueType::CallstackSample );
MemWrite( &item->callstackSampleFat.time, t0 );
MemWrite( &item->callstackSampleFat.thread, tid );
MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace );
TracyLfqCommit;
} }
} }
else else
@ -1047,40 +1030,37 @@ static void SetupSampling( int64_t& samplingPeriod )
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) #if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
t0 = ring.ConvertTimeToTsc( t0 ); t0 = ring.ConvertTimeToTsc( t0 );
if( t0 != 0 )
#endif #endif
QueueType type;
switch( id )
{ {
QueueType type; case EventCpuCycles:
switch( id ) type = QueueType::HwSampleCpuCycle;
{ break;
case EventCpuCycles: case EventInstructionsRetired:
type = QueueType::HwSampleCpuCycle; type = QueueType::HwSampleInstructionRetired;
break; break;
case EventInstructionsRetired: case EventCacheReference:
type = QueueType::HwSampleInstructionRetired; type = QueueType::HwSampleCacheReference;
break; break;
case EventCacheReference: case EventCacheMiss:
type = QueueType::HwSampleCacheReference; type = QueueType::HwSampleCacheMiss;
break; break;
case EventCacheMiss: case EventBranchRetired:
type = QueueType::HwSampleCacheMiss; type = QueueType::HwSampleBranchRetired;
break; break;
case EventBranchRetired: case EventBranchMiss:
type = QueueType::HwSampleBranchRetired; type = QueueType::HwSampleBranchMiss;
break; break;
case EventBranchMiss: default:
type = QueueType::HwSampleBranchMiss; assert( false );
break; break;
default:
assert( false );
break;
}
TracyLfqPrepare( type );
MemWrite( &item->hwSample.ip, ip );
MemWrite( &item->hwSample.time, t0 );
TracyLfqCommit;
} }
TracyLfqPrepare( type );
MemWrite( &item->hwSample.ip, ip );
MemWrite( &item->hwSample.time, t0 );
TracyLfqCommit;
} }
} }
pos += hdr.size; pos += hdr.size;