|
VLink
2.0.0
A high-performance communication middleware
|
Tracks active CPU time as a percentage of wall-clock time using a SpinLock guard.
更多...
#include <cpu_profiler.h>
Public 成员函数 | |
| CpuProfiler () noexcept | |
| Constructs a profiler with zeroed accumulators and no active interval. 更多... | |
| ~CpuProfiler () noexcept | |
| Destructor. 更多... | |
| void | begin () noexcept |
| Opens a new active interval. 更多... | |
| void | end () noexcept |
| Closes the current active interval and accrues its elapsed time. 更多... | |
| double | get () const noexcept |
| Returns the current CPU utilisation ratio as a percentage. 更多... | |
| double | restart () noexcept |
| Returns the current utilisation and atomically zeroes all accumulators. 更多... | |
静态 Public 成员函数 | |
| static bool | is_global_enabled () noexcept |
Reports whether profiling is enabled via the VLINK_PROFILER_ENABLE environment variable. 更多... | |
Tracks active CPU time as a percentage of wall-clock time using a SpinLock guard.
Each begin / end pair contributes one active interval to the running total. get returns the ratio of active to elapsed time; restart returns the same value and clears the accumulators atomically. Non-copyable; each profiler tracks a single logical stream.
|
noexcept |
Constructs a profiler with zeroed accumulators and no active interval.
|
noexcept |
Destructor.
|
noexcept |
Opens a new active interval.
Restarts the internal active timer and, on the first call, also starts the wall-clock timer used as the denominator in get. Acquires the internal SpinLock briefly.
|
noexcept |
Closes the current active interval and accrues its elapsed time.
Reads the active timer's elapsed value and adds non-negative deltas to total_active_. Acquires the internal SpinLock briefly.
|
noexcept |
Returns the current CPU utilisation ratio as a percentage.
Computed as (total_active_ns / total_elapsed_ns) * 100.0. Returns 0.0 when no time has elapsed yet. Values can exceed 100 on multi-core systems where the sum of active intervals outruns wall-clock time on one core.
0.0 when no data has accrued.
|
staticnoexcept |
Reports whether profiling is enabled via the VLINK_PROFILER_ENABLE environment variable.
The environment is sampled lazily on the first call and cached for the process lifetime. Use the return value to gate expensive sampling around begin / end pairs.
true when VLINK_PROFILER_ENABLE is set to "1".
|
noexcept |
Returns the current utilisation and atomically zeroes all accumulators.
Equivalent to reading get and then resetting both timers. Acquires the internal SpinLock briefly.
restart.