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

Push/pop Timer name prefixes #99

Closed
vasdommes opened this issue Jul 21, 2023 · 1 comment
Closed

Push/pop Timer name prefixes #99

vasdommes opened this issue Jul 21, 2023 · 1 comment
Assignees
Milestone

Comments

@vasdommes
Copy link
Collaborator

vasdommes commented Jul 21, 2023

Currently one has to declare Timer name as "run.solve.some_function.other_function".

We can automatically store current prefix in Timers (and push/pop prefixes using RAII).
Then the code will look like

{
  Scoped_Timer root_timer(timers, "root") // "root"
  Append_Timer_Prefix root_prefix(timers, "root");
  {
    Append_Timer_Prefix prefix(timers, "nested"); 
    Scoped_Timer timer(timers, "step_1"); // "root.nested.step_1"
    Scoped_Timer timer(timers, "step_2"); // "root.nested.step_2"
  }
  Scoped_Timer timer(timers, "foo"); // "root.foo"
}

Inspired by
https://gitlab.com/bootstrapcollaboration/blocks_3d/-/commit/8717ba22dea47d7b13cff43ad02da83bff559b38#2ad9be1f8a0f77401abdb81cd016327598b6dd51
(but we can do it in a more elegant way)

@vasdommes vasdommes self-assigned this Jul 21, 2023
@vasdommes
Copy link
Collaborator Author

We can even ask Scoped_Timer to append its name to current prefix.
Seems that we (almost?) always want a 'root' timer for a given scope.

NB: This works only if child timer is guaranteed to finish before the parent one. With Scoped_Timer, it will almost always be the case (unless we do some dirty tricks with pointers-to-timers). Simple Timer is more flexible, easier to break this nesting.

@vasdommes vasdommes added this to the Backlog milestone Nov 14, 2023
@vasdommes vasdommes modified the milestones: Backlog, 2.6.0 Nov 14, 2023
vasdommes added a commit that referenced this issue Nov 15, 2023
Fix #99 Push/pop Timer name prefixes
bharathr98 pushed a commit to bharathr98/sdpb that referenced this issue Mar 1, 2024
Also fix some timer names, e.g. for sdp2input

ScopedTimer now temporarily adds its name to Timers::prefix.
Example:

void f()
{
  Timers timers(false);
  Scoped_Timer root_timer(timers, "root"); // "root"
  Scoped_Timer foo_timer(timers, "foo"); // "root.foo"
  foo_timer.stop();
  Scoped_Timer bar_timer(timers, "bar"); // "root.bar"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant