tlx
|
MultiTimer can be used to measure time usage of different phases in a program or algorithm. More...
#include <multi_timer.hpp>
Classes | |
struct | Entry |
Public Member Functions | |
MultiTimer () | |
constructor More... | |
MultiTimer (const MultiTimer &) | |
default copy-constructor More... | |
MultiTimer & | operator= (const MultiTimer &) |
default assignment operator More... | |
MultiTimer (MultiTimer &&) | |
move-constructor: default More... | |
MultiTimer & | operator= (MultiTimer &&) |
move-assignment operator: default More... | |
~MultiTimer () | |
destructor More... | |
void | start (const char *timer) |
start new timer phase, stop the currently running one. More... | |
void | stop () |
stop the currently running timer. More... | |
void | reset () |
zero timers. More... | |
const char * | running () const |
return name of currently running timer. More... | |
double | get (const char *timer) |
return timer duration in seconds of timer. More... | |
double | total () const |
return total duration of all timers. More... | |
void | print (const char *info, std::ostream &os) const |
print all timers as a TIMER line to os More... | |
void | print (const char *info) const |
print all timers as a TIMER line to stderr More... | |
MultiTimer & | add (const MultiTimer &b) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values More... | |
MultiTimer & | operator+= (const MultiTimer &b) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values More... | |
Private Member Functions | |
Entry & | find_or_create (const char *name) |
internal methods to find or create new timer entries More... | |
Private Attributes | |
std::vector< Entry > | timers_ |
array of timers More... | |
std::chrono::duration< double > | total_duration_ |
total duration More... | |
const char * | running_ |
currently running timer name More... | |
uint32_t | running_hash_ |
hash of running_ More... | |
std::chrono::time_point< std::chrono::high_resolution_clock > | time_point_ |
start of currently running timer name More... | |
MultiTimer can be used to measure time usage of different phases in a program or algorithm.
It contains multiple named "timers", which can be activated without prior definition. At most one timer is start at any time, which means start()
will stop any current timer and start a new one.
Timers are identified by strings, which are passed as const char*, which MUST remain valid for the lifetime of the MultiTimer. Dynamic strings will not work, the standard way is to use plain string literals. The strings are hash for faster searches.
MultiTimer can also be used for multi-threading parallel programs. Each thread must create and keep its own MultiTimer instance, which can then be added together into a global MultiTimer object. The add() method of the global object is internally thread-safe using a global mutex.
Definition at line 36 of file multi_timer.hpp.
MultiTimer | ( | ) |
constructor
Definition at line 39 of file multi_timer.cpp.
|
default |
default copy-constructor
|
default |
move-constructor: default
|
default |
destructor
MultiTimer & add | ( | const MultiTimer & | b | ) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values
Definition at line 127 of file multi_timer.cpp.
|
private |
internal methods to find or create new timer entries
Definition at line 52 of file multi_timer.cpp.
double get | ( | const char * | timer | ) |
return timer duration in seconds of timer.
Definition at line 105 of file multi_timer.cpp.
MultiTimer & operator+= | ( | const MultiTimer & | b | ) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values
Definition at line 140 of file multi_timer.cpp.
|
default |
default assignment operator
|
default |
move-assignment operator: default
void print | ( | const char * | info, |
std::ostream & | os | ||
) | const |
print all timers as a TIMER line to os
Definition at line 113 of file multi_timer.cpp.
void print | ( | const char * | info | ) | const |
print all timers as a TIMER line to stderr
Definition at line 123 of file multi_timer.cpp.
void reset | ( | ) |
zero timers.
Definition at line 96 of file multi_timer.cpp.
const char * running | ( | ) | const |
return name of currently running timer.
Definition at line 101 of file multi_timer.cpp.
void start | ( | const char * | timer | ) |
start new timer phase, stop the currently running one.
Definition at line 66 of file multi_timer.cpp.
void stop | ( | ) |
stop the currently running timer.
Definition at line 84 of file multi_timer.cpp.
double total | ( | ) | const |
return total duration of all timers.
Definition at line 109 of file multi_timer.cpp.
|
private |
currently running timer name
Definition at line 95 of file multi_timer.hpp.
|
private |
hash of running_
Definition at line 97 of file multi_timer.hpp.
|
private |
start of currently running timer name
Definition at line 99 of file multi_timer.hpp.
|
private |
array of timers
Definition at line 86 of file multi_timer.hpp.
|
private |
total duration
Definition at line 92 of file multi_timer.hpp.