Skip to content

Commit

Permalink
docs: [torrust#746] for profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Mar 21, 2024
1 parent bfdeafc commit 6a7275e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"binstall",
"Bitflu",
"bools",
"Bragilevsky",
"bufs",
"Buildx",
"byteorder",
Expand Down Expand Up @@ -45,10 +46,12 @@
"dtolnay",
"elif",
"filesd",
"flamegraph",
"Freebox",
"gecos",
"Grcov",
"hasher",
"heaptrack",
"hexlify",
"hlocalhost",
"Hydranode",
Expand Down Expand Up @@ -139,11 +142,13 @@
"uroot",
"Vagaa",
"valgrind",
"Vitaly",
"Vuze",
"Weidendorfer",
"Werror",
"whitespaces",
"XBTT",
"Xdebug",
"Xeon",
"Xtorrent",
"Xunlei",
Expand Down
Binary file added docs/media/kcachegrind-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions docs/profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Profiling

## Using flamegraph

```console
TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" cargo flamegraph --bin=profiling -- 60
```

![flamegraph](./media/flamegraph.svg)

## Using valgrind and kcachegrind

You need to:

1. Build an run the tracker for profiling.
2. Make requests to the tracker while it's running.

Build and the binary for profiling:

```console
RUSTFLAGS='-g' cargo build --release --bin profiling \
&& export TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" \
&& valgrind \
--tool=callgrind \
--callgrind-out-file=callgrind.out \
--collect-jumps=yes \
--simulate-cache=yes \
./target/release/profiling 60
```

> 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).
After running the tracker with `<valgrind` it generates a file `callgrind.out`
that you can open with `kcachegrind`.

```console
kcachegrind callgrind.out
```

![kcachegrind screenshot](./media/kcachegrind-screenshot.png)

## Links

Profiling tools:

- [valgrind](https://valgrind.org/).
- [kcachegrind](https://kcachegrind.github.io/).
- [flamegraph](https://github.com/flamegraph-rs/flamegraph).

Talks about profiling:

- [Profiling Rust Programs with valgrind, heaptrack, and hyperfine](https://www.youtube.com/watch?v=X6Xz4CRd6kw&t=191s).
- [RustConf 2023 - Profiling async applications in Rust by Vitaly Bragilevsky](https://www.youtube.com/watch?v=8FAdY_0DpkM).
- [Profiling Code in Rust - by Vitaly Bragilevsky - Rust Linz, December 2022](https://www.youtube.com/watch?v=JRMOIE_wAFk&t=8s).
- [Xdebug 3 Profiling: 2. KCachegrind tour](https://www.youtube.com/watch?v=h-0HpCblt3A).

## Acknowledgments

Many thanks to [Vitaly Bragilevsky](https://github.com/bravit) and others for sharing the talks about profiling.

0 comments on commit 6a7275e

Please sign in to comment.