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 | |
MultiTimer (const MultiTimer &) | |
default copy-constructor | |
MultiTimer & | operator= (const MultiTimer &) |
default assignment operator | |
MultiTimer (MultiTimer &&) | |
move-constructor: default | |
MultiTimer & | operator= (MultiTimer &&) |
move-assignment operator: default | |
~MultiTimer () | |
destructor | |
void | start (const char *timer) |
start new timer phase, stop the currently running one. | |
void | stop () |
stop the currently running timer. | |
void | reset () |
zero timers. | |
const char * | running () const |
return name of currently running timer. | |
double | get (const char *timer) |
return timer duration in seconds of timer. | |
double | total () const |
return total duration of all timers. | |
void | print (const char *info, std::ostream &os) const |
print all timers as a TIMER line to os | |
void | print (const char *info) const |
print all timers as a TIMER line to stderr | |
MultiTimer & | add (const MultiTimer &b) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values | |
MultiTimer & | operator+= (const MultiTimer &b) |
add all timers from another, internally holds a global mutex lock, because this is used to add thread values | |
Private Member Functions | |
Entry & | find_or_create (const char *name) |
internal methods to find or create new timer entries | |
Private Attributes | |
std::vector< Entry > | timers_ |
array of timers | |
std::chrono::duration< double > | total_duration_ |
total duration | |
const char * | running_ |
currently running timer name | |
std::uint32_t | running_hash_ |
hash of running_ | |
std::chrono::time_point< std::chrono::high_resolution_clock > | time_point_ |
start of currently running timer name | |
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 37 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 126 of file multi_timer.cpp.
|
private |
internal methods to find or create new timer entries
Definition at line 51 of file multi_timer.cpp.
double get | ( | const char * | timer | ) |
return timer duration in seconds of timer.
Definition at line 104 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 139 of file multi_timer.cpp.
|
default |
default assignment operator
|
default |
move-assignment operator: default
void print | ( | const char * | info | ) | const |
print all timers as a TIMER line to stderr
Definition at line 122 of file multi_timer.cpp.
void print | ( | const char * | info, |
std::ostream & | os | ||
) | const |
print all timers as a TIMER line to os
Definition at line 112 of file multi_timer.cpp.
void reset | ( | ) |
zero timers.
Definition at line 95 of file multi_timer.cpp.
const char * running | ( | ) | const |
return name of currently running timer.
Definition at line 100 of file multi_timer.cpp.
void start | ( | const char * | timer | ) |
start new timer phase, stop the currently running one.
Definition at line 65 of file multi_timer.cpp.
void stop | ( | ) |
stop the currently running timer.
Definition at line 83 of file multi_timer.cpp.
double total | ( | ) | const |
return total duration of all timers.
Definition at line 108 of file multi_timer.cpp.
|
private |
currently running timer name
Definition at line 96 of file multi_timer.hpp.
|
private |
hash of running_
Definition at line 98 of file multi_timer.hpp.
|
private |
start of currently running timer name
Definition at line 100 of file multi_timer.hpp.
|
private |
array of timers
Definition at line 90 of file multi_timer.hpp.
|
private |
total duration
Definition at line 93 of file multi_timer.hpp.