2021-08-19 12:59:05 +00:00
|
|
|
# Valgrind
|
|
|
|
This document explains how to use [Valgrind] to perform certain debug tasks.
|
|
|
|
|
2021-09-02 13:58:25 +00:00
|
|
|
**Be aware that [Valgrind] has certain limitations, e.g. that its virtual machine online runs on a single core and that
|
|
|
|
it only works well under Linux!**
|
|
|
|
|
2021-08-19 12:59:05 +00:00
|
|
|
## Build
|
|
|
|
Create a debug build that uses the system memory allocator (i.e. neither [heappy] nor [jemalloc]):
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ cargo build --no-default-features
|
|
|
|
```
|
|
|
|
|
2021-09-02 13:58:25 +00:00
|
|
|
For longer runs you may wanna use a release build. Just note that some traces are less precise when working with them:
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ cargo build --no-default-features --release
|
|
|
|
```
|
|
|
|
|
2021-08-19 12:59:05 +00:00
|
|
|
## Memory Leaks
|
|
|
|
There is a script that does most of the config setting. Just start the server with:
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ ./scripts/valgrind_leak ./target/debug/influxdb_iox run ...
|
|
|
|
```
|
|
|
|
|
|
|
|
You can kill the server w/ `CTRL-C` when you're ready. The [Valgrind] output will be written to `valgrind-out.txt`.
|
|
|
|
|
|
|
|
## Suppression Rules
|
|
|
|
[Valgrind] allows you to suppress certain outputs. This can be used to ignore known "issues" like that [lazycell] leaks.
|
|
|
|
For IOx we provide a file that is used by the scripts (under `scripts/valgrind.supp`). If you plan to write your own
|
|
|
|
rules, here are some useful links:
|
|
|
|
|
|
|
|
- <https://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles>
|
|
|
|
- <https://www.valgrind.org/docs/manual/manual-core.html#manual-core.suppress>
|
|
|
|
- <https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto>
|
|
|
|
|
|
|
|
You may also use the `--gen-suppressions=all` to auto-generate supppression rules:
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ ./scripts/valgrind_leak --gen-suppressions=all ./target/debug/influxdb_iox run ...
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that Rust symbols like `influxdb_iox::main` are mangled in a way that [Valgrind] cannot parse them (e.g. to
|
|
|
|
`_ZN12influxdb_iox4main17h940b8bf02831a9d8E`). The easiest way is to replace `::` w/ `*` and prepand and append an
|
|
|
|
additional wildcard `*`, so `influxdb_iox::main` gets `*influxdb_iox*main*`.
|
|
|
|
|
2021-09-02 13:58:25 +00:00
|
|
|
## Massif
|
|
|
|
[Massif] allows you to track memory usage over time. This is helpful when memory is not really leaked in a traditional
|
|
|
|
sense (aka that allocated memory is not freed when the program exists) but when memory is accumulated in some data
|
|
|
|
structures. Run [Massif] via (assuming you have a release build):
|
|
|
|
|
|
|
|
```console
|
|
|
|
valgrind \
|
|
|
|
--tool=massif \
|
|
|
|
--detailed-freq=1 \
|
|
|
|
--max-snapshots=100 \
|
|
|
|
--threshold=0.1 \
|
|
|
|
--time-unit=ms \
|
|
|
|
./target/release/influxdb_iox \
|
|
|
|
run ...
|
|
|
|
```
|
|
|
|
|
|
|
|
You might wanna play around with the options a bit.
|
|
|
|
|
|
|
|
The simplest way to use the massif output is to use [massif-visualizer]:
|
|
|
|
|
|
|
|
![massif-visualizer screenshot](./images/screenshot_massif_visualizer.jpeg)
|
|
|
|
|
2021-08-19 12:59:05 +00:00
|
|
|
[heappy]: https://github.com/mkmik/heappy
|
|
|
|
[jemalloc]: ttps://github.com/jemalloc/jemalloc
|
|
|
|
[lazycell]: https://crates.io/crates/lazycell
|
2021-09-02 13:58:25 +00:00
|
|
|
[Massif]: https://valgrind.org/docs/manual/ms-manual.html
|
|
|
|
[massif-visualizer]: https://github.com/KDE/massif-visualizer
|
2021-08-19 12:59:05 +00:00
|
|
|
[Valgrind]: https://valgrind.org/
|