ark::pipeline::PeriodicTimer
Defined in header “ark/pipeline/periodic_timer.hh”.
A timer that is used to execute a function periodically. That function takes in the current time. This allows you to deterministically execute functions at some fixed rate.
Methods
-
PeriodicTimer(PeriodicTimerConfiguration config)
Constructor. Initialize a timer with the given configuration. -
~PeriodicTimer()
Virtual destructor, for cleanup. -
void reset_to_time(const std::chrono::steady_clock::time_point & time)
Resets the timer to the given timestamp. No executions will occur, and future ticks/elapsed calls will be relative to this timestamp. All elapsed time will be erased. -
bool tick(const std::chrono::steady_clock::time_point & now)
Called periodically with the current clock (virtual or otherwise). This will register the times that a timer should execute, so that downstream code can take care of executing them.Returns true if execute() will need to be invoked, false otherwise.
-
size_t queue_size()
Returns the number of executions remaining (the number of times you can invoke execute()). -
bool pop(TimerWorkItem & item)
Pops the oldest execution off the queue and returns a work item. This is the first phase of execution, allowing you to deterministically pop an execution time off the timer, and execute it in a background thread.Returns true if the pop was successful, false if the queue is empty.
-
void execute_work_item(TimerWorkItem && item)
The second half of timer execution. Consumes the given timer work item as received from pop(), taking ownership of it, and then invokes the callback. -
bool execute()
Pops the oldest execution off the queue and executes the callback against it. Returns true if something was executed, or false otherwise. -
std::chrono::nanoseconds time_remaining(const std::chrono::steady_clock::time_point & now)
Returns the amount of time left before the next execution, based on the given timestamp. -
TimerStatistics statistics()
Returns statistics related to this timer. -
TimerCallbackTimings timings()
Returns timing information related to this timer’s callback. -
std::chrono::nanoseconds configured_expected_runtime()
Returns the configured execution time for this timer. -
std::chrono::nanoseconds expected_runtime(const TimerWorkItem & item)
Returns the expected runtime as if this timer had executed the given work item. -
std::string name()
Returns the human-readable name assigned to the timer.