|
| 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. |
0 commit comments