Fix #1337 : On Linux respect max sample rate#1342
Merged
wolfpld merged 4 commits intowolfpld:masterfrom Apr 20, 2026
Merged
Conversation
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.
wolfpld
reviewed
Apr 20, 2026
wolfpld
reviewed
Apr 20, 2026
| int microseconds = GetSamplingInterval() / 10; | ||
| samplingPeriod = SamplingFrequencyToPeriodNs( GetSamplingFrequency() ); | ||
| const int microseconds = samplingPeriod / 1000; | ||
| if( etw::EnableCPUProfiling( session_kernel, microseconds ) != ERROR_SUCCESS ) |
Collaborator
Author
There was a problem hiding this comment.
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
wolfpld
reviewed
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_rateat 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
GetSamplingPeriod→SamplingFrequencyToPeriodNsis included to ensure the reportedsamplingPeriodalways 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.