60 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_initial_;
61 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> next_loop_deadline_;
63 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_before_sleep_;
64 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_after_sleep_;
66 const std::chrono::nanoseconds target_sampling_time_;
68 std::map<TimeType,std::chrono::nanoseconds> kept_times_map_;
70 long overrun_sampling_time_count_;
72 const bool enable_statistics_;
74 std::map<std::tuple<TimeType,Statistics>,std::tuple<std::chrono::nanoseconds,long>> statistics_map_;
75 void _compute_statistics_();
80 Clock(
const int&)=
delete;
87 explicit Clock(
const double& sampling_time_in_seconds,
const bool& enable_statistics=
true);
109 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
get_initial_time()
const;
115 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
get_last_update_time()
const;
160 [[deprecated(
"Use get_time(sas::Clock::Computational) instead.")]]
162 [[deprecated(
"Use get_time(sas::Clock::Idle) instead.")]]
163 double get_sleep_time()
const;
164 [[deprecated(
"Use get_time(sas::Clock::EffectiveSampling) instead.")]]
165 double get_effective_thread_sampling_time_sec()
const;
Clock utility for timing and statistics in control loops.
Definition sas_clock.hpp:49
long get_overrun_count() const
Return the number of times the sampling has overrun the target period.
Definition sas_clock.cpp:157
TimeType
Enumeration of time types, see get_time() and get_statistics().
Definition sas_clock.hpp:52
@ EffectiveSampling
The effective sampling time between sleeps (EffectiveSampling = Computational + Idle).
Definition sas_clock.hpp:54
@ Computational
Time spent between when the instant the previous sleep ended and the instant when the current one sta...
Definition sas_clock.hpp:53
@ Idle
Time spent between the instant when the previous sleep started and the instant when it ended.
Definition sas_clock.hpp:55
double get_time(const TimeType &time_type) const
Get a time value for the provided TimeType.
Definition sas_clock.cpp:162
void safe_sleep_seconds(const double &seconds, std::atomic_bool *break_loop)
Sleep for the specified duration while allowing early exit via break_loop.
Definition sas_clock.cpp:141
double get_computation_time() const
Deprecated.
Definition sas_clock.cpp:120
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > get_last_update_time() const
Get the time point of the last update.
Definition sas_clock.cpp:115
double get_statistics(const Statistics &statistics, const TimeType &time_type) const
Get a statistic value for the given statistic type and TimeType.
Definition sas_clock.cpp:169
void blocking_sleep_seconds(const double &seconds)
Block the calling thread for the specified duration (no early exit).
Definition sas_clock.cpp:149
void update_and_sleep()
Update internal timing measurements and sleep to respect target sampling time.
Definition sas_clock.cpp:69
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > get_initial_time() const
Get the initial time point recorded by the clock.
Definition sas_clock.cpp:105
double get_desired_thread_sampling_time_sec() const
Return the desired sampling time for the thread in seconds.
Definition sas_clock.cpp:125
void init()
Initialize the clock internal state and timers.
Definition sas_clock.cpp:56
double get_elapsed_time_sec() const
Get elapsed time since last update in seconds.
Definition sas_clock.cpp:135
Base class for SAS objects.
Definition sas_object.hpp:40
Core numerical utilities used across the project.
Statistics
Statistical measures supported by sas_core utilities.
Definition sas_core.hpp:49
Base object class for identification and license utilities.