|
VLink
2.0.0
A high-performance communication middleware
|
Per-instance CPU utilisation sampler with an env-driven global enable gate. 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 active CPU time as a percentage of wall-clock time using a SpinLock guard. More... | |
Namespaces | |
| vlink | |
Per-instance CPU utilisation sampler with an env-driven global enable gate.
CpuProfiler measures the fraction of wall-clock time spent inside paired begin / end intervals. Two ElapsedTimer instances back the computation: one accrues active intervals; the other captures the total wall-clock span since the first begin. The reported utilisation is therefore the ratio of accumulated active time to elapsed wall time.
| Phase / event | Source | Effect on counters |
|---|---|---|
First begin | active timer + timestamp timer | Both timers start |
Subsequent begin | active timer restart | Resets the active baseline |
end | active timer elapsed | Adds positive delta to total_active_ |
get | read-only | Returns (active / elapsed) * 100 |
restart | read + reset | Returns the value then zeroes counters |
* vlink::CpuProfiler profiler;
* --------------------------------------------------------
* {
* vlink::CpuProfilerGuard guard(&profiler); // begin()
* do_work();
* } // end()
* const double percent = profiler.get();
* --------------------------------------------------------
* VLINK_PROFILER_ENABLE is read on the first call to is_global_enabled and cached for the remainder of the process lifetime. Set it to "1" to enable; any other value disables.