Files
hakmem/benchmarks/scripts/utils/save_prof_sweep.sh

64 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# Save a short profiler sweep into docs/benchmarks/<YYYYMMDD_HHMMSS>/
# Usage: scripts/save_prof_sweep.sh [-d SEC] [-t CSV] [-s N]
RUNTIME=2
THREADS="1,4"
SAMPLE_N=8
BENCH_TIMEOUT=""
KILL_GRACE=${KILL_GRACE:-2}
while getopts ":d:t:s:h" opt; do
case $opt in
d) RUNTIME="$OPTARG" ;;
t) THREADS="$OPTARG" ;;
s) SAMPLE_N="$OPTARG" ;;
h) echo "Usage: $0 [-d SEC] [-t CSV] [-s N]"; exit 0 ;;
:) echo "Missing arg -$OPTARG"; exit 2 ;;
*) echo "Usage: $0 [-d SEC] [-t CSV] [-s N]"; exit 2 ;;
esac
done
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
OUTDIR="$ROOT_DIR/docs/benchmarks/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTDIR"
LIB="$(readlink -f "$ROOT_DIR/libhakmem.so" || true)"
LARSON="$ROOT_DIR/mimalloc-bench/bench/larson/larson"
if [[ -z "${BENCH_TIMEOUT}" ]]; then
BENCH_TIMEOUT=$(( RUNTIME + 3 ))
fi
echo "Saving sweep into: $OUTDIR" | tee "$OUTDIR/summary.txt"
echo "RUNTIME=$RUNTIME THREADS=$THREADS SAMPLE=1/$((1<<SAMPLE_N)) TIMEOUT=${BENCH_TIMEOUT}s" | tee -a "$OUTDIR/summary.txt"
declare -a RUNS=(
"tiny 8 1024"
"mid 2048 32768"
"gap 33000 65536"
"large 65536 1048576"
)
IFS=',' read -r -a TARR <<< "$THREADS"
for r in "${RUNS[@]}"; do
read -r name rmin rmax <<< "$r"
for t in "${TARR[@]}"; do
label="${name}_T${t}_${rmin}-${rmax}"
echo "== $label ==" | tee -a "$OUTDIR/summary.txt"
if [[ -f "$LARSON" && -f "$ROOT_DIR/libhakmem.so" ]]; then
timeout -k "${KILL_GRACE}s" "${BENCH_TIMEOUT}s" \
env HAKMEM_PROF=1 HAKMEM_PROF_SAMPLE="$SAMPLE_N" \
LD_PRELOAD="$LIB" "$LARSON" "$RUNTIME" "$rmin" "$rmax" 10000 1 12345 "$t" 2>&1 \
| tee "$OUTDIR/${label}.log" | tail -n 80 | tee -a "$OUTDIR/summary.txt"
else
echo "Skip: missing larson or libhakmem.so" | tee -a "$OUTDIR/summary.txt"
fi
done
done
echo "Done. See $OUTDIR" | tee -a "$OUTDIR/summary.txt"