25 #include <CD_NamespaceHeader.H>
36 using Clock = std::chrono::steady_clock;
41 using TimePoint = std::chrono::steady_clock::time_point;
62 inline Timer(
const std::string a_process);
88 startEvent(
const std::string a_event) noexcept;
96 stopEvent(
const std::string a_event) noexcept;
105 eventReport(std::ostream& a_outputStream,
const bool a_localReportOnly =
false) const noexcept;
141 std::map<std::string, std::tuple<bool, TimePoint, Duration>>
m_events;
153 printReportTail(std::ostream& a_outputStream,
const std::pair<Real, Real> a_elapsedTime)
const noexcept;
159 std::pair<Real, Real>
163 #include <CD_NamespaceFooter.H>
Implementation of CD_Timer.H.
Class which is used for run-time monitoring of events.
Definition: CD_Timer.H:31
void stopEvent(const std::string a_event) noexcept
Stop an event.
Definition: CD_TimerImplem.H:88
std::chrono::duration< Real > Duration
Duration in seconds.
Definition: CD_Timer.H:46
~Timer()
Destructor.
Definition: CD_TimerImplem.H:47
void startEvent(const std::string a_event) noexcept
Start an event.
Definition: CD_TimerImplem.H:59
EventFields
Enum for indexing tuple. A rare case of where unscoped enums are useful.
Definition: CD_Timer.H:126
std::chrono::steady_clock Clock
Clock implements.
Definition: CD_Timer.H:36
std::string m_processName
Process name. Used for input/output.
Definition: CD_Timer.H:135
void writeReportToFile(const std::string a_fileName) const noexcept
Print all timed events to a file.
Definition: CD_TimerImplem.H:342
std::chrono::steady_clock::time_point TimePoint
Point in time.
Definition: CD_Timer.H:41
void printReportHeader(std::ostream &a_outputStream) const noexcept
Print report header.
Definition: CD_TimerImplem.H:113
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:141
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 printReportTail(std::ostream &a_outputStream, const std::pair< Real, Real > a_elapsedTime) const noexcept
Print report tail.
Definition: CD_TimerImplem.H:149
static Real wallClock()
Static function which returns the time (in seconds) between now and an arbitrary time in the past.
Definition: CD_TimerImplem.H:31
Timer & operator=(const Timer &a_other)=default
Copy assignement.
std::pair< Real, Real > computeTotalElapsedTime(const bool a_localReportOnly) const noexcept
Compute the total time for all finished events.
Definition: CD_TimerImplem.H:310
void clear() noexcept
Clear all events.
Definition: CD_TimerImplem.H:53
void eventReport(std::ostream &a_outputStream, const bool a_localReportOnly=false) const noexcept
Print all timed events to cout.
Definition: CD_TimerImplem.H:173