Linux Tracing with Perfetto

1 minute read

Build perfetto

git clone https://github.com/google/perfetto -b v43.1
git clone https://android.googlesource.com/platform/external/perfetto/ && cd perfetto
git checkout v43.1

arm64

# tools/gn clean out/linux
tools/install-build-deps --linux-arm
tools/gn gen out/linux

printf '%s\n' > out/linux/args.gn \
    'is_debug=false' \
    'is_system_compiler=true' \
    'is_hermetic_clang=false' \
    'is_clang=false' \
    'target_cpu="arm64"' \
    'target_os="linux"' \
    'target_cc="aarch64-poky-linux-gcc"' \
    'target_ar="aarch64-poky-linux-ar"' \
    'target_cxx="aarch64-poky-linux-g++"' \
    'target_strip="aarch64-poky-linux-strip"' \
    'target_sysroot="/opt/poky/4.0.15/sysroots/cortexa53-crypto-poky-linux/"' \
    'extra_host_cflags="-Wno-error"'
tools/ninja -C out/linux tracebox traced traced_probes perfetto 

arm

tools/install-build-deps --linux-arm
tools/gn gen out/linux

printf '%s\n' > out/linux/args.gn \
    'is_debug=false' \
    'is_system_compiler=true' \
    'is_hermetic_clang=false' \
    'is_clang=false' \
    'target_cpu="arm"' \
    'target_os="linux"' \
    'target_cc="arm-poky-linux-gnueabi-gcc"' \
    'target_ar="arm-poky-linux-gnueabi-ar"' \
    'target_cxx="arm-poky-linux-gnueabi-g++"' \
    'target_strip="arm-poky-linux-gnueabi-strip"' \
    'target_sysroot="/opt/poky/4.0.15/sysroots/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi"' \
    'extra_target_cflags="-mfpu=neon-vfpv4 -mfloat-abi=hard"' \
    'extra_target_ldflags="-Wl,-dynamic-linker,/lib/ld-linux-armhf.so.3"' \
    'extra_host_cflags="-Wno-error"'
tools/ninja -C out/linux tracebox traced traced_probes perfetto
file out/linux/traced
out/linux/traced: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=7e0f496cbc9bb1adcac819b94469c13d00b56a9d, with debug_info, not stripped
scp out/linux/stripped/libperfetto.so root@192.168.1.80:/usr/lib/

Capture trace

scp out/linux/tracebox root@192.168.1.81:/tmp/
scp test/configs/scheduling.cfg root@192.168.1.81:/tmp/
tracebox -o trace_file.perfetto-trace --txt -c scheduling.cfg

Visualization

Head to https://ui.perfetto.dev, and open the trace file with it, or build local ui server:

ui/run-dev-server --out out/ui
[...]
First build completed!
Starting HTTP server on http://127.0.0.1:10000
[33.873] 68/68	makeManifest

convert

curl -L https://get.perfetto.dev/traceconv -o $HOME/.local/bin/traceconv
chmod +x $HOME/.local/bin/traceconv
traceconv [text|json|systrace|profile] [input proto file] [output file]

traceconv text /tmp/trace_file.perfetto-trace perfetto.txt