LDMX Software
|
Time how long a specific operation takes and serialize the result with ROOT. More...
#include <Timer.h>
Public Member Functions | |
Timer ()=default | |
create a timer but don't start it yet | |
virtual | ~Timer ()=default |
create defualt destructor | |
void | reset () |
reset a timer to un-started state without re-allocating | |
void | start () |
start the timer | |
void | stop () |
stop the timer | |
double | duration () const |
retrieve the value of the duration in seconds | |
void | write (TDirectory *location, const std::string &name) const |
Write ourselves under the input name to the input location. | |
ClassDef (Timer, 1) | |
Private Types | |
using | clock = std::chrono::high_resolution_clock |
Private Attributes | |
std::chrono::time_point< clock > | begin_ |
The time_point when the timer is started. | |
std::chrono::time_point< clock > | end_ |
The time_point when the timer is stopped. | |
long int | start_time_ {-1} |
Time stamp for when timer was started in nanoseconds since UNIX epoch. | |
double | duration_ {-1} |
Length of time recorded by the timer in seconds. | |
Time how long a specific operation takes and serialize the result with ROOT.
Under-the-hood, we use std::chrono::time_point and std::chrono::duration along with std::chrono::high_resolution_clock so we can clearly and faithfully time how long things take and transparently convert the resulting duration into seconds (including sub-second increments). Since ROOT doesn't have a dictionary for serializing these std::chrono classes (and I'm not interested in making one), I simply mark those helper-members as "transient" (have //!
on the line they are declared in) so they are ignored by the dictionary generation. The fundamental members start_time_ and duration_ are what end up being written to disk.
Below is an example of reading the absolute timer from a test run of this performance logging infrastructure. As you can see, the two atomic types are available for reading but the std::chrono::time_point objects are not.
|
private |
double framework::performance::Timer::duration | ( | ) | const |
retrieve the value of the duration in seconds
Definition at line 27 of file Timer.cxx.
References duration_.
void framework::performance::Timer::reset | ( | ) |
reset a timer to un-started state without re-allocating
Definition at line 8 of file Timer.cxx.
References begin_, duration_, end_, and start_time_.
void framework::performance::Timer::start | ( | ) |
start the timer
Definition at line 15 of file Timer.cxx.
References begin_, and start_time_.
Referenced by framework::performance::Tracker::absolute_start().
void framework::performance::Timer::stop | ( | ) |
void framework::performance::Timer::write | ( | TDirectory * | location, |
const std::string & | name | ||
) | const |
Write ourselves under the input name to the input location.
This is just here to avoid repeating the boiler-plate
Since I don't like seeing &
or c_str()
in my code.
Definition at line 29 of file Timer.cxx.
Referenced by framework::performance::Tracker::~Tracker().
|
private |
|
private |
Length of time recorded by the timer in seconds.
Sub-second intervals are recorded as well (so if the timer ran for 1 millisecond you would see 0.001 stored in this member variable).
Set to -1 if timer was not ended
Definition at line 74 of file Timer.h.
Referenced by duration(), reset(), and stop().
|
private |
|
private |