15#include "TimeLogger.h"
39template <
typename T = std::chrono::high_resolution_clock>
51 Timer(std::optional<std::string> task = std::nullopt) : _task(task) {}
57 if (_start_time.has_value() and _task.has_value())
59 _acc += T::now() - *_start_time;
67 _acc = T::duration::zero();
68 _start_time = T::now();
76 template <
typename Period = std::ratio<1>>
77 std::chrono::duration<double, Period>
elapsed()
const
79 if (_start_time.has_value())
80 return T::now() - *_start_time + _acc;
90 template <
typename Period = std::ratio<1>>
91 std::chrono::duration<double, Period>
stop()
93 if (_start_time.has_value())
95 _acc += T::now() - *_start_time;
96 _start_time = std::nullopt;
107 if (!_start_time.has_value())
108 _start_time = T::now();
120 if (_start_time.has_value())
121 throw std::runtime_error(
"Timer must be stopped before flushing.");
123 if (_task.has_value())
126 _task = std::nullopt;
132 std::optional<std::string> _task;
135 T::duration _acc = T::duration::zero();
138 std::optional<typename T::time_point> _start_time = T::now();
void register_timing(std::string task, std::chrono::duration< double, std::ratio< 1 > > wall)
Register timing (for later summary)
Definition TimeLogger.cpp:23
static TimeLogger & instance()
Singleton access.
Definition TimeLogger.cpp:16
Timer for measuring and logging elapsed time durations.
Definition Timer.h:41
std::chrono::duration< double, Period > stop()
Stop timer and return elapsed time.
Definition Timer.h:91
void resume()
Resume a stopped timer.
Definition Timer.h:105
~Timer()
Definition Timer.h:55
void start()
Reset elapsed time and (re-)start timer.
Definition Timer.h:65
std::chrono::duration< double, Period > elapsed() const
Elapsed time since time has been started.
Definition Timer.h:77
Timer(std::optional< std::string > task=std::nullopt)
Create and start timer.
Definition Timer.h:51
void flush()
Flush timer duration to the logger.
Definition Timer.h:118
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8