VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
cpu_profiler_guard.h File Reference

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

#include "./macros.h"
Include dependency graph for cpu_profiler_guard.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

 RAII scope guard that brackets a CpuProfiler active interval. More...

Namespaces

Detailed Description

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();
Note
  • 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.