Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ panic = "unwind"

[profile.profiling]
inherits = "dev"
opt-level = 0
opt-level = 1
debug = true
split-debuginfo = "unpacked"
panic = "abort"
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{

fn main() {
// Only needed when profiling Forest with `gperftools`. This might not work on all platforms.
println!("cargo:rerun-if-env-changed=FOREST_PROFILING_GPERFTOOLS_BUILD");
if is_env_truthy("FOREST_PROFILING_GPERFTOOLS_BUILD") {
println!("cargo:rustc-link-lib=tcmalloc");
}
Expand Down
39 changes: 39 additions & 0 deletions mise-tasks/gperf/heap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
#MISE description="Build and heap-profile a Forest binary with gperftools. Usage: mise run gperf:heap <bin> [-- <bin-args...>]. Dumps to /tmp/gperfheap.<bin>.prof.*"

set -euo pipefail

if [ $# -lt 1 ]; then
echo "usage: mise run gperf:heap <bin> [-- <bin-args...>]" >&2
exit 2
fi

bin="$1"
shift
# Strip the `--` separator if mise forwarded it.
if [ "${1-}" = "--" ]; then
shift
fi

# `FOREST_PROFILING_GPERFTOOLS_BUILD` toggles `cargo:rustc-link-lib=tcmalloc` in
# build.rs — without it, the binary won't be linked against gperftools and
# `HEAPPROFILE` is inert.
# `--message-format=json-render-diagnostics` reports the built executable path
# on stdout (respecting any `CARGO_TARGET_DIR` / `[build] target-dir` override);
# diagnostics still render on stderr.
exe=$(
FOREST_PROFILING_GPERFTOOLS_BUILD=1 cargo build \
--no-default-features --features system-alloc --profile=profiling \
--bin "$bin" --message-format=json-render-diagnostics |
sed -n 's/.*"executable":"\([^"]*\)".*/\1/p' |
tail -1
)
if [ -z "$exe" ]; then
echo "could not locate built executable for $bin" >&2
exit 1
fi

ulimit -n 8192
Comment thread
LesnyRumcajs marked this conversation as resolved.
HEAPPROFILE_USE_PID=t \
HEAPPROFILE="/tmp/gperfheap.${bin}.prof" \
"$exe" "$@"
Loading