HomePhabricator

[backport#14519] tests: add utility to easily profile node performance with perf

Description

[backport#14519] tests: add utility to easily profile node performance with perf

Summary:
docs: add perf section to developer docs (James O'Beirne)
add utility to easily profile node performance with perf (James O'Beirne)

Pull request description:

Adds a context manager to easily (and selectively) profile node performance during functional test execution using `perf`.

While writing some tests, I encountered some odd bitcoind slowness. I wrote up a utility (`TestNode.profile_with_perf`) that generates performance diagnostics for a node by running `perf` during the execution of a particular region of test code.

`perf` usage is detailed in the excellent (and sadly unmerged) https://github.com/bitcoin/bitcoin/pull/12649; all due props to @eklitzke.

### Example

```python
with node.profile_with_perf("large-msgs"):
    for i in range(200):
        node.p2p.send_message(some_large_msg)
    node.p2p.sync_with_ping()
```

This generates a perf data file in the test node's datadir (`/tmp/testtxmpod0y/node0/node-0-TestName-large-msgs.perf.data`).

Running `perf report` generates nice output about where the node spent most of its time while running that part of the test:

```bash
$ perf report -i /tmp/testtxmpod0y/node0/node-0-TestName-large-msgs.perf.data --stdio \
  | c++filt \
  | less

https://github.com/bitcoin/bitcoin/pull/14519/files


Backport of Core PR14519

Test Plan:

ninja
cd test
../../test/functional/abc-cmdline.py --perf --config=config.ini

run command to see test report in the output log

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D7080

Details

Provenance
MarcoFalke <falke.marco@gmail.com>Authored on Feb 5 2019, 22:40
majcostaCommitted on Jul 30 2020, 00:25
majcostaPushed on Jul 30 2020, 00:25
Reviewer
Restricted Project
Differential Revision
D7080: [backport#14519] tests: add utility to easily profile node performance with perf
Parents
rABC0d733b66aa9c: [backport#14465] tests: Stop node before removing the notification file
Branches
Unknown
Tags
Unknown