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;
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";
149 : timer_(timer), previous_(timer.
running()) {
~ScopedMultiTimerSwitch()
change back timer to previous timer.
~ScopedMultiTimer()
change back timer to previous timer.
MultiTimer & base_
reference to base timer
const char * name
reference to original string for comparison
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.
uint32_t hash
hash of name for faster search
MultiTimer & add(const MultiTimer &b)
add all timers from another, internally holds a global mutex lock, because this is used to add thread...
const char * running() const
return name of currently running timer.
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)
add all timers from another, internally holds a global mutex lock, because this is used to add thread...
void start(const char *timer)
start new timer phase, stop the currently running one.
void print(const char *info, std::ostream &os) const
print all timers as a TIMER line to os
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
std::chrono::duration< double > duration
duration of this timer
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
double total() const
return total duration of all timers.
uint32_t running_hash_
hash of running_
#define tlx_die_unless(X)
Check condition X and die miserably if false.
MultiTimer timer_
contained independent timer