From e550e15ce6c20f6db8ecd8fe0318f6d24e603508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Mon, 20 Apr 2026 14:29:35 +0200 Subject: [PATCH] Turn GetSamplingPeriod into SamplingFrequencyToPeriodNs This forces to (re)use frequency values as input, which may be changed by the platform code later on. This way we have a single "source of truth" for sample freq. Also removed the Win32 `GetSamplingInterval` which was a wrapper above `GetSamplingPeriod` but its value would be divided again anyway. --- public/client/TracySysTrace.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/public/client/TracySysTrace.cpp b/public/client/TracySysTrace.cpp index dcb510a3..8dcf4e13 100644 --- a/public/client/TracySysTrace.cpp +++ b/public/client/TracySysTrace.cpp @@ -34,9 +34,9 @@ static int GetSamplingFrequency() #endif } -static int GetSamplingPeriod() +static int SamplingFrequencyToPeriodNs( int samplingHz ) { - return 1000000000 / GetSamplingFrequency(); + return 1000000000 / samplingHz; } } @@ -174,11 +174,6 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record ) } } -static int GetSamplingInterval() -{ - return GetSamplingPeriod() / 100; -} - static etw::Session session_kernel = {}; static etw::Session session_vsync = {}; static PROCESSTRACE_HANDLE consumer_kernel = INVALID_PROCESSTRACE_HANDLE; @@ -207,10 +202,10 @@ bool SysTraceStart( int64_t& samplingPeriod ) #ifndef TRACY_NO_SAMPLING - int microseconds = GetSamplingInterval() / 10; + samplingPeriod = SamplingFrequencyToPeriodNs( GetSamplingFrequency() ); + const int microseconds = samplingPeriod / 1000; if( etw::EnableCPUProfiling( session_kernel, microseconds ) != ERROR_SUCCESS ) return etw::StopSession( session_kernel ), false; - samplingPeriod = GetSamplingPeriod(); #endif consumer_kernel = etw::SetupEventConsumer( session_kernel, EventRecordCallback ); @@ -659,7 +654,8 @@ bool SysTraceStart( int64_t& samplingPeriod ) const bool noVsync = noVsyncEnv && noVsyncEnv[0] == '1'; #endif - samplingPeriod = GetSamplingPeriod(); + const int samplingFrequency = GetSamplingFrequency(); + samplingPeriod = SamplingFrequencyToPeriodNs( samplingFrequency ); uint32_t currentPid = ___tracy_magic_pid_override != 0 ? ___tracy_magic_pid_override : (uint32_t)getpid(); s_numCpus = (int)std::thread::hardware_concurrency(); @@ -680,7 +676,7 @@ bool SysTraceStart( int64_t& samplingPeriod ) pe.type = PERF_TYPE_SOFTWARE; pe.size = sizeof( perf_event_attr ); pe.config = PERF_COUNT_SW_CPU_CLOCK; - pe.sample_freq = GetSamplingFrequency(); + pe.sample_freq = samplingFrequency; pe.sample_type = PERF_SAMPLE_TID | PERF_SAMPLE_TIME | PERF_SAMPLE_CALLCHAIN; #if LINUX_VERSION_CODE >= KERNEL_VERSION( 4, 8, 0 ) pe.sample_max_stack = 127;