diff --git a/.gitignore b/.gitignore index caa527540..1bffb9842 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ /target /tracker.* /tracker.toml -callgrind.out \ No newline at end of file +callgrind.out +flamegraph.svg +perf.data* \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 24bf78b6e..e6f196583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] \ No newline at end of file diff --git a/cSpell.json b/cSpell.json index d15355d56..16dff714e 100644 --- a/cSpell.json +++ b/cSpell.json @@ -18,6 +18,7 @@ "binstall", "Bitflu", "bools", + "Bragilevsky", "bufs", "Buildx", "byteorder", @@ -45,10 +46,12 @@ "dtolnay", "elif", "filesd", + "flamegraph", "Freebox", "gecos", "Grcov", "hasher", + "heaptrack", "hexlify", "hlocalhost", "Hydranode", @@ -105,6 +108,7 @@ "rerequests", "ringbuf", "rngs", + "rosegment", "routable", "rusqlite", "RUSTDOCFLAGS", @@ -138,11 +142,13 @@ "uroot", "Vagaa", "valgrind", + "Vitaly", "Vuze", "Weidendorfer", "Werror", "whitespaces", "XBTT", + "Xdebug", "Xeon", "Xtorrent", "Xunlei", diff --git a/docs/media/kcachegrind-screenshot.png b/docs/media/kcachegrind-screenshot.png new file mode 100644 index 000000000..a10eb5ad6 Binary files /dev/null and b/docs/media/kcachegrind-screenshot.png differ diff --git a/docs/profiling.md b/docs/profiling.md new file mode 100644 index 000000000..7c28367ce --- /dev/null +++ b/docs/profiling.md @@ -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 `