mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
tests: add utility to easily profile node performance with perf
Introduces `TestNode.profile_with_perf()` context manager which samples node execution to produce profiling data. Also introduces a test framework flag, `--perf`, which will run perf on all nodes for the duration of a given test.
This commit is contained in:
@@ -118,3 +118,36 @@ Helpers for script.py
|
||||
|
||||
#### [test_framework/blocktools.py](test_framework/blocktools.py)
|
||||
Helper functions for creating blocks and transactions.
|
||||
|
||||
### Benchmarking with perf
|
||||
|
||||
An easy way to profile node performance during functional tests is provided
|
||||
for Linux platforms using `perf`.
|
||||
|
||||
Perf will sample the running node and will generate profile data in the node's
|
||||
datadir. The profile data can then be presented using `perf report` or a graphical
|
||||
tool like [hotspot](https://github.com/KDAB/hotspot).
|
||||
|
||||
There are two ways of invoking perf: one is to use the `--perf` flag when
|
||||
running tests, which will profile each node during the entire test run: perf
|
||||
begins to profile when the node starts and ends when it shuts down. The other
|
||||
way is the use the `profile_with_perf` context manager, e.g.
|
||||
|
||||
```python
|
||||
with node.profile_with_perf("send-big-msgs"):
|
||||
# Perform activity on the node you're interested in profiling, e.g.:
|
||||
for _ in range(10000):
|
||||
node.p2p.send_message(some_large_message)
|
||||
```
|
||||
|
||||
To see useful textual output, run
|
||||
|
||||
```sh
|
||||
perf report -i /path/to/datadir/send-big-msgs.perf.data.xxxx --stdio | c++filt | less
|
||||
```
|
||||
|
||||
#### See also:
|
||||
|
||||
- [Installing perf](https://askubuntu.com/q/50145)
|
||||
- [Perf examples](http://www.brendangregg.com/perf.html)
|
||||
- [Hotspot](https://github.com/KDAB/hotspot): a GUI for perf output analysis
|
||||
|
||||
Reference in New Issue
Block a user