|
VLink 2.0.0
A high-performance communication middleware
|
Per-instance CPU utilisation profiler gated by a global environment variable. More...
#include <atomic>#include <cstdint>#include "./elapsed_timer.h"#include "./macros.h"#include "./spin_lock.h"Go to the source code of this file.
Classes | |
| class | vlink::CpuProfiler |
| Tracks CPU active time as a percentage of total elapsed wall-clock time. More... | |
Namespaces | |
| namespace | vlink |
Per-instance CPU utilisation profiler gated by a global environment variable.
CpuProfiler measures the fraction of wall-clock time that the CPU was actively executing work between paired begin() / end() calls. It uses two ElapsedTimer instances internally:
cpu_active_timer_ – measures only active time (CPU time spent in the section).cpu_timestamp_timer_ – measures total elapsed wall-clock time since begin().The utilisation ratio is:
VLINK_PROFILER_ENABLE. Set it to "1" to enable; "0" (default) to disable. The value is read once at first call to is_global_enabled() and cached for the process lifetime. begin() and end() are guarded by an internal SpinLock and are safe to call from any thread, but each profiler instance measures a single logical stream of work.begin() / end() still execute but should be short-circuited by the caller using is_global_enabled() for maximum performance.CpuProfilerGuard provides a convenient RAII wrapper that calls begin() and end() automatically.