Fix sample profiler resolution on Windows. (#59056)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 14 Sep 2021 22:21:17 +0000 (15:21 -0700)
committerGitHub <noreply@github.com>
Tue, 14 Sep 2021 22:21:17 +0000 (15:21 -0700)
commitbf2a7d0f0bcb0438f342b304988115f3c88a2178
treee815e2a8c5d98cff1c429f790b43d016bace5769
parentdb4c0c23eb4ce56b83d17e3f15cccc01964e419a
Fix sample profiler resolution on Windows. (#59056)

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.

Co-authored-by: lateralusX <lateralusx.github@gmail.com>
src/native/eventpipe/ep-sample-profiler.c