Skip to content

Fix #1337 : On Linux respect max sample rate#1342

Merged
wolfpld merged 4 commits intowolfpld:masterfrom
siliceum:fix/1337-respect-max-sample-rate
Apr 20, 2026
Merged

Fix #1337 : On Linux respect max sample rate#1342
wolfpld merged 4 commits intowolfpld:masterfrom
siliceum:fix/1337-respect-max-sample-rate

Conversation

@Lectem
Copy link
Copy Markdown
Collaborator

@Lectem Lectem commented Apr 20, 2026

On Linux, Tracy was ignoring the system's maximum perf sampling rate, which could cause dropped events — particularly on low-performance or embedded systems.

This PR reads /proc/sys/kernel/perf_event_max_sample_rate at startup and caps the requested frequency to the system maximum if needed. A debug message is emitted when the rate is reduced.

The refactor of GetSamplingPeriodSamplingFrequencyToPeriodNs is included to ensure the reported samplingPeriod always reflects the actual (possibly capped) frequency used.

Note: /proc/sys/kernel/perf_event_max_sample_rate's value is non-zero since torvalds/linux@723478c but I could had a null-check if needed.

Lectem added 2 commits April 20, 2026 14:29
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.
…void lost events

This may be especially useful for low performance machines. We also warn about this behaviour through TracyDebug which ends up in Messages.
Comment thread public/client/TracySysTrace.cpp Outdated
int microseconds = GetSamplingInterval() / 10;
samplingPeriod = SamplingFrequencyToPeriodNs( GetSamplingFrequency() );
const int microseconds = samplingPeriod / 1000;
if( etw::EnableCPUProfiling( session_kernel, microseconds ) != ERROR_SUCCESS )
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etw?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it was also using GetSamplingPeriod() that I replaced, and GetSamplingInterval was adding an indirection for nothing (dividing by 100, then divided by 10 at call site).

Alternative (not touching GetSamplingInterval) would have been to introduce yet another function or write the 1000000000 / samplingHz inline in the linux code.

Your call

Comment thread public/client/TracySysTrace.cpp Outdated
@wolfpld wolfpld merged commit 25f09be into wolfpld:master Apr 20, 2026
7 checks passed
@Lectem Lectem deleted the fix/1337-respect-max-sample-rate branch April 20, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants