Header only profiling library which generate a JSON file to use with Chrome://tracing
- Add header file to your project
- Instrument your code
- Define
USE_PROFILER
- Compile and run your program
- Load generated
profiler.json
with Chrome://tracing
Zones are defined using the following commands:
PZone("ZoneName")
or PZone("ZoneName", "ZoneCategory")
Zones are declared using RAII. Timing starts when a zone defintions is declared and ended when the corresponding scope ends.
void myFunction()
{
PZone("MyZone"); // Timing starts here
function1();
// Scope ends and timing ends as well
}
If multiple timing zones are desired inside one function these have to be separated by adding scopes around them.
void myAdvFunction()
{
PZone("MainZone");
{
PZone("SubZone1");
subfunction1();
}
{
PZone("SubZone2");
subfunction2();
}
}
Per logfile metadata can be added using: PMetadata("Title", "Value")
NOTE Add meta data once! Do not add metadata inside any loop!
Examples:
Add product name:
PMetadata("product_name", "MyExecutable");
Add compile date using built in compiler macro:
PMetadata("build_date", __DATE__);
Add compile time using built in compiler macro:
PMetadata("build_time", __TIME__);
The profiler will do timing with microsecond precision. Each log point is 128 bytes and stored in internal memory. The log is written to disk when the program exits. When USE_PROFILER
is undefined the zone definition macros will expand to nothing, thus having no effect on the compiled executable.