17 #ifndef THRILL_COMMON_STATS_TIMER_HEADER 18 #define THRILL_COMMON_STATS_TIMER_HEADER 38 template <
bool Active>
46 using time_point = std::chrono::steady_clock::time_point;
63 : running_(false), accumulated_() {
64 if (start_immediately) Start();
73 bool Real()
const {
return true; }
84 last_start_ = steady_clock::now();
92 last_start_ = steady_clock::now();
101 accumulated_ += std::chrono::duration_cast<
duration>(
102 steady_clock::now() - last_start_);
116 last_start_ = steady_clock::now();
125 d += std::chrono::duration_cast<
duration>(
126 steady_clock::now() - last_start_);
133 return std::chrono::duration_cast<std::chrono::microseconds>(
134 Accumulated()).count();
139 return std::chrono::duration_cast<std::chrono::milliseconds>(
140 Accumulated()).count();
145 return std::chrono::duration_cast<std::chrono::seconds>(
146 Accumulated()).count();
152 return static_cast<double>(Microseconds()) / 1e6;
158 return static_cast<double>(Microseconds()) / 1e3;
163 accumulated_ += tm.accumulated_;
169 return os << t.SecondsDouble();
173 return Put(line, t.SecondsDouble());
195 bool Real()
const {
return false; }
262 return os <<
"<invalid>";
266 return Put(line, t.SecondsDouble());
270 template <
bool Active>
279 template <
bool Active>
297 template <
typename Timer>
301 explicit RunTimer(Timer& timer) : timer_(timer) { timer.Start(); }
317 #endif // !THRILL_COMMON_STATS_TIMER_HEADER
StatsTimerBase(bool start_immediately)
Initialize and optionally immediately start the timer.
StatsTimerBase & Stop()
stop timer
friend JsonLine & Put(JsonLine &line, const StatsTimerBase &t)
common::AtomicMovable< bool > running_
boolean whether the timer is currently running
StatsTimerBase & StartEventually()
start timer only if it not running
StatsTimerBase & Start()
start timer
RIAA class for running the timer until destruction.
friend JsonLine & Put(JsonLine &line, const StatsTimerBase &t)
std::chrono::seconds::rep Seconds() const
return currently accumulated time in milliseconds
StatsTimerBase & Stop()
stop timer
std::chrono::steady_clock::time_point time_point
double MillisecondsDouble() const
std::chrono::microseconds::rep Microseconds() const
return currently accumulated time in microseconds
uint_pair & operator+=(const uint_pair &b)
addition operator (uses 64-bit arithmetic)
std::chrono::microseconds duration
std::chrono::steady_clock steady_clock
duration accumulated_
total accumulated time in microseconds.
StatsTimerBase(bool)
Initialize and optionally immediately start the timer.
StatsTimerBase & Reset()
return accumulated time
std::chrono::microseconds::rep Microseconds() const
return currently accumulated time in microseconds
time_point last_start_
last start time of the stop watch
bool running() const
Whether the timer is running.
duration Accumulated() const
return currently accumulated time
StatsTimerBaseStopped()
Initialize but do NOT automatically start the timer.
std::chrono::seconds::rep Seconds() const
return currently accumulated time in seconds
duration Accumulated() const
return currently accumulated time
double SecondsDouble() const
std::chrono::steady_clock steady_clock
std::chrono::microseconds duration
double MillisecondsDouble() const
StatsTimerBase & StopEventually()
stop timer if it is running
bool Real() const
Whether the timer is real.
double SecondsDouble() const
StatsTimerBase & StartEventually()
start timer only if it not running
bool Real() const
Whether the timer is real.
std::chrono::milliseconds::rep Milliseconds() const
return currently accumulated time in milliseconds
static JsonLine & Put(JsonLine &line, bool const &value)
std::chrono::steady_clock::time_point time_point
std::chrono::milliseconds::rep Milliseconds() const
return currently accumulated time in milliseconds
bool running() const
Whether the timer is running.
StatsTimerBase & Reset()
return accumulated time
StatsTimerBase & StopEventually()
stop timer if it is running
StatsTimerBaseStarted()
Initialize and automatically start the timer.
This class provides a statistical stop watch timer that can easily be deactivated using a boolean tem...
std::ostream & operator<<(std::ostream &os, const DIABase &d)
make ostream-able.
StatsTimerBase & Start()
start timer
JsonLine is an object used to aggregate a set of key:value pairs for output into a JSON log...