LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Provides time interval measurements. More...
#include "StopWatch.h"
Classes | |
struct | makeDurationTrait |
Trait whose type member is a std::chrono::duration type. More... | |
struct | makeDurationTrait< std::chrono::duration< Rep, Duration > > |
struct | makeDurationTrait< std::ratio< Num, Den > > |
Public Types | |
using | Clock_t = Clock |
type of clock used to extract current time More... | |
using | DefaultUnit_t = DefaultUnit |
default unit for time report More... | |
using | ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time. More... | |
Public Member Functions | |
StopWatch (bool start=true) | |
Initializes and starts the timer. More... | |
template<typename Unit > | |
StopWatch (Unit prev, bool start=true) | |
Initializes and starts the timer. More... | |
template<typename Unit > | |
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t | elapsed () const |
template<typename Unit > | |
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t | partial () const |
template<typename Unit > | |
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t | previous () const |
Watch control | |
void | restart () |
Restarts the watch; previous time is forgotten. More... | |
void | resume () |
Resumes the run of the watch; previous time is preserved. More... | |
void | stop () |
Pauses the watch. More... | |
template<typename Unit = DefaultUnit_t> | |
void | setPrevious (Unit dur) |
Changes the amount of time accumulated before this run. More... | |
Query | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | elapsed () const |
Returns the total time spent running since the last restart. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | partial () const |
Returns the time spent running since the last resume. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | previous () const |
Returns the time accumulated before the current run. More... | |
bool | running () const |
Returns whether the watch is tracking time right now. More... | |
Protected Types | |
using | TimePoint_t = decltype(Clock_t::now()) |
type to store start time More... | |
template<typename Unit > | |
using | makeDuration_t = typename makeDurationTrait< Unit >::type |
Type of std::chrono::duration type constructed from makeDurationTrait. More... | |
Protected Member Functions | |
DefaultUnit_t | partialDur () const |
Returns partial time as a duration. More... | |
Static Protected Member Functions | |
static TimePoint_t | now () |
Returns the current time point from our clock. More... | |
template<typename Unit , typename From > | |
static auto | durationTo (From const &dur) |
Convert a duration into a unit (may be a ratio or a duration) More... | |
Protected Attributes | |
TimePoint_t | lastStart |
time of the last start More... | |
DefaultUnit_t | previousTime |
time accumulated from previous runs More... | |
bool | isRunning |
whether we are measuring time now More... | |
Provides time interval measurements.
DefaultUnit | unit reported by default (seconds, floating point) |
Clock | type of clock object used (default: high_resolution_clock) |
The stopwatch keeps track of the clock and can return the time elapsed from a previous time mark. Example of use:
The time from all methods returning a value are in the DefaultUnit_t unit.
On DefaultUnit
type:
On Clock
type:
now()
static function returning std::chrono::time_point
Definition at line 75 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::Clock_t = Clock |
type of clock used to extract current time
Definition at line 80 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::DefaultUnit_t = DefaultUnit |
default unit for time report
Definition at line 81 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time.
Definition at line 84 of file StopWatch.h.
|
protected |
Type of std::chrono::duration type constructed from makeDurationTrait.
Definition at line 157 of file StopWatch.h.
|
protected |
type to store start time
Definition at line 139 of file StopWatch.h.
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | bool | start = true | ) |
Initializes and starts the timer.
start | whether to start immediately (default: true) |
Definition at line 187 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::isRunning, testing::StopWatch< DefaultUnit, Clock >::now(), and testing::StopWatch< DefaultUnit, Clock >::previousTime.
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | Unit | prev, |
bool | start = true |
||
) |
Initializes and starts the timer.
prev | time already accumulated on start |
start | whether to start immediately (default: true) |
Definition at line 193 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::previousTime.
|
staticprotected |
Convert a duration into a unit (may be a ratio or a duration)
Definition at line 306 of file StopWatch.h.
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::elapsed | ( | ) | const |
Returns the total time spent running since the last restart.
testing::StopWatch<DefaultUnit, Clock>::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::elapsed | ( | ) | const |
Definition at line 237 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::running().
|
staticprotected |
Returns the current time point from our clock.
Definition at line 271 of file StopWatch.h.
Referenced by testing::StopWatch< DefaultUnit, Clock >::partialDur(), testing::StopWatch< DefaultUnit, Clock >::restart(), testing::StopWatch< DefaultUnit, Clock >::resume(), and testing::StopWatch< DefaultUnit, Clock >::StopWatch().
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::partial | ( | ) | const |
Returns the time spent running since the last resume.
testing::StopWatch<DefaultUnit, Clock>::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::partial | ( | ) | const |
Definition at line 247 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::partialDur(), and testing::StopWatch< DefaultUnit, Clock >::running().
|
protected |
Returns partial time as a duration.
Definition at line 279 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::lastStart, and testing::StopWatch< DefaultUnit, Clock >::now().
Referenced by testing::StopWatch< DefaultUnit, Clock >::partial(), and testing::StopWatch< DefaultUnit, Clock >::stop().
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::previous | ( | ) | const |
Returns the time accumulated before the current run.
testing::StopWatch<DefaultUnit, Clock>::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::previous | ( | ) | const |
Definition at line 256 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::previousTime.
void testing::StopWatch< DefaultUnit, Clock >::restart | ( | ) |
Restarts the watch; previous time is forgotten.
Definition at line 201 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::isRunning, testing::StopWatch< DefaultUnit, Clock >::lastStart, testing::StopWatch< DefaultUnit, Clock >::now(), and testing::StopWatch< DefaultUnit, Clock >::previousTime.
void testing::StopWatch< DefaultUnit, Clock >::resume | ( | ) |
Resumes the run of the watch; previous time is preserved.
Definition at line 210 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::isRunning, testing::StopWatch< DefaultUnit, Clock >::lastStart, testing::StopWatch< DefaultUnit, Clock >::now(), and testing::StopWatch< DefaultUnit, Clock >::running().
bool testing::StopWatch< DefaultUnit, Clock >::running | ( | ) | const |
Returns whether the watch is tracking time right now.
Definition at line 263 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::isRunning.
Referenced by testing::StopWatch< DefaultUnit, Clock >::elapsed(), testing::StopWatch< DefaultUnit, Clock >::partial(), and testing::StopWatch< DefaultUnit, Clock >::resume().
void testing::StopWatch< DefaultUnit, Clock >::setPrevious | ( | Unit | dur | ) |
Changes the amount of time accumulated before this run.
Definition at line 228 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::previousTime.
void testing::StopWatch< DefaultUnit, Clock >::stop | ( | ) |
Pauses the watch.
Definition at line 219 of file StopWatch.h.
References testing::StopWatch< DefaultUnit, Clock >::isRunning, testing::StopWatch< DefaultUnit, Clock >::partialDur(), and testing::StopWatch< DefaultUnit, Clock >::previousTime.
|
protected |
whether we are measuring time now
Definition at line 143 of file StopWatch.h.
Referenced by testing::StopWatch< DefaultUnit, Clock >::restart(), testing::StopWatch< DefaultUnit, Clock >::resume(), testing::StopWatch< DefaultUnit, Clock >::running(), testing::StopWatch< DefaultUnit, Clock >::stop(), and testing::StopWatch< DefaultUnit, Clock >::StopWatch().
|
protected |
time of the last start
Definition at line 141 of file StopWatch.h.
Referenced by testing::StopWatch< DefaultUnit, Clock >::partialDur(), testing::StopWatch< DefaultUnit, Clock >::restart(), and testing::StopWatch< DefaultUnit, Clock >::resume().
|
protected |
time accumulated from previous runs
Definition at line 142 of file StopWatch.h.
Referenced by testing::StopWatch< DefaultUnit, Clock >::previous(), testing::StopWatch< DefaultUnit, Clock >::restart(), testing::StopWatch< DefaultUnit, Clock >::setPrevious(), testing::StopWatch< DefaultUnit, Clock >::stop(), and testing::StopWatch< DefaultUnit, Clock >::StopWatch().