Skip to content

Commit b400b83

Browse files
authored
Profiling with perf (HULKs#1928)
* Write documentation on how to use perf with hotspot on the Nao * rename hulk binary * Always use sysroot flag when launching hotspot
1 parent 2fd1ec6 commit b400b83

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

crates/hulk_nao/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ edition.workspace = true
55
license.workspace = true
66
homepage.workspace = true
77

8+
[[bin]]
9+
name = "hulk"
10+
path = "src/main.rs"
11+
812
[package.metadata.pepsi]
913
cross-compile = true
1014

crates/repository/src/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ pub fn get_hulk_binary(profile: &str) -> String {
4646
other => other,
4747
};
4848

49-
format!("target/x86_64-aldebaran-linux-gnu/{profile_directory}/hulk_nao")
49+
format!("target/x86_64-aldebaran-linux-gnu/{profile_directory}/hulk")
5050
}

docs/tooling/overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Apart from the NAO code our repository contains several tools to aid in the deve
99
- [Recording & Replay](./recording_and_replay.md): Post-mortem analysis of game data
1010
- [Machine Learning](./machine-learning.md): Our tooling to create datasets and neural networks
1111
- [Behavior Simulator](./behavior_simulator.md): The simulator and viewer to debug and automatically test behavior
12-
- [Debugging with GDB/LLDB](./debugging.md): How to use a debugger with our software
1312
- [Parameter Tester](./parameter_tester.md): A tool to test if the parameters can be correctly parsed
13+
- [Debugging with GDB/LLDB](./debugging.md): How to use a debugger with our software
14+
- [Profiling with `perf`](./profiling.md): How to profile our software with `perf`

docs/tooling/profiling.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Profiling on the Nao Robot
2+
3+
We use the perf command to profile applications running on the Nao robot. It comes preinstalled in our robot image.
4+
5+
!!!warning
6+
Important: Ensure that your hulk binary includes debug symbols; without them, the profile will be unusable.
7+
Enable debug symbols by adding the --profile with-debug option to either the pepsi upload or pepsi build command. This preserves compiler optimizations while retaining symbol information for profiling.
8+
9+
### Step 1: SSH into the Robot
10+
11+
To profile an application running on the Nao, you must SSH into the robot first:
12+
13+
```bash
14+
pepsi shell <nao-number>
15+
```
16+
17+
### Step 2: Record a Profile with perf
18+
19+
To profile a running application (e.g., hulk), use:
20+
21+
```bash
22+
perf record --call-graph dwarf,8192 --aio -z --sample-cpu --mmap-pages 16M --pid $(pidof hulk) sleep 30
23+
```
24+
25+
This samples the stack traces of the hulk process for 30 seconds.
26+
27+
!!!info
28+
It's generally easiest to run perf as root, as otherwise various permissions and kernel knobs must be adjusted.
29+
30+
This command will generate a `perf.data` file containing the recorded samples.
31+
32+
### Step 3: Analyze the Profile with hotspot
33+
34+
We use Hotspot to inspect the `perf.data` file.
35+
With the binary and `perf.data` in place, launch Hotspot:
36+
37+
```bash
38+
hotspot \
39+
--sysroot ~/.local/share/hulk/sdk/9.0.2/sysroots/corei7-64-aldebaran-linux/ \
40+
--appPath ./target/x86_64-aldebaran-linux-gnu/with-debug/ \
41+
--kallsyms ./kallsyms
42+
```
43+
44+
Setting the `sysroot` is not requires when you profile a binary on your system, for example a behavior test case.
45+
Use the Flame Graph, Top Down, or Bottom Up views to investigate time spent in functions.
46+
47+
### Enable Debug Symbols in the SDK
48+
49+
By default, debug symbols are not enabled in our SDK.
50+
If you want to profile library code, consider enabling debug symbols in the Yocto distribution config:
51+
52+
```
53+
diff --git a/meta-hulks/conf/distro/HULKs-OS.conf b/meta-hulks/conf/distro/HULKs-OS.conf
54+
index 3e23671..982a187 100644
55+
--- a/meta-hulks/conf/distro/HULKs-OS.conf
56+
+++ b/meta-hulks/conf/distro/HULKs-OS.conf
57+
@@ -5,4 +5,3 @@ SUMMARY = "HULKs flavoured Nao"
58+
DISTRO = "HULKs-OS"
59+
DISTRO_NAME = "HULKs-OS"
60+
DISTRO_VERSION = "9.0.1"
61+
-SDKIMAGE_FEATURES:remove = "dbg-pkgs src-pkgs"
62+
```
63+
Rebuild the SDK afterward and use in it to build the code and as the `sysroot` argument when launching Hotspot.

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ nav:
6161
- Recording & Replay: tooling/recording_and_replay.md
6262
- Machine Learning: tooling/machine-learning.md
6363
- Behavior Simulator: tooling/behavior_simulator.md
64-
- Debugging with GDB/LLDB: tooling/debugging.md
6564
- Parameter Tester: tooling/parameter_tester.md
65+
- Debugging with GDB/LLDB: tooling/debugging.md
66+
- Profiling with perf: tooling/profiling.md
6667
- Operating System:
6768
- Overview: operating_system/overview.md
6869
- Partitioning: operating_system/partitioning.md

0 commit comments

Comments
 (0)