56 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_initial_;
57 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> next_loop_deadline_;
59 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_before_sleep_;
60 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_after_sleep_;
62 const std::chrono::nanoseconds target_sampling_time_;
64 std::map<TimeType,std::chrono::nanoseconds> kept_times_map_;
66 long overrun_sampling_time_count_;
68 const bool enable_statistics_;
70 std::map<std::tuple<TimeType,Statistics>,std::tuple<std::chrono::nanoseconds,long>> statistics_map_;
71 void _compute_statistics_();
76 Clock(
const int&)=
delete;
83 explicit Clock(
const double& sampling_time_in_seconds,
const bool& enable_statistics=
true);
105 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
get_initial_time()
const;
111 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
get_last_update_time()
const;
143 double get_time(
const TimeType& time_type)
const;
151 double get_statistics(
const Statistics &statistics,
const TimeType &time_type)
const;
154 [[deprecated(
"Use get_time(sas::Clock::Computational) instead.")]]
156 [[deprecated(
"Use get_time(sas::Clock::Idle) instead.")]]
157 double get_sleep_time()
const;
158 [[deprecated(
"Use get_time(sas::Clock::EffectiveSampling) instead.")]]
159 double get_effective_thread_sampling_time_sec()
const;
Definition sas_clock.hpp:46
long get_overrun_count() const
Return the number of times the sampling has overrun the target period.
Definition sas_clock.cpp:152
double get_time(const TimeType &time_type) const
Get a time value for the provided TimeType.
Definition sas_clock.cpp:157
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:136
double get_computation_time() const
Deprecated.
Definition sas_clock.cpp:115
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:110
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:164
void blocking_sleep_seconds(const double &seconds)
Block the calling thread for the specified duration (no early exit)
Definition sas_clock.cpp:144
void update_and_sleep()
Update internal timing measurements and sleep to respect target sampling time.
Definition sas_clock.cpp:64
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:100
double get_desired_thread_sampling_time_sec() const
Return the desired sampling time for the thread in seconds.
Definition sas_clock.cpp:120
void init()
Initialize the clock internal state and timers.
Definition sas_clock.cpp:51
double get_elapsed_time_sec() const
Get elapsed time since last update in seconds.
Definition sas_clock.cpp:130
Definition sas_object.hpp:39
Core numerical utilities and helpers used across the project.
Base object class for identification and license utilities.