![]() |
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Lightweight elapsed-cycle measurement utility. More...
#include <stk_time_util.h>
Public Member Functions | |
| Stopwatch () | |
| Construct a Stopwatch. | |
| template<typename Func> | |
| void | Start (Func now_func) |
| Capture the start time. | |
| template<typename Func> | |
| Cycles | Update (Func now_func) |
| Return the number of cycles elapsed since the last Start() or Update(). | |
Protected Attributes | |
| Cycles | m_prev |
| Counter value captured at the last Start() or Update() call. | |
Static Private Attributes | |
| static constexpr Cycles | NOT_STARTED = 0ULL |
| Value of m_prev meaning that stopwatch is not started. | |
Lightweight elapsed-cycle measurement utility.
Measures the number of CPU cycles (or other monotonic counter units) that have elapsed between successive calls to Update(). The time source is supplied by the caller as a callable (function pointer, lambda, or functor), allowing the stopwatch to remain independent of any particular hardware counter.
Typical usage:
Definition at line 156 of file stk_time_util.h.
|
inline |
Construct a Stopwatch.
Definition at line 166 of file stk_time_util.h.
References m_prev, and NOT_STARTED.
|
inline |
Capture the start time.
| Func | Callable type returning a Cycles value. |
| [in] | now_func | Callable invoked with no arguments that returns the current time as a Cycles value (e.g. a CPU cycle counter read function or a lambda wrapping one). |
Definition at line 178 of file stk_time_util.h.
References m_prev.
|
inline |
Return the number of cycles elapsed since the last Start() or Update().
| Func | Callable type returning a Cycles value. |
| [in] | now_func | Callable invoked with no arguments that returns the current time as a Cycles value. Must be the same counter source used in the preceding Start() call. |
Cycles since the previous reference point. Returns 0 on the very first call when Start() was not called beforehand (the call itself becomes the new reference point). Definition at line 195 of file stk_time_util.h.
References m_prev, NOT_STARTED, and STK_UNLIKELY.
|
protected |
Counter value captured at the last Start() or Update() call.
Definition at line 211 of file stk_time_util.h.
Referenced by Start(), Stopwatch(), and Update().
|
staticconstexprprivate |
Value of m_prev meaning that stopwatch is not started.
Definition at line 158 of file stk_time_util.h.
Referenced by Stopwatch(), and Update().