CSimProfiler & CSimScopeProfiler – Scoped High-Resolution Profiling
These classes provide a lightweight, high-resolution profiling mechanism for measuring execution time of code blocks or functions.
They use std::chrono::steady_clock by default for monotonic and reliable time measurements, and allow integration with a running average collector.
Key Components
- CProfilerType – A template wrapper to easily define the clock type for profiling. By default, it uses
std::chrono::steady_clock. - CSimScopeProfiler – RAII-style scoped profiler. Automatically measures the time between construction and destruction of the object.
- CSimProfiler – Manual profiler. You explicitly call
Start()andEnd()to measure execution duration.
CSimScopeProfiler
The scoped profiler is ideal for short-lived blocks of code. Its constructor records the start time, and its destructor calculates the elapsed time and optionally updates a running average.
{
CSimScopeProfiler simScopeProfiler("ItemName", &runningAverage);
// Do work...
// When simScopeProfiler goes out of scope, elapsed time is automatically measured and reported.
}
Members:
| Member | Description |
|---|---|
| simulationNANOSec | Timestamp when the profiler starts (using ClockT). |
| text | Name of the profiled code section. |
| runningAverage | Pointer to a CRunningAverage object to accumulate measurements. |
CSimProfiler
This profiler is used when you need explicit control over start and end points. You call Start() at the beginning and End() at the end. You can also append measurements to a running average at any time.
CSimProfiler profiler;
profiler.Start();
// Do some work...
profiler.End("ItemName"); // Reports elapsed time
profiler.Append("ItemName", runningAverage); // Updates running average manually