Skip to content

Commit

Permalink
chore: add cargo-make target for heaptrack
Browse files Browse the repository at this point in the history
  • Loading branch information
pbillaut committed Sep 16, 2024
1 parent 236b612 commit d6d43e9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

.idea/

# Profiling Tools
heaptrack*.zst
!docs/**/heaptrack*.zst

flamegraph.svg
profile.json
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
criterion = { version = "0.5.1", features = ["html_reports"] }
test-log = { version = "0.2.16", features = ["trace"] }

[profile.perf]
# Profile for memory profiling
inherits = "release"
debug = true

[[bench]]
name = "bench_main"
harness = false
44 changes: 44 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[env]
BENCHES_DATA_DIR = "${CARGO_MAKE_WORKING_DIRECTORY}/benches/data"
BUILD_PROFILE_PERF = "perf"

# ------------------------------------------------------
# Group: Memory Profiling
# ------------------------------------------------------
[tasks.build-perf]
description = "Build the perf release to profile against"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE_PERF}"]

[tasks.heaptrack]
description = "Run heaptrack"
script = '''
SIZE="${1:-10K}"
TAG="${2:-$(date +"%Y-%m-%d_%H-%M-%S")}"
if [ -z "${SIZE}" ] || [ -z "${TAG}" ]; then
echo "ERROR: Invalid or missing argument"
echo
echo "Usage: cargo make mem-perf <SIZE> <TAG>"
echo "Example: cargo make mem-perf 1K optimized"
echo
exit 1
fi
SAMPLE_FILE="${BENCHES_DATA_DIR}/activities_${SIZE}.csv"
if [ ! -f "$SAMPLE_FILE" ]; then
echo "ERROR: File '${SAMPLE_FILE}' does not exist."
echo
echo "Available sample files in '${DATA_DIR}':"
for file in ${BENCHES_DATA_DIR}/activities_*.csv; do
echo "• $(basename "$file")"
done
echo
exit 1
fi
OUTPUT_FILE="${CARGO_MAKE_WORKING_DIRECTORY}/heaptrack.${CARGO_MAKE_CRATE_NAME}.${SIZE}.${TAG}.zst"
BINARY="${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/${BUILD_PROFILE_PERF}/${CARGO_MAKE_CRATE_NAME}"
heaptrack --output "${OUTPUT_FILE}" "${BINARY}" "${SAMPLE_FILE}"
'''

0 comments on commit d6d43e9

Please sign in to comment.