Skip to content

Commit a7845a9

Browse files
committedMar 21, 2024··
Merge #749: Add configuration for cargo flamegprah and docs for profiling
6a7275e docs: [#746] for profiling (Jose Celano) bfdeafc test: [#746] profiling: add configuration to generate flamegraphs (Jose Celano) Pull request description: Add configuration for `cargo flamegprah` and docs for profiling. ACKs for top commit: josecelano: ACK 6a7275e Tree-SHA512: 77cb464b21a5913609a433980b551de6bae6bcdee679a39748ee8733641b812bdeb36b02b8811f9cc8fdef1c39bc07dcc6011722697dc23e727082d653aab143
2 parents 47c2fe2 + 6a7275e commit a7845a9

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed
 

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
/target
1111
/tracker.*
1212
/tracker.toml
13-
callgrind.out
13+
callgrind.out
14+
flamegraph.svg
15+
perf.data*

‎Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ opt-level = 1
103103
debug = 1
104104
lto = "fat"
105105
opt-level = 3
106+
107+
[target.x86_64-unknown-linux-gnu]
108+
linker = "/usr/bin/clang"
109+
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"]

‎cSpell.json

+6
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",
@@ -105,6 +108,7 @@
105108
"rerequests",
106109
"ringbuf",
107110
"rngs",
111+
"rosegment",
108112
"routable",
109113
"rusqlite",
110114
"RUSTDOCFLAGS",
@@ -138,11 +142,13 @@
138142
"uroot",
139143
"Vagaa",
140144
"valgrind",
145+
"Vitaly",
141146
"Vuze",
142147
"Weidendorfer",
143148
"Werror",
144149
"whitespaces",
145150
"XBTT",
151+
"Xdebug",
146152
"Xeon",
147153
"Xtorrent",
148154
"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)
Please sign in to comment.