Changeset View
Changeset View
Standalone View
Standalone View
doc/developer-notes.md
Show All 11 Lines | - [Development tips and tricks](#development-tips-and-tricks) | ||||
- [Compiling for gprof profiling](#compiling-for-gprof-profiling) | - [Compiling for gprof profiling](#compiling-for-gprof-profiling) | ||||
- [debug.log](#debuglog) | - [debug.log](#debuglog) | ||||
- [Writing tests](#writing-tests) | - [Writing tests](#writing-tests) | ||||
- [Writing script integration tests](#writing-script-integration-tests) | - [Writing script integration tests](#writing-script-integration-tests) | ||||
- [Testnet and Regtest modes](#testnet-and-regtest-modes) | - [Testnet and Regtest modes](#testnet-and-regtest-modes) | ||||
- [DEBUG_LOCKORDER](#debug_lockorder) | - [DEBUG_LOCKORDER](#debug_lockorder) | ||||
- [Valgrind suppressions file](#valgrind-suppressions-file) | - [Valgrind suppressions file](#valgrind-suppressions-file) | ||||
- [Compiling for test coverage](#compiling-for-test-coverage) | - [Compiling for test coverage](#compiling-for-test-coverage) | ||||
- [Performance profiling with perf](#performance-profiling-with-perf) | |||||
- [Sanitizers](#sanitizers) | - [Sanitizers](#sanitizers) | ||||
- [Locking/mutex usage notes](#lockingmutex-usage-notes) | - [Locking/mutex usage notes](#lockingmutex-usage-notes) | ||||
- [Threads](#threads) | - [Threads](#threads) | ||||
- [Ignoring IDE/editor files](#ignoring-ideeditor-files) | - [Ignoring IDE/editor files](#ignoring-ideeditor-files) | ||||
- [Development guidelines](#development-guidelines) | - [Development guidelines](#development-guidelines) | ||||
- [Wallet](#wallet) | - [Wallet](#wallet) | ||||
- [General C++](#general-c) | - [General C++](#general-c) | ||||
- [C++ data structures](#c-data-structures) | - [C++ data structures](#c-data-structures) | ||||
▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | |||||
ninja coverage-check-all | ninja coverage-check-all | ||||
``` | ``` | ||||
A coverage report will now be accessible at `./check-all.coverage/index.html`. | A coverage report will now be accessible at `./check-all.coverage/index.html`. | ||||
To include branch coverage, you can add the `-DENABLE_BRANCH_COVERAGE=ON` option | To include branch coverage, you can add the `-DENABLE_BRANCH_COVERAGE=ON` option | ||||
to the `cmake` command line. | to the `cmake` command line. | ||||
### Performance profiling with perf | |||||
Profiling is a good way to get a precise idea of where time is being spent in | |||||
code. One tool for doing profiling on Linux platforms is called | |||||
[`perf`](http://www.brendangregg.com/perf.html), and has been integrated into | |||||
the functional test framework. Perf can observe a running process and sample | |||||
(at some frequency) where its execution is. | |||||
Perf installation is contingent on which kernel version you're running; see | |||||
[this StackExchange | |||||
thread](https://askubuntu.com/questions/50145/how-to-install-perf-monitoring-tool) | |||||
for specific instructions. | |||||
Certain kernel parameters may need to be set for perf to be able to inspect the | |||||
running process' stack. | |||||
```sh | |||||
$ sudo sysctl -w kernel.perf_event_paranoid=-1 | |||||
$ sudo sysctl -w kernel.kptr_restrict=0 | |||||
``` | |||||
Make sure you [understand the security | |||||
trade-offs](https://lwn.net/Articles/420403/) of setting these kernel | |||||
parameters. | |||||
To profile a running bitcoind process for 60 seconds, you could use an | |||||
invocation of `perf record` like this: | |||||
```sh | |||||
$ perf record \ | |||||
-g --call-graph dwarf --per-thread -F 140 \ | |||||
-p `pgrep bitcoind` -- sleep 60 | |||||
``` | |||||
You could then analyze the results by running | |||||
```sh | |||||
perf report --stdio | c++filt | less | |||||
``` | |||||
or using a graphical tool like [Hotspot](https://github.com/KDAB/hotspot). | |||||
See the functional test documentation for how to invoke perf within tests. | |||||
### Sanitizers | ### Sanitizers | ||||
Bitcoin ABC can be compiled with various "sanitizers" enabled, which add | Bitcoin ABC can be compiled with various "sanitizers" enabled, which add | ||||
instrumentation for issues regarding things like memory safety, thread race | instrumentation for issues regarding things like memory safety, thread race | ||||
conditions, or undefined behavior. This is controlled with the | conditions, or undefined behavior. This is controlled with the | ||||
`-DENABLE_SANITIZERS` cmake flag, which should be a semicolon separated list of | `-DENABLE_SANITIZERS` cmake flag, which should be a semicolon separated list of | ||||
sanitizers to enable. The sanitizer list should correspond to supported | sanitizers to enable. The sanitizer list should correspond to supported | ||||
▲ Show 20 Lines • Show All 677 Lines • Show Last 20 Lines |