10#include "TimeLogger.h" 
   38template <
typename T = std::chrono::high_resolution_clock>
 
   50  Timer(std::optional<std::string> task = std::nullopt) : _task(std::move(task))
 
 
   58    if (_start_time.has_value() and _task.has_value())
 
   60      _acc += T::now() - *_start_time;
 
 
   68    _acc = T::duration::zero();
 
   69    _start_time = T::now();
 
 
   77  template <
typename Period = std::ratio<1>>
 
   78  std::chrono::duration<double, Period> 
elapsed()
 const 
   80    if (_start_time.has_value()) 
 
   81      return T::now() - *_start_time + _acc;
 
 
   91  template <
typename Period = std::ratio<1>>
 
   92  std::chrono::duration<double, Period> 
stop()
 
   94    if (_start_time.has_value()) 
 
   96      _acc += T::now() - *_start_time;
 
   97      _start_time = std::nullopt;
 
 
  108    if (!_start_time.has_value())
 
  109      _start_time = T::now();
 
 
  121    if (_start_time.has_value())
 
  122      throw std::runtime_error(
"Timer must be stopped before flushing.");
 
  124    if (_task.has_value())
 
  127      _task = std::nullopt;
 
 
  133  std::optional<std::string> _task;
 
  136  T::duration _acc = T::duration::zero();
 
  139  std::optional<typename T::time_point> _start_time = T::now();
 
 
void register_timing(const 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
 
std::chrono::duration< double, Period > stop()
Stop timer and return elapsed time.
Definition Timer.h:92
 
void resume()
Resume a stopped timer.
Definition Timer.h:106
 
~Timer()
Definition Timer.h:56
 
void start()
Reset elapsed time and (re-)start timer.
Definition Timer.h:66
 
std::chrono::duration< double, Period > elapsed() const
Elapsed time since time has been started.
Definition Timer.h:78
 
Timer(std::optional< std::string > task=std::nullopt)
Create and start timer.
Definition Timer.h:50
 
void flush()
Flush timer duration to the logger.
Definition Timer.h:119
 
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8