A Google Trace event Format Output Profiler
A simple to use instrumentation profiler to benchmark timings of chunks of your code base.
Macro definitions will not show their implementations for clarity
#define GTFO_PROFILE_SESSION_START(name, filePath)
#define GTFO_PROFILE_SESSION_END()Session macros are used to describe large/conceptual chunks of code that all profiling
data within the start and end macro calls will be assigned to.
#define GTFO_PROFILE_SCOPE(scopeName, scopeCategory)
#define GTFO_PROFILE_FUNCTION()Scope macros are used to describe small chunks of code such as function calls, class constructors/destructors, etc.
Scope macros will automatically stop timing when they are destroyed in their current scope. GTFO_PROFILE_FUNCTION() is syntactic
sugar and simply calls GTFO_PROFILE_SCOPE(...) with the expansion of the _FUNCTION_ variable and "function" as the category.
To disable profiling, simply define GTFO_PROFILER_OFF. You can do this using CMake (and other build systems too) by doing the following.
add_compile_definitions(yourTarget GTFO_PROFILER_OFF)or
target_compile_definitions(yourTarget PUBLIC GTFO_PROFILER_OFF)You can also just #define GTFO_PROFILER_OFF somewhere in your code base.
// app.cpp
#include "window.h"
#include "app.h"
//...
void App::init() {
GTFO_PROFILE_FUNCTION();
{
GTFO_PROFILE_SCOPE("Load Config", "init");
mConfig = loadConfig();
}
{
GTFO_PROFILE_SCOPE("Window Init", "init");
mWindow = new Window();
mWindow->setSize(1920, 1080);
mWindow->setBorderless(false);
mWindow->setVSync(true);
}
{
GTFO_PROFILE_SCOPE("Renderer Init", "init");
mRenderer = new Renderer();
mRenderer->startBackend();
mRenderer->giveWindowContext(mWindow);
}
};
//...
// main.cpp
#include "app.h"
#include "gtfo_profiler.h"
int main() {
GTFO_PROFILE_SESSION_START("App Init", "AppInitResults.json");
App *app = new App();
app->init();
GTFO_PROFILE_SESSION_END();
GTFO_PROFILE_SESSION_START("App Run", "AppRunResults.json");
app->run();
GTFO_PROFILE_SESSION_END();
GTFO_PROFILE_SESSION_START("App Shutdown", "AppShutdownResults.json");
delete app;
GTFO_PROFILE_SESSION_END();
}To integrate GTFOProfiler into you project simply add both the include and src directories
and then link it against your project using your build system (CMake, Premake, etc.)
As of v1.0.0, gtfo_profiler.h is hardcoded into using nlohmann/json.hpp by doing '#include "../include/nlohmann/json.hpp"'. If your project already contains nlohmann_json as a dependency, change this #include statement to point to your nlohmann/json.hpp