As a project sponsored by the OCaml software foundation, I’ve worked on demangling OCaml symbols in perf. Some screenshots are below. The work is currently being upstreamed. In the meantime, it can be used as follows:
git clone --depth=1 https://github.com/copy/linux.git
# or:
# wget https://github.com/copy/linux/archive/master.tar.gz && tar xfv master.tar.gz
cd linux/tools/perf
make
alias perf=$PWD/perf
# or copy perf to somewhere in your PATH
Your distribution’s version of perf will also work for the examples below, but will have less readable symbols
Short intruction to perf
Perf is a Linux-only sampling profiler (and more), which can be used to analyse the performance profile of OCaml and other executables. When compiling with ocamlopt, add -g
to include debug information in the executable. dune does this automatically, even in the release profile. To start a program and record its profile:
perf record --call-graph dwarf program.exe
Or record a running program:
perf record --call-graph dwarf -p `pidof program.exe`
Then, view a profile using:
perf report # top-down
perf report --no-children # bottom-up
Within the report view, the following keybindings are useful:
-
+
: open/close one callchain level -
e
: open/close entire callchain -
t
: Toggle beween current thread and all threads (e.g., onlydune
,ocamlopt
, etc.)
Or generate a flamegraph:
git clone https://github.com/brendangregg/FlameGraph
cd FlameGraph
perf script -i path/to/perf.data | ./stackcollapse-perf.pl | ./flamegraph.pl > perf-flamegraph.svg
You may need to run the following command to allow recording by non-root users (more infos):
echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid
Sources
Before:
After:
Bottom-up:
Flamegraph (cropped):