Skip to content

Conversation

wuyifff
Copy link

@wuyifff wuyifff commented Aug 13, 2025

Description

This PR refactors the Timer utility to introduce a hierarchical timer tree structure, also add a feature that timer can support manually stop.

Key Changes:

src/oops/util/Timer.cc: The Timer class now tracks its position within a call tree using TimerHelper and a new stopped_ flag to prevent duplicate time logging.

src/oops/util/TimerHelper.cc & src/oops/util/TimerHelper.h: The TimerHelper is updated to manage a new TimerTree class, including methods to navigate the tree (goDown, goUp) and to print the complete hierarchical timing structure.

src/oops/util/TimerTree.h: This new file defines the TimerTree class, which handles the creation and management of the hierarchical timer structure and includes a method to print the tree in a unix tree command like format.

Useage

We can use it as before, declare timer in the beginning of the code section and it will auto destruct when exit block. Another usage (new) is wrapping the statements we want to measure time using timer declaration and explicit timer.stop.

For example:

# statements
util::Timer timer_initial_b("DRPLanczosMinimizer", "initial_B_LMP_multiply");
lmp_.multiply(vv, pr);
B.multiply(pr, zz);
timer_initial_b.stop();
# statements

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.

1 participant