7#ifndef SRC_INCLUDE_TIMER_HPP
8#define SRC_INCLUDE_TIMER_HPP
14#include <forward_list>
25 typedef std::string Key;
32 typedef std::forward_list<Key> TimerPath;
41 Timer(
const Key& rootKey);
42 virtual ~Timer() =
default;
49 void tick(
const Key& timerName);
55 void tock(
const Key& timerName);
64 double lap(
const Key& timerName)
const;
70 double elapsed(
const Key& timerName)
const;
78 std::ostream&
report(
const Key& timerName, std::ostream& os)
const;
84 std::ostream&
report(std::ostream& os)
const;
91 std::ostream&
report(
const TimerPath&, std::ostream& os)
const;
101 void additionalTime(
const TimerPath& path, WallTimeDuration additionalWall,
102 CpuTimeDuration additionalCpu,
int additionalTicks);
118 std::map<Key, TimerNode> childNodes;
123 std::ostream& report(std::ostream& os,
const std::string& prefix)
const;
124 std::ostream& reportAll(std::ostream& os,
const std::string& prefix)
const;
126 TimerPath searchDescendants(
const Key& timerName)
const;
129 TimerPath pathToFirstMatch(
const Key&)
const;
std::ostream & operator<<(std::ostream &os, const Nextsim::Timer &tim)
Overload of the output operator for a Timer.
A class providing a timer.
std::chrono::high_resolution_clock::duration WallTimeDuration
Type of a time duration on the wall clock.
std::chrono::high_resolution_clock::time_point WallTimePoint
Type of a point in time for the wall clock.
std::clock_t CpuTimePoint
Type of a point in time for the CPU clock.
double CpuTimeDuration
Type of a time duration on the CPU clock.
A class for a hierarchical timer functions.
void additionalTime(const TimerPath &path, WallTimeDuration additionalWall, CpuTimeDuration additionalCpu, int additionalTicks)
Adds an additional time increment to a timer.
double elapsed(const Key &timerName) const
Returns the elapsed time.
void tock()
Stop the last timer to be started.
std::ostream & report(const Key &timerName, std::ostream &os) const
Prints the status of a named timer to an ostream.
void tick(const Key &timerName)
Starts a named timer.
Timer()
Creates a Timer with an unnamed root node.
double lap(const Key &timerName) const
Returns the elapsed time without stopping the timer.
void reset()
Deletes all timers except the root, which is reset.
TimerPath currentTimerNodePath() const
Returns the timer path to the currently running timer.
static Timer main
Static timer for general use.