Skip to content

Commit b2ec789

Browse files
authored
Merge pull request #180 from divyaprakash-iitd/develop
[WIP] Added tracy integration instructions
2 parents 6cd4343 + 28f5410 commit b2ec789

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

_data/docs_v7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
- Advanced-AD-Techniques
5959
- Container-Development
6060
- Writing-Unit-Tests
61-
61+
- Tracy-Integration
6262
- title: FAQ
6363
docs_v7:
6464
- FAQ

_docs_v7/Tracy-Integration.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Integrating Tracy Profiler with SU2
3+
permalink: /docs_v7/Tracy-Integration/
4+
---
5+
6+
- [Introduction](#introduction)
7+
- [Compiling SU2 with Tracy](#compiling-su2-with-tracy)
8+
- [Instrumenting SU2 Code](#instrumenting-su2-code)
9+
- [Running the Profiler and Visualizing Data](#running-the-profiler-and-visualizing-data)
10+
- [Conclusion](#conclusion)
11+
12+
---
13+
14+
## Introduction
15+
16+
Tracy is a high-performance, real-time profiler designed for C++ applications, offering nanosecond-resolution timing with minimal overhead. It is an excellent tool for profiling computationally intensive software like SU2, where traditional profilers such as Valgrind may introduce significant slowdowns. This guide provides step-by-step instructions for integrating Tracy with SU2, enabling users to analyze and optimize the performance of their CFD simulations effectively.
17+
18+
## Compiling SU2 with Tracy
19+
20+
To compile SU2 with Tracy support, follow these steps:
21+
22+
- Configure the build with Tracy enabled using Meson:
23+
```bash
24+
./meson.py setup build -Dwith-mpi=disabled --buildtype=debugoptimized -Denable-tracy=true --prefix=<SU2_INSTALL_PATH>
25+
```
26+
- Build and install SU2:
27+
```bash
28+
./ninja -C build install
29+
```
30+
- Replace `<SU2_INSTALL_PATH>` with your desired installation directory.
31+
32+
This embeds the Tracy client into SU2 for profiling.
33+
34+
## Instrumenting SU2 Code
35+
36+
To profile a function in SU2, you must use the project's centralized wrapper macros. This approach ensures that profiling can be cleanly enabled or disabled at compile time without modifying the core logic.
37+
38+
1. **Include the SU2 Tracy Wrapper Header:**
39+
- Add an include directive for `tracy_structure.hpp` at the top of your C++ source file. The relative path will depend on the file's location. For example, for a file in `SU2_CFD/src/fluid/`:
40+
```cpp
41+
#include "../../../Common/include/tracy_structure.hpp"
42+
```
43+
- **Important:** Do not include `<tracy/Tracy.hpp>` directly. The wrapper header manages the actual Tracy library.
44+
45+
2. **Instrument the Function with SU2 Macros:**
46+
- Use `SU2_ZONE_SCOPED_N("MyLabel")` to mark a function or scope with a custom name. This is the recommended macro for clarity.
47+
```cpp
48+
void MyFunction() {
49+
SU2_ZONE_SCOPED_N("MyFunction");
50+
// Function implementation
51+
}
52+
```
53+
- The label you provide (e.g., `"MyFunction"`) is what will appear in the Tracy profiler's timeline.
54+
- Alternatively, for a quick annotation, you can use `SU2_ZONE_SCOPED;`. This macro automatically uses the compiler-provided function name for the label.
55+
```cpp
56+
void MyFunction() {
57+
SU2_ZONE_SCOPED;
58+
// Function implementation
59+
}
60+
```
61+
62+
## Running the Profiler and Visualizing Data
63+
64+
After compiling and instrumenting SU2, profile and visualize the data as follows:
65+
66+
1. **Build the Tracy Server:**
67+
68+
Install additional dependencies required for the Tracy server.
69+
```bash
70+
sudo apt install libfreetype6-dev libcapstone-dev libdbus-1-dev \
71+
libxkbcommon-dev libwayland-dev wayland-protocols \
72+
libegl1-mesa-dev libglvnd-dev libgtk-3-dev
73+
```
74+
- Navigate to the Tracy directory: `cd <SU2_SOURCE_DIR>/subprojects/tracy`.
75+
- Build the profiler using CMake:
76+
```bash
77+
cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release
78+
cmake --build profiler/build --config Release --parallel
79+
```
80+
81+
2. **Launch the Tracy Profiler:**
82+
- Run the profiler:
83+
```bash
84+
./profiler/build/tracy-profiler
85+
```
86+
- Click "Connect" in the GUI to wait for SU2.
87+
88+
3. **Run the SU2 Simulation:**
89+
- In a separate terminal, execute your simulation:
90+
```bash
91+
<SU2_INSTALL_PATH>/bin/SU2_CFD <your_config_file>.cfg
92+
```
93+
- Replace `<SU2_INSTALL_PATH>` and `<your_config_file>` with your installation path and configuration file.
94+
95+
The Tracy GUI will display real-time profiling data during the simulation.
96+
97+
## Conclusion
98+
99+
Integrating Tracy with SU2 equips users with a powerful, low-overhead tool for profiling and optimizing CFD simulations. Its real-time visualization and precise timing capabilities make it ideal for performance analysis. For advanced features, troubleshooting, or additional details, consult the [Tracy documentation](https://github.com/wolfpld/tracy/releases/latest/download/tracy.pdf).

0 commit comments

Comments
 (0)