|
| 1 | +# Profiling |
| 2 | + |
| 3 | +## Using flamegraph |
| 4 | + |
| 5 | +```console |
| 6 | +TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" cargo flamegraph --bin=profiling -- 60 |
| 7 | +``` |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Using valgrind and kcachegrind |
| 12 | + |
| 13 | +You need to: |
| 14 | + |
| 15 | +1. Build an run the tracker for profiling. |
| 16 | +2. Make requests to the tracker while it's running. |
| 17 | + |
| 18 | +Build and the binary for profiling: |
| 19 | + |
| 20 | +```console |
| 21 | +RUSTFLAGS='-g' cargo build --release --bin profiling \ |
| 22 | + && export TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" \ |
| 23 | + && valgrind \ |
| 24 | + --tool=callgrind \ |
| 25 | + --callgrind-out-file=callgrind.out \ |
| 26 | + --collect-jumps=yes \ |
| 27 | + --simulate-cache=yes \ |
| 28 | + ./target/release/profiling 60 |
| 29 | +``` |
| 30 | + |
| 31 | +> NOTICE: You should make requests to the services you want to profile. For example, using the [UDP load test](./benchmarking.md#run-udp-load-test). |
| 32 | +
|
| 33 | +After running the tracker with `<valgrind` it generates a file `callgrind.out` |
| 34 | +that you can open with `kcachegrind`. |
| 35 | + |
| 36 | +```console |
| 37 | +kcachegrind callgrind.out |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +## Links |
| 43 | + |
| 44 | +Profiling tools: |
| 45 | + |
| 46 | +- [valgrind](https://valgrind.org/). |
| 47 | +- [kcachegrind](https://kcachegrind.github.io/). |
| 48 | +- [flamegraph](https://github.com/flamegraph-rs/flamegraph). |
| 49 | + |
| 50 | +Talks about profiling: |
| 51 | + |
| 52 | +- [Profiling Rust Programs with valgrind, heaptrack, and hyperfine](https://www.youtube.com/watch?v=X6Xz4CRd6kw&t=191s). |
| 53 | +- [RustConf 2023 - Profiling async applications in Rust by Vitaly Bragilevsky](https://www.youtube.com/watch?v=8FAdY_0DpkM). |
| 54 | +- [Profiling Code in Rust - by Vitaly Bragilevsky - Rust Linz, December 2022](https://www.youtube.com/watch?v=JRMOIE_wAFk&t=8s). |
| 55 | +- [Xdebug 3 Profiling: 2. KCachegrind tour](https://www.youtube.com/watch?v=h-0HpCblt3A). |
| 56 | + |
| 57 | +## Acknowledgments |
| 58 | + |
| 59 | +Many thanks to [Vitaly Bragilevsky](https://github.com/bravit) and others for sharing the talks about profiling. |
0 commit comments