mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
mal_toolkit::Measurer< clock > Struct Template Reference

A class for measuring and logging the execution time of functions. More...

#include "measurer.hpp"

Inheritance diagram for mal_toolkit::Measurer< clock >:
[legend]
Collaboration diagram for mal_toolkit::Measurer< clock >:
[legend]

Classes

struct  Entry
 

Public Member Functions

 Measurer (std::string_view s="Measurer", bool log_automatically=true, float time_to_flush=30, std::source_location location=std::source_location::current())
 Construct a Measurer object.
 
void begin ()
 Start measuring execution time.
 
float end ()
 End measurement and log the result.
 
void log ()
 Log the accumulated measurements.
 
float avg (const size_t last_n_entries=std::numeric_limits< size_t >::max())
 Calculate the average execution time of the last N entries.
 
float avg_over_the_last (float seconds)
 Calculate the average execution time over a specific time interval.
 
float avg_over_the_last_limited (const float seconds)
 Calculate the average execution time over a specific time interval with a limit.
 
uint64_t amount_of_calls (float seconds)
 Calculate the amount of function calls within a specific time interval.
 
float elapsed ()
 Get the total elapsed time since the start of the measurement.
 

Public Attributes

float time_to_flush = 30
 Interval in seconds for automatic log flushing.
 
size_t maximum_entries = std::numeric_limits<size_t>::max()
 Maximum number of measurement entries.
 
bool log_automatically = true
 Determines if measurements are logged automatically.
 

Private Attributes

std::string output
 The string identifier for the measurer.
 
std::vector< Entryentries
 A vector of measurement entries.
 
size_t index = 0
 The current index in the entries vector.
 
Timer< clock > flush
 Timer for automatic log flushing.
 
Timer< clock > measure
 Timer for measuring execution time.
 
Timer< clock > entry_time
 Timer for tracking entry times.
 

Detailed Description

template<class clock>
struct mal_toolkit::Measurer< clock >

A class for measuring and logging the execution time of functions.

Template Parameters
clockThe clock type to use for timing (e.g., std::chrono::steady_clock).

Definition at line 16 of file measurer.hpp.

Constructor & Destructor Documentation

◆ Measurer()

template<class clock >
mal_toolkit::Measurer< clock >::Measurer ( std::string_view s = "Measurer< clock >",
bool log_automatically = true,
float time_to_flush = 30,
std::source_location location = std::source_location::current() )
inline

Construct a Measurer object.

Parameters
sA string identifier for the measurer.
log_automaticallyWhether to log measurements automatically.
time_to_flushTime interval for automatic log flushing (in seconds).
locationThe source location (optional) for debug logging.

Definition at line 37 of file measurer.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ amount_of_calls()

template<class clock >
uint64_t mal_toolkit::Measurer< clock >::amount_of_calls ( float seconds)
inline

Calculate the amount of function calls within a specific time interval.

Parameters
secondsTime interval in seconds.
Returns
The number of function calls.

Definition at line 165 of file measurer.hpp.

◆ avg()

template<class clock >
float mal_toolkit::Measurer< clock >::avg ( const size_t last_n_entries = std::numeric_limits<size_t>::max())
inline

Calculate the average execution time of the last N entries.

Parameters
last_n_entriesNumber of last entries to consider.
Returns
The average elapsed time in seconds.

Definition at line 104 of file measurer.hpp.

Here is the caller graph for this function:

◆ avg_over_the_last()

template<class clock >
float mal_toolkit::Measurer< clock >::avg_over_the_last ( float seconds)
inline

Calculate the average execution time over a specific time interval.

Parameters
secondsTime interval in seconds.
Returns
The average elapsed time in seconds.

Definition at line 121 of file measurer.hpp.

◆ avg_over_the_last_limited()

template<class clock >
float mal_toolkit::Measurer< clock >::avg_over_the_last_limited ( const float seconds)
inline

Calculate the average execution time over a specific time interval with a limit.

Parameters
secondsTime interval in seconds.
Returns
The average elapsed time in seconds.

Definition at line 141 of file measurer.hpp.

◆ begin()

template<class clock >
void mal_toolkit::Measurer< clock >::begin ( )
inline

Start measuring execution time.

Definition at line 54 of file measurer.hpp.

◆ elapsed()

template<class clock >
float mal_toolkit::Measurer< clock >::elapsed ( )
inline

Get the total elapsed time since the start of the measurement.

Returns
The elapsed time in seconds.

Definition at line 184 of file measurer.hpp.

Here is the caller graph for this function:

◆ end()

template<class clock >
float mal_toolkit::Measurer< clock >::end ( )
inline

End measurement and log the result.

Returns
The elapsed time in seconds.

Definition at line 60 of file measurer.hpp.

Here is the call graph for this function:

◆ log()

template<class clock >
void mal_toolkit::Measurer< clock >::log ( )
inline

Log the accumulated measurements.

Definition at line 75 of file measurer.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ entries

template<class clock >
std::vector<Entry> mal_toolkit::Measurer< clock >::entries
private

A vector of measurement entries.

Definition at line 192 of file measurer.hpp.

◆ entry_time

template<class clock >
Timer<clock> mal_toolkit::Measurer< clock >::entry_time
private

Timer for tracking entry times.

Definition at line 196 of file measurer.hpp.

◆ flush

template<class clock >
Timer<clock> mal_toolkit::Measurer< clock >::flush
private

Timer for automatic log flushing.

Definition at line 194 of file measurer.hpp.

◆ index

template<class clock >
size_t mal_toolkit::Measurer< clock >::index = 0
private

The current index in the entries vector.

Definition at line 193 of file measurer.hpp.

◆ log_automatically

template<class clock >
bool mal_toolkit::Measurer< clock >::log_automatically = true

Determines if measurements are logged automatically.

Definition at line 188 of file measurer.hpp.

◆ maximum_entries

template<class clock >
size_t mal_toolkit::Measurer< clock >::maximum_entries = std::numeric_limits<size_t>::max()

Maximum number of measurement entries.

Definition at line 187 of file measurer.hpp.

◆ measure

template<class clock >
Timer<clock> mal_toolkit::Measurer< clock >::measure
private

Timer for measuring execution time.

Definition at line 195 of file measurer.hpp.

◆ output

template<class clock >
std::string mal_toolkit::Measurer< clock >::output
private

The string identifier for the measurer.

Definition at line 191 of file measurer.hpp.

◆ time_to_flush

template<class clock >
float mal_toolkit::Measurer< clock >::time_to_flush = 30

Interval in seconds for automatic log flushing.

Definition at line 186 of file measurer.hpp.


The documentation for this struct was generated from the following file: