#!/usr/bin/env bash set -euo pipefail # Run a representative subset of mimalloc-bench with HAKMEM via LD_PRELOAD. # Produces logs under bench_results/. ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT_DIR" RESULT_DIR="$ROOT_DIR/bench_results/mimalloc_suite_$(date +%Y%m%d_%H%M%S)" mkdir -p "$RESULT_DIR" echo "[info] Building HAKMEM shared library with PGO (for LD_PRELOAD)" make -s pgo-profile-shared pgo-build-shared >/dev/null BENCH_ROOT="$ROOT_DIR/mimalloc-bench" BENCH_OUT="$BENCH_ROOT/out/bench" if [[ ! -d "$BENCH_OUT" ]]; then echo "[warn] mimalloc-bench/out/bench not found." echo " Build it first: (may require sudo/network)" echo " cd mimalloc-bench" echo " ./build-bench-env.sh all" exit 1 fi pushd "$BENCH_OUT" >/dev/null TESTS=(larson cfrac espresso xmalloc-test sh6bench sh8bench cscratch cthrash mstress malloc-large) ALLOC_HAK=(sys) # sys + LD_PRELOAD=hakmem ALLOC_BASE=(mi je sys) # reference allocators for comparison PROCS=(1 4) echo "[info] Running mimalloc-bench subset with HAKMEM (LD_PRELOAD)" for p in "${PROCS[@]}"; do log="$RESULT_DIR/hakmem_p${p}.log" echo "[case] HAKMEM LD_PRELOAD --procs=$p | tests: ${TESTS[*]}" | tee -a "$log" LD_PRELOAD="$ROOT_DIR/libhakmem.so" \ HAKMEM_WRAP_TINY=1 bash ../../bench.sh --procs="$p" "${ALLOC_HAK[@]}" "${TESTS[@]}" 2>&1 | tee -a "$log" || true done echo "[info] Running reference allocators (mi/je/sys)" for p in "${PROCS[@]}"; do log="$RESULT_DIR/ref_p${p}.log" echo "[case] REF mi/je/sys --procs=$p | tests: ${TESTS[*]}" | tee -a "$log" bash ../../bench.sh --procs="$p" "${ALLOC_BASE[@]}" "${TESTS[@]}" 2>&1 | tee -a "$log" || true done popd >/dev/null echo "[info] Logs written to: $RESULT_DIR" echo "[done] mimalloc-bench subset complete"