Fix EventPipe sample profiler resolution on Windows. #58997
Merged
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.
If sample profiler was initially created before sampling has been enabled, happens when setting up sessions during startup,
sample_profiler_load_dependecies won't get called, meaning we won't setup timeBeginPeriod/timeEndPeriod on Windows, and won't adjust default scheduling resolution to 1ms staying on default 16ms.
There is a ref count check in current sample_profiler_enable checking if we should call sample_profiler_load_dependecies (_ref_count == 0), but in case where we can't start profiling _can_start_sampling == false, we won't call sample_profiler_enable but always increase _ref_count that in turn will prevent calls to sample_profiler_load_dependecies when enabling sample profiler and that in turn won't call timeBeginPeriod staying on default scheduling resolution.
Fix is to always call sample_profiler_load_dependecies making sure we will setup needed dependencies when _ref_count == 0.