Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for cargo flamegprah and docs for profiling #749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
/target
/tracker.*
/tracker.toml
callgrind.out
callgrind.out
flamegraph.svg
perf.data*
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ opt-level = 1
debug = 1
lto = "fat"
opt-level = 3

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"]
6 changes: 6 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 @@ -105,6 +108,7 @@
"rerequests",
"ringbuf",
"rngs",
"rosegment",
"routable",
"rusqlite",
"RUSTDOCFLAGS",
Expand Down Expand Up @@ -138,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.
Loading