Skip to content

Commit 4ceae1a

Browse files
committed
tracing: add initial support for perfetto/tracy
1 parent 76713ee commit 4ceae1a

14 files changed

Lines changed: 876 additions & 81 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ experiment/
1010
**/_pychache__
1111
.artifacts/
1212
.vscode/*
13-
.claude/*
13+
.claude/*
14+
build-*

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ project(dsr
55
LANGUAGES CXX)
66

77
include(GNUInstallDirs)
8+
include(FetchContent)
9+
find_package(Threads REQUIRED)
810

911
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1012

@@ -21,6 +23,8 @@ if (TSAN)
2123
add_link_options(-fsanitize=thread)
2224
endif()
2325

26+
include(cmake/profiling.cmake)
27+
2428
add_definitions(-I/usr/include/x86_64-linux-gnu/qt6/QtOpenGLWidgets/)
2529

2630
include_directories(/home/robocomp/robocomp/classes)

PROFILING.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Profiling Backends
2+
3+
The repository supports multiple profiling backends through CMake.
4+
5+
## Backend Selection
6+
7+
Use:
8+
9+
```bash
10+
-DCORTEX_PROFILING_BACKEND=NONE
11+
-DCORTEX_PROFILING_BACKEND=TRACY
12+
-DCORTEX_PROFILING_BACKEND=PERFETTO
13+
```
14+
15+
### `NONE`
16+
17+
No profiling backend is enabled.
18+
19+
### `TRACY`
20+
21+
Uses the interactive Tracy client/profiler flow.
22+
23+
If `CORTEX_ENABLE_TRACY` is not explicitly configured, the build falls back to the `DEFAULT` Tracy preset.
24+
25+
What you need:
26+
27+
- an instrumented build with `-DCORTEX_PROFILING_BACKEND=TRACY`
28+
- the Tracy Profiler GUI
29+
- a live connection between the running process and the profiler
30+
31+
Important:
32+
33+
- Tracy is mainly an interactive workflow
34+
- traces are not written automatically to disk by the client
35+
- if you want a saved trace, connect with the profiler and save the session from the UI
36+
37+
Typical usage:
38+
39+
```bash
40+
cmake -S . -B build \
41+
-DWITH_TESTS=ON \
42+
-DCORTEX_PROFILING_BACKEND=TRACY \
43+
-DCORTEX_ENABLE_TRACY=DEFAULT
44+
cmake --build build --target tests
45+
./build/tests/tests "[SYNCHRONIZATION][GRAPH]"
46+
```
47+
48+
Tracy options are OFF, ON, DEFAULT, MEDIUM, EXTRA, WSL, WSL_EXTRA
49+
50+
### `PERFETTO`
51+
52+
Uses Perfetto's in-process backend and writes an offline trace file automatically at process exit.
53+
54+
What you need:
55+
56+
- an instrumented build with `-DCORTEX_PROFILING_BACKEND=PERFETTO`
57+
- a generated `.pftrace` file
58+
- either the web UI at `https://ui.perfetto.dev/` or another Perfetto-compatible viewer
59+
60+
Typical usage:
61+
62+
```bash
63+
cmake -S . -B build-perfetto \
64+
-DWITH_TESTS=ON \
65+
-DCORTEX_PROFILING_BACKEND=PERFETTO
66+
cmake --build build-perfetto --target tests
67+
export CORTEX_PERFETTO_TRACE_FILE=.artifacts/output.pftrace
68+
./build-perfetto/tests/tests "[SYNCHRONIZATION][GRAPH]"
69+
```
70+
71+
The trace file path can be overridden with:
72+
73+
```bash
74+
export CORTEX_PERFETTO_TRACE_FILE=/path/to/output.pftrace
75+
```
76+
77+
If not set, the default output path is:
78+
79+
```text
80+
.artifacts/perfetto/<executable>-<pid>-<timestamp>.pftrace
81+
```
82+
83+
relative to the process working directory.
84+
85+
The generated trace file can be opened with:
86+
87+
- https://ui.perfetto.dev/
88+
- the standalone Perfetto UI / trace processor tools
89+
90+
Recommended flow on this repository:
91+
92+
1. Run the instrumented binary or test.
93+
2. Wait for the process to exit cleanly.
94+
3. Open `https://ui.perfetto.dev/`.
95+
4. Use `Open trace file` and load the `.pftrace`.
96+
97+
Notes:
98+
99+
- Perfetto is the better fit for offline captures that you want to inspect later.
100+
- The trace is flushed on shutdown, so if the process is killed hard you may lose the file.
101+
- The current instrumentation covers graph, RT, CRDT, bootstrap, and synchronization paths.

api/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ target_link_libraries(dsr_api
7272
${QT_GEOM}
7373
)
7474

75+
target_link_libraries(dsr_api PRIVATE cortex_profiling)
76+
7577
target_include_directories(dsr_api
7678
PUBLIC
7779
# Headers of DSR Core

0 commit comments

Comments
 (0)