VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::CpuProfiler类 参考final

Tracks CPU active time as a percentage of total elapsed wall-clock time. 更多...

#include <cpu_profiler.h>

vlink::CpuProfiler 的协作图:

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.

注解
Copy and assignment are disabled. Instances should be owned by a single component.

构造及析构函数说明

◆ CpuProfiler()

vlink::CpuProfiler::CpuProfiler ( )
noexcept

Constructs a profiler with all accumulators initialised to zero.

这是这个函数的调用关系图:

◆ ~CpuProfiler()

vlink::CpuProfiler::~CpuProfiler ( )
noexcept

Destructor.

函数调用图:

成员函数说明

◆ begin()

void vlink::CpuProfiler::begin ( )
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.

注解
This method acquires an internal SpinLock briefly.
函数调用图:
这是这个函数的调用关系图:

◆ end()

void vlink::CpuProfiler::end ( )
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.

注解
This method acquires an internal SpinLock briefly.
函数调用图:
这是这个函数的调用关系图:

◆ get()

double vlink::CpuProfiler::get ( ) const
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.

返回
CPU utilisation in the range [0.0, 100.0] (may exceed 100 on multi-core).
函数调用图:
这是这个函数的调用关系图:

◆ is_global_enabled()

bool vlink::CpuProfiler::is_global_enabled ( )
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.
函数调用图:
这是这个函数的调用关系图:

◆ restart()

double vlink::CpuProfiler::restart ( )
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.

注解
This method acquires an internal SpinLock briefly.
返回
CPU utilisation percentage accumulated since construction or the last restart().
函数调用图:
这是这个函数的调用关系图:

该类的文档由以下文件生成: