VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
cpu_profiler_guard.h 文件参考

RAII guard that automatically calls CpuProfiler::begin() and CpuProfiler::end(). 更多...

#include "./macros.h"
cpu_profiler_guard.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

 RAII scope guard that brackets a CpuProfiler active interval. 更多...

命名空间

详细描述

RAII guard that automatically calls CpuProfiler::begin() and CpuProfiler::end().

CpuProfilerGuard is a lightweight RAII wrapper that calls CpuProfiler::begin() in its constructor and CpuProfiler::end() in its destructor. This ensures the active interval is always closed, even if an exception is thrown.

Example
void process_frame() {
vlink::CpuProfilerGuard guard(&profiler);
// ... do work ...
} // profiler.end() called here automatically
double usage = profiler.get();
注解
  • Passing nullptr as the profiler pointer is safe; both constructor and destructor check for nullptr before calling any method.
  • The guard is non-copyable and non-movable; it must be used as a stack-allocated object.
  • Use CpuProfiler::is_global_enabled() to skip guard construction when profiling is disabled globally, reducing overhead in hot paths.