To perform basic instrumentation in your game, follow these steps:
- Copy Source: Copy the
src folder from the Optick repository or latest release into your game project. - Include Header: Add
#include "optick.h" to your source files. - Frame Instrumentation: Add the
OPTICK_FRAME("Name"); macro inside your main loop to mark the start of a frame. - Function Instrumentation: Use the
OPTICK_EVENT(); macro inside functions you want to profile. - Thread Instrumentation: Use the
OPTICK_THREAD("Name"); macro at the beginning of new threads to declare them in Optick. - Configuration: Edit
optick.config.h to enable or disable specific features or to disable Optick entirely in final production builds.
Important for Dynamic Linking:
If your game uses dynamic linking and you intend to use Optick from multiple DLLs within the same executable, you must:
- Add Optick's code to a common Dynamic Library.
- Compile that library with the
OPTICK_EXPORT define.
Alternatively, you can use the precompiled OptickCore.dll provided in the release:
- Add the
include folder to your project's extra include directories. - Add
lib/x64/debug and lib/x64/release to your extra library directories. - Copy
OptickCore.dll from the respective folders to your project's debug/release output folders.
#include "optick.h"
// In your main loop
while( true )
{
OPTICK_FRAME("MainThread");
engine.Update();
}
// To instrument a function
void SlowFunction()
{
OPTICK_EVENT();
...
}
// To declare a new thread
void WorkerThread(...)
{
OPTICK_THREAD("Worker");
while (isRunning)
{
...
}
}