| Crates.io | cargo-samply |
| lib.rs | cargo-samply |
| version | 0.4.1 |
| created_at | 2023-12-09 13:08:15.003224+00 |
| updated_at | 2025-12-28 19:06:19.712804+00 |
| description | A cargo subcommand to automate the process of running samply for project binaries |
| homepage | https://github.com/PhilippPolterauer/cargo-samply.git |
| repository | https://github.com/PhilippPolterauer/cargo-samply.git |
| max_upload_size | |
| id | 1063679 |
| size | 229,751 |
Profile Rust code with samply, without remembering the build/run ceremony.
Important: This project is not affiliated with, endorsed by, or maintained by the official
samplyproject or its authors. It is an independent Cargo subcommand that integrates with thesamplyprofiler.
cargo samply automates the usual profiling workflow:
samply profiler[profile.samply] management for you, ensuring optimized code with debug symbols without manual Cargo.toml edits.target/release/examples/.... Just use --bin, --example, --bench, or --test.--bench) for Criterion-style benchmarks, which are often missed when profiling manually.samply installation before starting the build, so you find out immediately if something is missing.rustup)samply installed and available in your PATHcargo install cargo-samply
cargo install samply
cargo install --git https://github.com/PhilippPolterauer/cargo-samply.git
From any Rust project:
$ cargo samply
Once samply starts its local UI server, open the printed address (typically 127.0.0.1:3001).

$ cargo samply --help
The samply subcommand
Usage: cargo samply [OPTIONS] [TRAILING_ARGUMENTS]...
Arguments:
[TRAILING_ARGUMENTS]... Trailing arguments passed to the binary being profiled
Options:
--profile <PROFILE> Build with the specified profile [default: samply]
-p, --package <PACKAGE> Package to profile (in a workspace)
-b, --bin <BIN> Binary to run
-e, --example <EXAMPLE> Example to run
--bench <BENCH> Benchmark target to run (e.g. `cargo samply --bench throughput`)
--test <TEST> Test target to run (e.g. `cargo samply --test integration_test`)
--bench-flag <BENCH_FLAG> The flag to use when running the benchmark target [default: --bench]
--samply-args <SAMPLY_ARGS> Arguments to pass to samply (e.g. `--samply-args "--rate 2000"`)
-f, --features <FEATURES> Build features to enable
--no-default-features Disable default features
-v, --verbose Print extra output to help debug problems
-q, --quiet Suppress all output except errors
-n, --no-samply Disable the automatic samply start
--dry-run Print the build and run commands without executing them
--no-profile-inject Do not modify Cargo.toml to add the samply profile
--list-targets List all available targets in the workspace and exit
-h, --help Print help
-V, --version Print version
# Profile the default binary target
cargo samply
# Profile a specific binary
cargo samply --bin my-binary
# Profile an example
cargo samply --example my-example
# Profile a benchmark (Criterion harness validated)
cargo samply --bench throughput -- --sample-size 10
# Profile an integration test
cargo samply --test my_integration_test
# Build using a different profile
cargo samply --profile release
# Enable specific features
cargo samply --features feature1,feature2
# Disable default features
cargo samply --no-default-features
# Pass arguments to the program being profiled
cargo samply -- arg1 arg2 --flag value
# Pass arguments to samply (e.g., set sample rate)
cargo samply --samply-args "--rate 2000" --bin my-binary
# Run without starting samply (useful for debugging build/target selection)
cargo samply --no-samply
--bench <name>, cargo-samply prefixes the runtime invocation with --bench (mirroring cargo bench).--test <name>, cargo-samply builds the test binary in test mode and runs it for profiling.--test)Profile integration tests or test binaries:
cargo samply --test integration_suite
--samply-args)Pass additional arguments directly to samply:
# Set sample rate
cargo samply --samply-args "--rate 2000" --bin my-binary
# Pass multiple samply options
cargo samply --samply-args "--rate 2000 --save-only profile.json" --bin my-binary
-p, --package)In a workspace with multiple packages, specify which package to profile:
cargo samply -p my-package --bin my-binary
--dry-run)Use --dry-run to preview the build and run commands without executing them:
cargo samply --dry-run --bin my-binary
This prints the cargo build invocation and the samply record command that would be executed, along with any environment variable overrides.
--bench-flag)By default, benchmark targets are invoked with --bench (as Criterion expects). For custom harnesses, you can override this:
# Use a custom flag
cargo samply --bench throughput --bench-flag=--my-custom-flag
# Disable flag injection entirely
cargo samply --bench throughput --bench-flag=none
--list-targets)To see all available binaries, examples, and benchmarks in the workspace:
cargo samply --list-targets
--no-profile-inject)By default, cargo-samply adds a [profile.samply] section to your Cargo.toml to ensure optimized builds with debug symbols. To prevent this modification:
cargo samply --no-profile-inject
Note: If the profile is missing, the build may fail or produce binaries without debug symbols.
| Variable | Description |
|---|---|
CARGO_SAMPLY_SAMPLY_PATH |
Override the path to the samply binary (default: uses samply from PATH). |
CARGO_SAMPLY_NO_PROFILE_INJECT |
If set (any non-empty value), prevents modification of Cargo.toml. Equivalent to --no-profile-inject. |
CARGO_SAMPLY_NO_SYSROOT_INJECTION |
If set, disables automatic injection of Rust sysroot library paths into LD_LIBRARY_PATH/DYLD_LIBRARY_PATH/PATH. Useful if you manage library paths manually. |
This project includes a justfile for common development tasks. Install just and use:
# Run tests (matches CI configuration)
just test
# Update test snapshots when needed
just test-overwrite
# Clean all target directories
just clean-all
# Clean only test project target directories
just clean
# Clean only main project
just clean-main
The project uses trycmd for integration testing, which validates CLI behavior against snapshot files.
When making changes that affect command output:
just testjust test-overwriteIssues and PRs are welcome.
just test