diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml new file mode 100644 index 000000000..c6e0da270 --- /dev/null +++ b/rust/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.x86_64-unknown-linux-musl] +rustflags="-C force-frame-pointers=yes" + +[target.x86_64-unknown-linux-gnu] +rustflags="-C force-frame-pointers=yes" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7e0ae2a09..102deeedc 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -92,6 +92,9 @@ lto = "fat" # at the expense of compilation time codegen-units = 1 +[profile.bench] +strip = false # Frame pointers are necessary for profiling; `strip=true` appears to remove them. + # Override build settings just for the GUI client, so we get a pdb/dwp # Cargo ignores profile settings if they're not in the workspace's Cargo.toml [profile.dev.package.firezone-gui-client] @@ -103,7 +106,3 @@ strip = "none" debug = "full" split-debuginfo = "packed" strip = "none" - -# Override build settings for the relay, so we can capture flamegraphs -[profile.release.package.firezone-relay] -debug = "full" diff --git a/rust/README.md b/rust/README.md index 44f1f038e..e82814fc6 100644 --- a/rust/README.md +++ b/rust/README.md @@ -27,3 +27,17 @@ Resulting in, e.g. 2024-04-01T18:25:48.295243016Z INFO No token / actor_name on disk, starting in signed-out state 2024-04-01T18:25:48.295360641Z INFO null ``` + +## Benchmarking on Linux + +The recommended way for benchmarking any of the Rust components is Linux' `perf` utility. +For example, to attach to a running application, do: + +1. Ensure the binary you are profiling is compiled with the `bench` profile. +1. `sudo perf perf record -g --freq 10000 --pid $(pgrep )`. +1. Run the speed test or whatever load-inducing task you want to measure. +1. `sudo perf script > profile.perf` +1. Open [profiler.firefox.com](https://profiler.firefox.com) and load `profile.perf` + +Instead of attaching to a process with `--pid`, you can also specify the path to executable directly. +That is useful if you want to capture perf data for a test or a micro-benchmark.