|
VLink 2.0.0
A high-performance communication middleware
|
Tracks CPU active time as a percentage of total elapsed wall-clock time. 更多...
#include <cpu_profiler.h>
Public 成员函数 | |
| CpuProfiler () noexcept | |
| Constructs a profiler with all accumulators initialised to zero. | |
| ~CpuProfiler () noexcept | |
| Destructor. | |
| void | begin () noexcept |
| Marks the start of an active CPU work section. | |
| void | end () noexcept |
| Marks the end of an active CPU work section and accumulates the elapsed time. | |
| double | get () const noexcept |
| Returns the current CPU utilisation ratio as a percentage. | |
| double | restart () noexcept |
| Returns the current utilisation and resets all accumulators to zero. | |
静态 Public 成员函数 | |
| static bool | is_global_enabled () noexcept |
| Returns whether CPU profiling is globally enabled via environment variable. | |
Tracks CPU active time as a percentage of total elapsed wall-clock time.
Each begin() / end() pair contributes one active interval to the running total. get() returns the cumulative utilisation ratio; restart() returns the ratio and resets all accumulators.
|
noexcept |
Constructs a profiler with all accumulators initialised to zero.
|
noexcept |
Destructor.
|
noexcept |
Marks the start of an active CPU work section.
Restarts the active-time timer. If this is the very first call, also starts the wall-clock timestamp timer used as the denominator in get(). Safe to call multiple times; each call resets the active-timer baseline.
SpinLock briefly.
|
noexcept |
Marks the end of an active CPU work section and accumulates the elapsed time.
Reads the active-time elapsed since the last begin() and adds it to the running total (total_active_). Negative elapsed values (e.g., clock skew) are ignored.
SpinLock briefly.
|
nodiscardnoexcept |
Returns the current CPU utilisation ratio as a percentage.
Computes: (total_active_ns / total_elapsed_ns) * 100.0 Returns 0.0 if no time has elapsed since profiling started.
|
staticnodiscardnoexcept |
Returns whether CPU profiling is globally enabled via environment variable.
Reads VLINK_PROFILER_ENABLE on the first call and caches the result. Returns true if the variable is set to "1", false otherwise.
true if profiling is enabled globally.
|
noexcept |
Returns the current utilisation and resets all accumulators to zero.
The return value is identical to calling get() before the reset. After this call, get() returns 0.0 until the next begin() / end() pair.
SpinLock briefly.restart().