A simple CPU block profiler. Inspired by j_blow streams.
Please check sandbox example here
{
ProfileBlock("Block_1");
std::this_thread::sleep_for(20ms);
{
ProfileBlock("Block_1.1");
std::this_thread::sleep_for(20ms);
std::this_thread::sleep_for(10ms);
{
ProfileBlock("Block_1.1.1");
std::this_thread::sleep_for(20ms);
std::this_thread::sleep_for(10ms);
}
}
{
ProfileBlock("Block_1.2");
std::this_thread::sleep_for(10ms);
}
std::this_thread::sleep_for(10ms);
}
{
ProfileBlock("Block_2");
std::this_thread::sleep_for(30ms);
}Output:
Block_1 155.548 ms
Block_1.1 93.1160 ms
Block_1.1.1 46.9826 ms
Block_1.2 15.3387 ms
Block_2 31.3534 ms
Don’t forget to call ClearProfiler(); at the end of the game loop cycle, or increase the PROFILER_MAX_ENTRIES value if needed. Otherwise, profiler log entries may overwrite each other.
Also, remember to define the PROFILER_ENABLED macro before including the profiler.hpp file.
