chombo-discharge
Loading...
Searching...
No Matches
CD_Timer.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
14#ifndef CD_TIMER_H
15#define CD_TIMER_H
16
17// Std includes
18#include <chrono>
19#include <map>
20#include <tuple>
21
22// Chombo includes
23#include <REAL.H>
24
25// Our includes
26#include <CD_NamespaceHeader.H>
27
31class Timer
32{
33public:
37 using Clock = std::chrono::steady_clock;
38
42 using TimePoint = std::chrono::steady_clock::time_point;
43
47 using Duration = std::chrono::duration<Real>;
48
53 inline static Real
54 wallClock();
55
59 inline Timer() = default;
60
65 inline Timer(const std::string& a_process);
66
70 inline ~Timer();
71
76 Timer(const Timer& a_other) = default;
77
83 Timer&
84 operator=(const Timer& a_other) = default;
85
91 inline void
92 startEvent(const std::string& a_event) noexcept;
93
99 inline void
100 stopEvent(const std::string& a_event) noexcept;
101
109 inline void
111
117 inline void
119
123 inline void
124 clear() noexcept;
125
131 {
132 StoppedEvent = 0,
133 StartClock = 1,
134 ElapsedTime = 2
135 };
136
141
147
152 void
154
160 void
162
169 computeTotalElapsedTime(const bool a_localReportOnly) const noexcept;
170};
171
172#include <CD_NamespaceFooter.H>
173
174#include <CD_TimerImplem.H>
175
176#endif
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:131
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:140
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:146
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
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26