26#include <CD_NamespaceHeader.H>
37 using Clock = std::chrono::steady_clock;
42 using TimePoint = std::chrono::steady_clock::time_point;
65 inline Timer(
const std::string& a_process);
93 startEvent(
const std::string& a_event)
noexcept;
102 stopEvent(
const std::string& a_event)
noexcept;
112 eventReport(std::ostream& a_outputStream,
const bool a_localReportOnly =
false) const noexcept;
149 std::map<std::string, std::tuple<bool, TimePoint, Duration>>
m_events;
164 printReportTail(std::ostream& a_outputStream,
const std::pair<Real, Real> a_elapsedTime)
const noexcept;
171 std::pair<Real, Real>
175#include <CD_NamespaceFooter.H>
Implementation of CD_Timer.H.
Class which is used for run-time monitoring of events.
Definition CD_Timer.H:32
std::chrono::duration< Real > Duration
Duration in seconds.
Definition CD_Timer.H:47
~Timer()
Destructor.
Definition CD_TimerImplem.H:48
EventFields
Enum for indexing tuple. A rare case of where unscoped enums are useful.
Definition CD_Timer.H:134
std::chrono::steady_clock Clock
Clock implements.
Definition CD_Timer.H:37
std::string m_processName
Process name. Used for input/output.
Definition CD_Timer.H:143
void startEvent(const std::string &a_event) noexcept
Start an event.
Definition CD_TimerImplem.H:60
std::chrono::steady_clock::time_point TimePoint
Point in time.
Definition CD_Timer.H:42
void printReportHeader(std::ostream &a_outputStream) const noexcept
Print report header.
Definition CD_TimerImplem.H:114
std::map< std::string, std::tuple< bool, TimePoint, Duration > > m_events
Timer events. First entry is the name of the event.
Definition CD_Timer.H:149
Timer()=default
Default constructor. This creates a timer without any timer events and without a name.
Timer(const Timer &a_other)=default
Copy construction.
void writeReportToFile(const std::string &a_fileName) const noexcept
Print all timed events to a file.
Definition CD_TimerImplem.H:340
void printReportTail(std::ostream &a_outputStream, const std::pair< Real, Real > a_elapsedTime) const noexcept
Print report tail.
Definition CD_TimerImplem.H:146
static Real wallClock()
Static function which returns the time (in seconds) between now and an arbitrary time in the past.
Definition CD_TimerImplem.H:32
std::pair< Real, Real > computeTotalElapsedTime(const bool a_localReportOnly) const noexcept
Compute the total time for all finished events.
Definition CD_TimerImplem.H:308
void clear() noexcept
Clear all events.
Definition CD_TimerImplem.H:54
Timer & operator=(const Timer &a_other)=default
Copy assignment.
void eventReport(std::ostream &a_outputStream, const bool a_localReportOnly=false) const noexcept
Print all timed events to cout.
Definition CD_TimerImplem.H:170
void stopEvent(const std::string &a_event) noexcept
Stop an event.
Definition CD_TimerImplem.H:89