GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix confusing timeout & loop combined usage by Baraa-Hasheesh · Pull Request #1625 · async-profiler/async-profiler

Conversation

@Baraa-Hasheesh

@Baraa-Hasheesh Baraa-Hasheesh commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

Description

Currently using both timeout & loop together is confusing,

This change makes so that timeout is used to correctly stop the profiler once reached, & loop is used to control the duration of the profiling session

Related issues

#1621

Motivation and context

Fix confusing timeout & loop behaviour & allow combined usage

How has this been tested?

manual testing


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Baraa-Hasheesh
Allow usage of both timeout & loop together
5a8baaa
fandreuz
fandreuz reviewed Dec 17, 2025
View reviewed changes
Comment thread src/profiler.cpp Resolved

Uh oh!

There was an error while loading. Please reload this page.

fandreuz
fandreuz reviewed Dec 17, 2025
View reviewed changes
Comment thread src/profiler.cpp Outdated
u64 current_micros = OS::micros();
u64 sleep_until = _jfr.active() ? current_micros + 1000000 : _stop_time;
u64 loop_limit = std::min(_stop_time, _loop_time);
u64 sleep_until = _jfr.active() ? current_micros + 1000000 : std::min(_stop_time, loop_limit);

@fandreuz fandreuz Dec 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
u64 sleep_until = _jfr.active() ? current_micros + 1000000 : std::min(_stop_time, loop_limit);
u64 sleep_until = _jfr.active() ? current_micros + 1000000 : loop_limit;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 17, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What if you do --loop 79s --timeout 1000s

The timeout wouldn't be respected, as you would end up running for 1027 seconds

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fandreuz fandreuz Dec 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

std::min(_stop_time, loop_limit) ==
std::min(_stop_time, std::min(_stop_time, _loop_time)) ==
std::min(_stop_time, _stop_time, _loop_time) ==
std::min(_stop_time, _loop_time) ==
loop_limit

unless I'm missing something.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 17, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

loop limit is recalculated at every iteration -> start time is updated at every loop

So let's say we start at time 0 & timeout is 10 & loop is 3

  • iteration 1 => _stop_time = 10, _loop_limit = 3, _start_time = 0
  • iteration 2 => _stop_time = 10, _loop_limit = 6, _start_time = 3
  • iteration 3 => _stop_time = 10, _loop_limit = 9, _start_time = 6
  • iteration 4 => _stop_time = 10, _loop_limit = 12, _start_time = 9

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 17, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

my bad, thanks for raising it, I'm pretty sure I just had a brain fart here :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fandreuz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Baraa-Hasheesh Baraa-Hasheesh Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

0ebfd52

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
fandreuz
fandreuz reviewed Dec 17, 2025
View reviewed changes
Comment thread src/profiler.cpp Outdated

Error Profiler::restart(Arguments& args) {
MutexLocker ml(_state_lock);
bool restart = OS::micros() < _stop_time;

@fandreuz fandreuz Dec 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd call this should_restart

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Baraa-Hasheesh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Baraa-Hasheesh Baraa-Hasheesh Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

0ebfd52

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Baraa-Hasheesh
should restart & min
0ebfd52
apangin
apangin reviewed Dec 18, 2025
View reviewed changes
Comment thread src/profiler.cpp
if (args._timeout != 0 || args._loop != 0 || args._output == OUTPUT_JFR) {
_loop_time = addTimeout(_start_time, args._loop);
if (args._file_num == 0) {
_stop_time = addTimeout(_start_time, args._timeout);

@apangin apangin Dec 18, 2025

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What if _timeout == 0?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

_stop_time would be set to 0x7fffffffffffffffULL which effectively mean profiler will never timeout

-> same as old behaviour

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

apangin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/profiler.cpp Outdated

Error Profiler::restart(Arguments& args) {
MutexLocker ml(_state_lock);
bool should_restart = OS::micros() < _stop_time;

@apangin apangin Dec 18, 2025

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Isn't it better to pass the flag from outside? I mean, from timerLoop which should be responsible for time-related decisions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That makes sense

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@apangin I don't really like the name of the function "restart"

How would you feel if I rename it to "rotate"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@apangin apangin Dec 19, 2025

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree "restart" isn't accurate. But neither is "rotate".
Maybe "expire"? Because it is called when timer is expired.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Baraa-Hasheesh Baraa-Hasheesh Dec 19, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

"expire" is good for me, bd0d93b

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Baraa-Hasheesh added 2 commits December 19, 2025 08:03
@Baraa-Hasheesh
rename function & pass flag
bd0d93b
@Baraa-Hasheesh
current_micros
5094eb5
@apangin
apangin merged commit fde780e into async-profiler:master Dec 19, 2025
@Baraa-Hasheesh Baraa-Hasheesh mentioned this pull request Dec 19, 2025
Loop & Timeout are confusing together #1621
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@apangin apangin apangin left review comments
+1 more reviewer
@fandreuz fandreuz fandreuz left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Baraa-Hasheesh @apangin @fandreuz
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.