27 struct MultiTimer::Entry {
33 std::chrono::duration<double> duration;
54 for (
size_t i = 0; i <
timers_.size(); ++i) {
59 new_entry.hash =
hash;
60 new_entry.name = name;
61 new_entry.duration = std::chrono::duration<double>::zero();
62 timers_.emplace_back(new_entry);
70 static bool warning_shown =
false;
72 TLX_LOG1 <<
"MultiTimer: trying to start timer " 73 << timer <<
" twice!";
74 TLX_LOG1 <<
"MultiTimer: multi-threading is not supported, " 85 auto new_time_point = std::chrono::high_resolution_clock::now();
116 os <<
"TIMER info=" << info;
117 for (
const Entry& timer :
timers_) {
118 os <<
' ' << timer.name <<
'=' << timer.duration.count();
124 return print(info, std::cerr);
128 std::unique_lock<std::mutex> lock(s_timer_add_mutex);
130 TLX_LOG1 <<
"MultiTimer: trying to add running timer";
132 for (
const Entry& t : b.
timers_) {
134 e.duration += t.duration;
149 : timer_(timer), previous_(timer.
running()) {
~ScopedMultiTimerSwitch()
change back timer to previous timer.
~ScopedMultiTimer()
change back timer to previous timer.
void print(const char *info, std::ostream &os) const
print all timers as a TIMER line to os
MultiTimer & base_
reference to base timer
const char * running() const
return name of currently running timer.
static std::mutex s_timer_add_mutex
MultiTimer & operator=(const MultiTimer &)
default assignment operator
static uint32_t hash_djb2(const unsigned char *str)
Simple, fast, but "insecure" string hash method by Dan Bernstein from http://www.cse.yorku.ca/~oz/hash.html.
ScopedMultiTimerSwitch(MultiTimer &timer, const char *new_timer)
construct and timer to switch to
MultiTimer can be used to measure time usage of different phases in a program or algorithm.
MultiTimer & add(const MultiTimer &b)
std::vector< Entry > timers_
array of timers
const char * running_
currently running timer name
void stop()
stop the currently running timer.
MultiTimer & timer_
reference to MultiTimer
MultiTimer & operator+=(const MultiTimer &b)
double total() const
return total duration of all timers.
void start(const char *timer)
start new timer phase, stop the currently running one.
ScopedMultiTimer(MultiTimer &base, const char *timer)
construct and change timer to tm
double get(const char *timer)
return timer duration in seconds of timer.
const char * previous_
previous timer, used to switch back to on destruction
Entry & find_or_create(const char *name)
internal methods to find or create new timer entries
HashCrc32< T > hash
Select a hashing method.
std::chrono::duration< double > total_duration_
total duration
std::chrono::time_point< std::chrono::high_resolution_clock > time_point_
start of currently running timer name
uint32_t running_hash_
hash of running_
#define tlx_die_unless(X)
MultiTimer timer_
contained independent timer