-
Notifications
You must be signed in to change notification settings - Fork 233
Profiling
Ștefan Talpalaru edited this page Sep 23, 2020
·
7 revisions
This profiler is a wrapper around GDB that samples the main thread by getting backtraces and presents its statistics based on the wall clock - thus including the time spent waiting for I/O.
Keep in mind that the profiled program is paused while GDB gets a backtrace, so don't use very high sampling rates. Also keep an eye on GDB's CPU usage.
In the same parent directory as nim-beacon-chain:
$ ls
nim-beacon-chain
$ git clone https://github.com/jasonrohrer/wallClockProfiler.git
$ cd wallClockProfiler
$ g++ $CXXFLAGS -o wallClockProfiler wallClockProfiler.cpp
$ cd ..
Flame graph support is in a PR that's not expected to be merged any time soon by upstream:
$ git clone https://github.com/stefantalpalaru/FlameGraph.git
$ cd FlameGraph
$ git checkout wallClockProfiler
$ cd ..
Start a Medalla node and get the beacon_node PID:
$ cd nim-beacon-chain
$ make medalla
# wait until beacon_node starts running, then run from another terminal tab:
$ ps -e -o pid,command | grep beacon_node
Assuming the PID you got is 1234, run the profiler for 5 minutes, at 19 samples per second:
$ ../wallClockProfiler/wallClockProfiler 19 build/beacon_node 1234 300 > profile_19_300.txt
# make the flame graph
$ ../FlameGraph/stackcollapse-wcp.pl profile_19_300.txt > profile_19_300_collapsed.txt
$ ../FlameGraph/flamegraph.pl profile_19_300_collapsed.txt > profile_19_300.svg
Now you can open "profile_19_300.svg" in a browser and click on individual functions to zoom in.
perf record --call-graph dwarf,16000 -e task-clock -p $(pidof beacon_node)
perf script > out.perf
../FlameGraph/stackcollapse-perf.pl out.perf > perf_collapsed.txt
../FlameGraph/flamegraph.pl perf_collapsed.txt > perf.svg