Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiling): Dynamically adjust profiler sleep time #1634

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

Zylphrex
Copy link
Member

Because more time may have elapsed between 2 samples due to us calling the sampling function and other threads executing, we need to account for it in the sleep or the time between samples will often be greater than the expected interval. This change ensures we account for this time elapsed and dynamically adjust the amount of time we sleep for between samples.

Because more time may have elapsed between 2 samples due to us calling the
sampling function and other threads executing, we need to account for it in the
sleep or the time between samples will often be greater than the expected
interval. This change ensures we account for this time elapsed and dynamically
adjust the amount of time we sleep for between samples.
@Zylphrex Zylphrex requested review from a team and sl0thentr0py September 20, 2022 21:43
now = time.perf_counter()
elapsed = max(now - last, 0)

if elapsed < self._interval:
Copy link

Choose a reason for hiding this comment

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

I'm not sure why you test this before you sleep. Shouldn't we sleep all the time at least a little bit, just the remaining amount of time until self._interval passed?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the elapsed time is greater than self._interval, then we'd want to sample as soon as possible otherwise the time between the 2 samples will be much larger than expected. This is because other threads could be running without giving this thread a chance to execute.

@Zylphrex Zylphrex enabled auto-merge (squash) September 26, 2022 14:17
@Zylphrex Zylphrex merged commit f71a8f4 into master Sep 26, 2022
@Zylphrex Zylphrex deleted the txiao/fix/dynamically-adjust-profiler-sleep-time branch September 26, 2022 14:33
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.

3 participants