Tracy Profiler

A real time, nanosecond resolution, remote telemetry, hybrid frame and sampling profiler for games and other applications. - github

caption

Installation

On linux, need to build from source.

Notes: by default it compile for Wayland. Need X11 => need to enable LEGACY option in CMake build settings (-DLEGACY=ON) This will require glfw.

Otherwise it’s rather easy to build:

$ git clone --recursive https://github.com/wolfpld/tracy.git
$ cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release -DLEGACY=ON
$ cmake --build profiler/build --config Release --parallel

Tracing C++

Include in your code (look in example folder):

#include "Tracy.hpp"
#include "TracyC.h"

and compile with

$  g++ fibers.cpp ../public/TracyClient.cpp -I../public/tracy -DTRACY_ENABLE -lpthread -ldl

For short program Add -DTRACY_NO_EXIT

The part above is refered as client setup in the documentation.

Then
1- Start tracy-profiler - (the server) and click connect (start listening socket) 2- launch your executable - (the client)

If everything goes well this will give some data into the profiler.

Instrumentation

With the steps mentioned above, you will be able to connect to the profiled program, but there probably won’t be any data collection performed. Unless you’re able to perform automatic call stack sampling (see chapter 3.15.5), you will have to instrument the application manually.

Notes the API sometimes rely on unique ptr (unique adress) for string definition. Make sure to read the doc refering to that part, eg this is the case for FrameMarker:

Frame

To slice the program’s execution recording into frame-sized chunks.

// recommended approach to ensure unique addr for this API calls
const char * const sl_AudioProcessing = " Audio processing " ;

FrameMarkStart( sl_AudioProcessing ) ;
...
FrameMarkEnd( sl_AudioProcessing ) ;

Zone

To record a zone’s execution time add the ZoneScoped macro at the beginning of the scope you want to measure. This will automatically record function name, source file name and location. Optionally you may use the ZoneScopedC( 0xRRGGBB ) macro to set a custom color for the zone. Note that the color value will be constant in the recording.

Plotting Data

Tracy is able to capture and draw value changes over time.

Message Log

You can send messages (for example, your typical debug output) using the TracyMessage( text, size ) macro;

Memory Profiling

Callstack

The easiest way is to launch instrument code with high privilege => this will allows stack sampling and stack collection

You can force call stack capture in the non-S postfixed macros by adding the TRACY_CALLSTACK define, set to the desired call stack capture depth.

see also

Alternatives

  • VTune - intel proprietary tools
  • Optik (Brofiler) / HN - how to make it work on linux is unclear
  • KUtrace / HN - an extremely low-overhead Linux kernel tracing facility for observing all the execution time on all cores of a multi-core processor, nothing missing, while running completely unmodified user programs written in any computer language.
Written on October 5, 2024, Last update on October 9, 2024
benchmarking hardware profiler