title |
---|
Profiling with tracy |
Tracy is a realtime profiler which you can use to analyze performance bottleneck. It consists of two parts: client and profiler. The client integrated in BN sends profiling data to the profiler. As the client is opt-in, you need to build BN with tracy client in order to start profiling.
:::caution
Both the game and profiler have to be built with same version of tracy to work properly. Due to
numerous issues,
The windows version uses v0.10
wheras the
linux version uses
30f1b90
.
:::
$ git clone https://github.com/wolfpld/tracy
$ cd tracy
$ git checkout 30f1b901a9bab40a193c97c77ec82ac70805164d # the commit used by BN tracy client
# for ubuntu
$ sudo apt install cmake clang git libcapstone-dev xorg-dev dbus libgtk-3-dev
# for arch, copied from https://github.com/wolfpld/tracy/blob/master/.github/workflows/linux.yml#L16C12-L16C163
$ pacman -Syu --noconfirm && pacman -S --noconfirm --needed freetype2 tbb debuginfod wayland dbus libxkbcommon libglvnd meson cmake git wayland-protocols
- Install dependencies.
$ cmake -B profiler/build -S profiler # if you're using wayland
- Set up cmake. By default tracy uses wayland, if you want to use X11, you need to add
LEGACY=1
flag.
:::note{title="for X11"}
$ cmake -DLEGACY=ON -B profiler/build -S profiler # if you're using X11
tracy uses wayland by default, if you want to use X11, you need to add LEGACY=1
flag.
:::
:::note{title="fileselector fixes"}
$ cmake -DGTK_FILESELECTOR=ON -B profiler/build -S profiler
Due to issues with default fileselector (xdg-portal),
tracy may fail to open or save trace history. As an workaround, add GTK_FILESELECTOR=ON
in compile
flags to use gtk fileselector.
:::
$ cmake --build profiler/build --config Release --parallel $(nproc)
- Build the binary. It will be available on
./profiler/build/tracy-profiler
.
:::tip{title="Adding desktop entry"}
[Desktop Entry]
Version=1.0
Type=Application
Name=Tracy Profiler
GenericName=Code profiler
GenericName[pl]=Profiler kodu
GenericName[ko]=코드 프로파일러
Comment=Examine code to see where it is slow
Comment[pl]=Znajdowanie wolno wykonującego się kodu
Comment[ko]=코드 분석해서 느린 곳 찾기
Exec=<THE_PATH_WHERE_YOU_INSTALLED_TRACY>/profiler/build/tracy-profiler %f
Icon=<THE_PATH_WHERE_YOU_INSTALLED_TRACY>/icon/icon.ico
Terminal=false
Categories=Development;Profiling;
MimeType=application/tracy;
X-Desktop-File-Install-Version=0.26
To make the profiler available in app runner, create $HOME/.local/share/applications/tracy.desktop
file with the following content. Make sure to replace <THE_PATH_WHERE_YOU_INSTALLED_TRACY>
with
the path where you installed tracy!
:::
Download pre-compiled executable from https://github.com/wolfpld/tracy/releases.
Build on cmake with -D USE_TRACY=ON
flag. For example,
$ cmake -B build -DUSE_TRACY=ON ...other flags...
See CMake options for more information.
Mark ZoneScoped
in the function you'd like to profile. It will be displayed in the tracy GUI. For
example,
bool game::do_turn()
{
ZoneScoped;
/** Other code... */
}
There are also more complex profiling macros available. Check following links for more:
- https://github.com/wolfpld/tracy
- https://luxeengine.com/integrating-tracy-profiler-in-cpp/
- An Introduction to Tracy Profiler in C++ - Marcos Slomp - CppCon 2023
- Start BN (built with
USE_TRACY=ON
), and run the tracy profiler.
- Click
connect
button to connect to the game.
- Profiling data will be displayed in the GUI.