diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 13bfd77e..5bcdb53e 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -689,8 +689,9 @@ enum TraceEventId EventBranchMiss }; -static void ProbePreciseIp( perf_event_attr& pe ) +static void ProbePreciseIp( perf_event_attr& pe, unsigned long long config0, unsigned long long config1 ) { + pe.config = config1; pe.precise_ip = 3; while( pe.precise_ip != 0 ) { @@ -702,6 +703,17 @@ static void ProbePreciseIp( perf_event_attr& pe ) } pe.precise_ip--; } + pe.config = config0; + while( pe.precise_ip != 0 ) + { + const int fd = perf_event_open( &pe, -1, 0, -1, PERF_FLAG_FD_CLOEXEC ); + if( fd != -1 ) + { + close( fd ); + break; + } + pe.precise_ip--; + } TracyDebug( " Probed precise_ip: %i\n", pe.precise_ip ); } @@ -769,11 +781,10 @@ static void SetupSampling( int64_t& samplingPeriod ) s_numBuffers++; } - // CPU cycles + // CPU cycles + instructions retired pe = {}; pe.type = PERF_TYPE_HARDWARE; pe.size = sizeof( perf_event_attr ); - pe.config = PERF_COUNT_HW_CPU_CYCLES; pe.sample_freq = 5*1000*1000; pe.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; pe.disabled = 1; @@ -781,8 +792,8 @@ static void SetupSampling( int64_t& samplingPeriod ) pe.exclude_idle = 1; if( !noRetirement ) { - TracyDebug( "Setup sampling CPU cycles\n" ); - ProbePreciseIp( pe ); + TracyDebug( "Setup sampling cycles + retirement\n" ); + ProbePreciseIp( pe, PERF_COUNT_HW_CPU_CYCLES, PERF_COUNT_HW_INSTRUCTIONS ); for( int i=0; i