Skip to content

Commit 6a7275e

Browse files
committed
docs: [#746] for profiling
1 parent bfdeafc commit 6a7275e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

cSpell.json

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"binstall",
1919
"Bitflu",
2020
"bools",
21+
"Bragilevsky",
2122
"bufs",
2223
"Buildx",
2324
"byteorder",
@@ -45,10 +46,12 @@
4546
"dtolnay",
4647
"elif",
4748
"filesd",
49+
"flamegraph",
4850
"Freebox",
4951
"gecos",
5052
"Grcov",
5153
"hasher",
54+
"heaptrack",
5255
"hexlify",
5356
"hlocalhost",
5457
"Hydranode",
@@ -139,11 +142,13 @@
139142
"uroot",
140143
"Vagaa",
141144
"valgrind",
145+
"Vitaly",
142146
"Vuze",
143147
"Weidendorfer",
144148
"Werror",
145149
"whitespaces",
146150
"XBTT",
151+
"Xdebug",
147152
"Xeon",
148153
"Xtorrent",
149154
"Xunlei",

docs/media/kcachegrind-screenshot.png

583 KB
Loading

docs/profiling.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
![flamegraph](./media/flamegraph.svg)
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+
![kcachegrind screenshot](./media/kcachegrind-screenshot.png)
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

Comments
 (0)