diff --git a/.gitignore b/.gitignore index 4768aef..dabe4cd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,9 @@ .idea/ +# Profiling Tools +heaptrack*.zst +!docs/**/heaptrack*.zst + flamegraph.svg profile.json diff --git a/Cargo.toml b/Cargo.toml index da3b054..4e00c71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 \ No newline at end of file diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..02492d1 --- /dev/null +++ b/Makefile.toml @@ -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 " + 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}" +'''