Page MenuHomePhabricator

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

Authored by majcosta on Wed, Jul 29, 17:17.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

majcosta created this revision.Wed, Jul 29, 17:17
Herald added a reviewer: Restricted Project. · View Herald TranscriptWed, Jul 29, 17:17
majcosta requested review of this revision.Wed, Jul 29, 17:17
majcosta edited the summary of this revision. (Show Details)Wed, Jul 29, 17:32
Fabien accepted this revision.Wed, Jul 29, 20:58
This revision is now accepted and ready to land.Wed, Jul 29, 20:58