VLink  2.0.0
A high-performance communication middleware
elapsed_timer.h 文件参考

Lowest-level elapsed-time primitive used by deadline tracking, profilers and task metrics. 更多...

#include <atomic>
#include <cstdint>
#include "./macros.h"
elapsed_timer.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

class  vlink::ElapsedTimer
 Atomic high-resolution timer with selectable clock source and unit. 更多...
 

命名空间

 

详细描述

Lowest-level elapsed-time primitive used by deadline tracking, profilers and task metrics.

ElapsedTimer measures how much time has passed since start was called, using either a monotonic wall clock or process CPU time, with millisecond / microsecond / nanosecond resolution. It backs DeadlineTimer, CpuProfiler and the message-loop task latency counters.

API table
Method Purpose Mutates state
start Latch the current time as the start reference yes
stop Mark the timer inactive (start = -1) yes
restart Read elapsed, latch new start atomically yes
get Read elapsed without changing state no
is_active Report whether start has set the reference no
get_sys_timestamp Sample wall-clock time (CLOCK_REALTIME) no
get_cpu_timestamp Sample monotonic time (CLOCK_MONOTONIC_RAW) no
get_cpu_active_time Sample cumulative process CPU time no
Clock source (Method)
Value Clock source Notes
kCpuTimestamp std::chrono::steady_clock Monotonic wall time, never jumps
kCpuActiveTime getrusage / GetProcessTimes Total process user + kernel time
Precision (Accuracy)
Value Unit 64-bit dynamic range
kMilli milliseconds ~292 million years
kMicro microseconds ~292 thousand years
kNano nanoseconds ~292 years
Example
t.start();
do_work();
const int64_t us = t.get(); // microseconds since start; -1 if not started
const int64_t since = t.restart(); // read + atomic reset
t.stop();
注解
The timer is not started by the constructor; call start explicitly. The internal start time is held in a 64-byte aligned std::atomic<int64_t>; concurrent reads are safe, but interleaved start / stop from different threads race on the active flag.