@@ -17,6 +17,7 @@ Developer Notes
1717 - [ DEBUG_LOCKORDER] ( #debug_lockorder )
1818 - [ Valgrind suppressions file] ( #valgrind-suppressions-file )
1919 - [ Compiling for test coverage] ( #compiling-for-test-coverage )
20+ - [ Performance profiling with perf] ( #performance-profiling-with-perf )
2021 - [ Locking/mutex usage notes] ( #lockingmutex-usage-notes )
2122 - [ Threads] ( #threads )
2223 - [ Ignoring IDE/editor files] ( #ignoring-ideeditor-files )
@@ -257,6 +258,51 @@ make cov
257258# A coverage report will now be accessible at `./test_bitcoin.coverage/index.html`.
258259```
259260
261+ ### Performance profiling with perf
262+
263+ Profiling is a good way to get a precise idea of where time is being spent in
264+ code. One tool for doing profiling on Linux platforms is called
265+ [ ` perf ` ] ( http://www.brendangregg.com/perf.html ) , and has been integrated into
266+ the functional test framework. Perf can observe a running process and sample
267+ (at some frequency) where its execution is.
268+
269+ Perf installation is contingent on which kernel version you're running; see
270+ [ this StackExchange
271+ thread] ( https://askubuntu.com/questions/50145/how-to-install-perf-monitoring-tool )
272+ for specific instructions.
273+
274+ Certain kernel parameters may need to be set for perf to be able to inspect the
275+ running process' stack.
276+
277+ ``` sh
278+ $ sudo sysctl -w kernel.perf_event_paranoid=-1
279+ $ sudo sysctl -w kernel.kptr_restrict=0
280+ ```
281+
282+ Make sure you [ understand the security
283+ trade-offs] ( https://lwn.net/Articles/420403/ ) of setting these kernel
284+ parameters.
285+
286+ To profile a running bitcoind process for 60 seconds, you could use an
287+ invocation of ` perf record ` like this:
288+
289+ ``` sh
290+ $ perf record \
291+ -g --call-graph dwarf --per-thread -F 140 \
292+ -p ` pgrep bitcoind` -- sleep 60
293+ ```
294+
295+ You could then analyze the results by running
296+
297+ ``` sh
298+ perf report --stdio | c++filt | less
299+ ```
300+
301+ or using a graphical tool like [ Hotspot] ( https://github.com/KDAB/hotspot ) .
302+
303+ See the functional test documentation for how to invoke perf within tests.
304+
305+
260306** Sanitizers**
261307
262308Bitcoin Core can be compiled with various "sanitizers" enabled, which add
0 commit comments