#!/usr/bin/env bash set -euo pipefail # Soak runner for Mixed benchmark to track RSS + throughput stability. # Intended for Phase 50 "Operational Edge" (RSS drift / long-run stability). # # Usage examples: # make bench_random_mixed_hakmem_minimal # BENCH_BIN=./bench_random_mixed_hakmem_minimal \ # DURATION_SEC=1800 STEP_ITERS=20000000 WS=400 \ # ./scripts/soak_mixed_rss.sh > soak.csv # # Output CSV columns: # epoch_s,elapsed_s,iter,throughput_ops_s,peak_rss_mb bin=${BENCH_BIN:-./bench_random_mixed_hakmem_minimal} ws=${WS:-400} step_iters=${STEP_ITERS:-20000000} duration_sec=${DURATION_SEC:-1800} profile=${HAKMEM_PROFILE:-MIXED_TINYV3_C7_SAFE} # Force known research knobs OFF to avoid accidental carry-over (same policy as run_mixed_10_cleanenv.sh). export HAKMEM_TINY_HEADER_WRITE_ONCE=${HAKMEM_TINY_HEADER_WRITE_ONCE:-0} export HAKMEM_TINY_C7_PRESERVE_HEADER=${HAKMEM_TINY_C7_PRESERVE_HEADER:-0} export HAKMEM_TINY_TCACHE=${HAKMEM_TINY_TCACHE:-0} export HAKMEM_TINY_TCACHE_CAP=${HAKMEM_TINY_TCACHE_CAP:-64} export HAKMEM_MALLOC_TINY_DIRECT=${HAKMEM_MALLOC_TINY_DIRECT:-0} export HAKMEM_FRONT_FASTLANE_ALLOC_LEGACY_DIRECT=${HAKMEM_FRONT_FASTLANE_ALLOC_LEGACY_DIRECT:-0} export HAKMEM_FORCE_LIBC_ALLOC=${HAKMEM_FORCE_LIBC_ALLOC:-0} export HAKMEM_ENV_SNAPSHOT_SHAPE=${HAKMEM_ENV_SNAPSHOT_SHAPE:-0} export HAKMEM_FASTLANE_DIRECT=${HAKMEM_FASTLANE_DIRECT:-1} export HAKMEM_FREE_TINY_FAST_MONO_DUALHOT=${HAKMEM_FREE_TINY_FAST_MONO_DUALHOT:-1} export HAKMEM_FREE_TINY_FAST_MONO_LEGACY_DIRECT=${HAKMEM_FREE_TINY_FAST_MONO_LEGACY_DIRECT:-1} start_epoch=$(date +%s) end_epoch=$((start_epoch + duration_sec)) echo "epoch_s,elapsed_s,iter,throughput_ops_s,peak_rss_mb" iter=0 while :; do now=$(date +%s) if (( now >= end_epoch )); then break fi tmp_time=$(mktemp) tmp_out=$(mktemp) HAKMEM_PROFILE="${profile}" /usr/bin/time -v -o "${tmp_time}" \ "${bin}" "${step_iters}" "${ws}" 1 >"${tmp_out}" 2>&1 || true out=$(rg -o "Throughput =\\s+[0-9]+\\s+ops/s" -m 1 "${tmp_out}" | rg -o "[0-9]+" || echo 0) peak_kb=$(rg -o "Maximum resident set size \\(kbytes\\):\\s+[0-9]+" -m 1 "${tmp_time}" | rg -o "[0-9]+" || echo 0) peak_mb=$(awk -v kb="${peak_kb}" 'BEGIN{printf "%.2f", kb/1024.0}') rm -f "${tmp_time}" "${tmp_out}" iter=$((iter + step_iters)) now=$(date +%s) elapsed=$((now - start_epoch)) echo "${now},${elapsed},${iter},${out},${peak_mb}" done