MXS-2078 Add IntervalTimer

IntervalTimer is used for accumulating intervals (i.e. durations) over sections of code.
This commit is contained in:
Niclas Antti
2018-11-01 09:21:50 +02:00
parent 56d28d703c
commit 13a0390de6
2 changed files with 55 additions and 0 deletions

View File

@ -46,6 +46,27 @@ Duration StopWatch::restart()
m_start = m_lap = now;
return split;
}
IntervalTimer::IntervalTimer() : m_total(0)
{
}
void IntervalTimer::start_interval()
{
m_last_start = Clock::now();
}
void IntervalTimer::end_interval()
{
m_total += Clock::now() - m_last_start;
// reset to make it easier to spot usage bugs, like calling end_interval(); end_interval();
m_last_start = TimePoint();
}
Duration IntervalTimer::total() const
{
return m_total;
}
} // maxbase
/********** OUTPUT ***********/