Clock utility for timing and statistics in control loops.
More...
#include <sas_clock.hpp>
|
|
| Clock (const int &)=delete |
| | Clock (const double &sampling_time_in_seconds, const bool &enable_statistics=true) |
| | Construct a Clock.
|
|
void | init () |
| | Initialize the clock internal state and timers.
|
|
void | update_and_sleep () |
| | Update internal timing measurements and sleep to respect target sampling time.
|
| double | get_elapsed_time_sec () const |
| | Get elapsed time since last update in seconds.
|
| std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > | get_initial_time () const |
| | Get the initial time point recorded by the clock.
|
| std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > | get_last_update_time () const |
| | Get the time point of the last update.
|
| void | safe_sleep_seconds (const double &seconds, std::atomic_bool *break_loop) |
| | Sleep for the specified duration while allowing early exit via break_loop.
|
| void | blocking_sleep_seconds (const double &seconds) |
| | Block the calling thread for the specified duration (no early exit).
|
| double | get_desired_thread_sampling_time_sec () const |
| | Return the desired sampling time for the thread in seconds.
|
| long | get_overrun_count () const |
| | Return the number of times the sampling has overrun the target period.
|
| double | get_time (const TimeType &time_type) const |
| | Get a time value for the provided TimeType.
|
| double | get_statistics (const Statistics &statistics, const TimeType &time_type) const |
| | Get a statistic value for the given statistic type and TimeType.
|
|
double | get_computation_time () const |
| | Deprecated.
|
|
double | get_sleep_time () const |
|
double | get_effective_thread_sampling_time_sec () const |
Clock utility for timing and statistics in control loops.
◆ TimeType
Enumeration of time types, see get_time() and get_statistics().
| Enumerator |
|---|
| Computational | Time spent between when the instant the previous sleep ended and the instant when the current one started.
|
| EffectiveSampling | The effective sampling time between sleeps (EffectiveSampling = Computational + Idle).
|
| Idle | Time spent between the instant when the previous sleep started and the instant when it ended.
|
◆ Clock()
| sas::Clock::Clock |
( |
const double & | sampling_time_in_seconds, |
|
|
const bool & | enable_statistics = true ) |
|
explicit |
Construct a Clock.
- Parameters
-
| sampling_time_in_seconds | Desired sampling time in seconds |
| enable_statistics | Whether to enable internal statistics collection (default: true) |
◆ blocking_sleep_seconds()
| void sas::Clock::blocking_sleep_seconds |
( |
const double & | seconds | ) |
|
Block the calling thread for the specified duration (no early exit).
- Parameters
-
| seconds | Sleep duration in seconds |
◆ get_desired_thread_sampling_time_sec()
| double sas::Clock::get_desired_thread_sampling_time_sec |
( |
| ) |
const |
Return the desired sampling time for the thread in seconds.
- Returns
- Desired sampling time in seconds
◆ get_elapsed_time_sec()
| double sas::Clock::get_elapsed_time_sec |
( |
| ) |
const |
Get elapsed time since last update in seconds.
- Returns
- Elapsed time in seconds
◆ get_initial_time()
| std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > sas::Clock::get_initial_time |
( |
| ) |
const |
Get the initial time point recorded by the clock.
- Returns
- time_point of the initial time
◆ get_last_update_time()
| std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > sas::Clock::get_last_update_time |
( |
| ) |
const |
Get the time point of the last update.
- Returns
- time_point of the last update
◆ get_overrun_count()
| long sas::Clock::get_overrun_count |
( |
| ) |
const |
Return the number of times the sampling has overrun the target period.
- Returns
- Overrun count
◆ get_statistics()
| double sas::Clock::get_statistics |
( |
const Statistics & | statistics, |
|
|
const TimeType & | time_type ) const |
Get a statistic value for the given statistic type and TimeType.
- Parameters
-
- Returns
- The requested statistic value as a double
- Exceptions
-
| std::runtime_error | if statistics collection was not enabled at construction or if the requested statistic is not available for the provided TimeType. |
◆ get_time()
| double sas::Clock::get_time |
( |
const TimeType & | time_type | ) |
const |
Get a time value for the provided TimeType.
- Parameters
-
| time_type | The TimeType (Computational, EffectiveSampling, Idle) |
- Returns
- Time value in seconds corresponding to time_type
◆ safe_sleep_seconds()
| void sas::Clock::safe_sleep_seconds |
( |
const double & | seconds, |
|
|
std::atomic_bool * | break_loop ) |
Sleep for the specified duration while allowing early exit via break_loop.
- Parameters
-
| seconds | Sleep duration in seconds |
| break_loop | Pointer to an atomic boolean that will interrupt the sleep if set |
The documentation for this class was generated from the following files: