File timer.hpp¶
Some tools to measure (ellapsed) time.
- Author
Maximilien Naveau (maximilien.naveau@gmail.com) license License BSD-3-Clause
- Copyright
Copyright (c) 2019, New York University and Max Planck Gesellschaft.
- Date
2019-05-22
-
namespace
real_time_tools
-
class
Timer
- #include <timer.hpp>
The timer class is a simple time measurement class that measure between tic and tac and with a memory buffer of a certain size.
Public Functions
-
Timer
() timer constructor
-
void
tic
() tic measures the time when it is called.
This is to be used with the tac method that will return the time elapsed between tic and tac.
-
double
tac
() tac is to be used after tic has been called.
-
double
tac_tic
() this is like a tac() followed by a tic(), making sure the previous tac_time becomes the tic_time
-
void
log_time_interval
(double time_interval) Save the time interval measured.
- Parameters:
time_interval –
-
void
dump_measurements
(std::string file_name) const IOSTREAM functions.
dump_tic_tac_measurements writes in a file the time elapsed between every tick
- Parameters:
file_name – is the path to the file.
-
void
print_statistics
() const print_statistics display in real time the statistics of the time measurements acquiered so far.
-
inline void
set_memory_size
(const unsigned memory_buffer_size) SETTERS.
set_memory_size sets the buffer size. It resets all value of the buffer to zero. !! WARNING non real time method. !!
- Parameters:
memory_buffer_size – is the size use to reset the size of the
-
inline void
set_name
(std::string name) set_name modify the name of the object for display purposes.
- Parameters:
name – is the new name of the object.
-
inline double
get_min_elapsed_sec
() const GETTERS.
get_min_elapsed_sec
- Returns:
a copy of the minimum elapsed times
-
inline double
get_max_elapsed_sec
() const get_max_elapsed_sec
- Returns:
a copy of the maximum elapsed times
-
inline double
get_avg_elapsed_sec
() const get_avg_elapsed_sec
- Returns:
a copy of the average elapsed time
-
inline double
get_std_dev_elapsed_sec
() const get_std_dev_elapsed_sec
- Returns:
a copy of the standard deviation of the elapsed times
Public Static Functions
-
static double
get_current_time_sec
() Some utilities.
get_current_time_sec gives the current time in double and in seconds
- Returns:
-
static inline double
get_current_time_ms
() get_current_time_ms gives the current time in double and in milli seconds
- Returns:
-
static int
sleep_microseconds
(int sleep_duration_us) puts the current thread to sleep for the duration of “sleep_duration_us” micro-seconds.
- Parameters:
sleep_time_us – is the sleeping duration asked in micro-seconds.
- Returns:
0 on success, error code otherwise
-
static void
sleep_sec
(const double &sleep_time_sec) sleep_sec puts the current thread to sleep for the duration of “sleep_time_sec” seconds.
- Parameters:
sleep_time_sec – is the sleeping duration asked in seconds.
-
static inline void
sleep_ms
(const double &sleep_time_ms) sleep_ms puts the current thread to sleep for the duration of “sleep_time_sec” seconds.
- Parameters:
sleep_time_ms – is the sleeping duration asked in seconds.
-
static void
sleep_until_sec
(const double &date_sec) sleep_until_sec puts the threads to sleep until the date “date_sec” is reached.
- Parameters:
date_sec – is the date until when to sleep in seconds.
-
static void
timespec_add_sec
(struct timespec &date_spec, const double duration_sec) timespec_add_sec posix type of a date in time.
- Parameters:
date_spec – is the date to be changed
duration_sec – the duration to be added to “t” in seconds
-
static void
sec_to_timespec
(double date_sec, struct timespec &date_spec) sec_to_timespec converts a double representing the time in seconds to a struct timespec.
- Parameters:
date_sec – [in] is the time in sec to be converted.
date_spec – [out] is the converted structure.
-
static std::string
get_current_date_str
() get_current_date_str get the current date and format it in a string with “year_month_day_hour_minute_sec”
Protected Attributes
-
std::deque<double>
time_measurement_buffer_
¶ time_measurement_buffer_ this is a chained list of double
-
long unsigned count_
count_time_buffer_ is a counter that manages the time_measurement_buffer_ fill in.
-
unsigned
memory_buffer_size_
¶ memory_buffer_size_ is the max size of the memory buffer.
-
double
min_elapsed_time_
¶ min_elapsed_time_ is the minimum measured elapsed time
-
double
max_elapsed_time_
¶ max_elapsed_time_ is the maximum measured elapsed time
-
double
avg_elapsed_time_
¶ avg_elapsed_time_ is the average measured elapsed time
-
double
second_moment_elapsed_time_
¶ avg_elapsed_time_ is the second moment measured elapsed time
-
std::string
name_
¶ name_ of the timer object
-
-
class