|
VLink 2.0.0
A high-performance communication middleware
|
High-resolution elapsed-time measurement with configurable clock source and precision. More...
Go to the source code of this file.
Classes | |
| class | vlink::ElapsedTimer |
| Atomic, high-resolution elapsed-time timer. More... | |
Namespaces | |
| namespace | vlink |
High-resolution elapsed-time measurement with configurable clock source and precision.
ElapsedTimer measures how much time (wall-clock or CPU-active time) has elapsed since start() was called. It is the lowest-level timing primitive in VLink and is used internally by DeadlineTimer, CpuProfiler, and the message-loop task latency tracking.
Two independent axes of configuration are available:
| Value | Clock source | Notes |
|---|---|---|
| kCpuTimestamp | CLOCK_MONOTONIC_RAW / steady_clock | Monotonic wall time, never jumps |
| kCpuActiveTime | getrusage / GetProcessTimes | CPU user+kernel time consumed |
| Value | Unit | Range (64-bit) |
|---|---|---|
| kMilli | milliseconds | ~292 million years |
| kMicro | microseconds | ~292 thousand years |
| kNano | nanoseconds | ~292 years |
start() explicitly.get() returns -1 when the timer has not been started or has been stopped.start_time_ is stored as a std::atomic<int64_t>, making concurrent reads from multiple threads safe, though concurrent start()/stop() calls from different threads lead to a data race on the "is started" semantic.get_sys_timestamp() uses CLOCK_REALTIME via clock_gettime for nanosecond resolution; on Windows it falls back to std::chrono::system_clock.get_cpu_timestamp() uses CLOCK_MONOTONIC_RAW on Linux (immune to NTP adjustments) and std::chrono::steady_clock on other platforms.