OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scripts / mountain-bench.sh

64 lines · bash ref:
#!/bin/bash
# mountain-bench.sh — run scenes/test/mountain_bench.tscn under a fixed configuration.
#
#   scripts/mountain-bench.sh                     # one run, JSON to /tmp/mountain-bench-<time>.json
#   scripts/mountain-bench.sh --inject-ms 25      # RULER SELF-TEST (must report VALID)
#   scripts/mountain-bench.sh --out result.json
#
# NEVER run two benchmarks at once, or during a build: they contend for cores, cache and
# GPU and corrupt each other's numbers (optimization-loop §2). This refuses if scons or
# another Godot is running.
set -uo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. "$REPO/scripts/engine.sh"
export DISPLAY="${DISPLAY:-:0}"

if pgrep -x scons >/dev/null || pgrep -f "scons " >/dev/null; then
  echo "mountain-bench: a scons build is running -- numbers would be corrupted. Refusing." >&2; exit 3
fi
if pgrep -f "godot.linuxbsd" | grep -qv "^$$\$"; then
  echo "mountain-bench: another Godot is running (editor/game) -- close it first. Refusing." >&2; exit 3
fi
# A blanked monitor turns vsync-less presents into ~1 s stalls (hyper-games #86).
if command -v xset >/dev/null && xset q 2>/dev/null | grep -q "Monitor is Off"; then
  echo "mountain-bench: the monitor is OFF (DPMS) -- wake it first. Refusing." >&2; exit 3
fi

OUT="/tmp/mountain-bench-$(date +%Y%m%d-%H%M%S).json"
ARGS=()
while [ $# -gt 0 ]; do
  case "$1" in
    --out) OUT="$2"; shift 2 ;;
    *) ARGS+=("$1"); shift ;;
  esac
done
echo "mountain-bench: engine $GODOT"
echo "mountain-bench: commit $(git -C "$REPO" rev-parse --short HEAD)$(git -C "$REPO" diff --quiet || echo '+dirty')"
# THE MACHINE'S STATE, before and after. Identical workloads drifted 6.35 -> 7.79 ms
# (idle p50) across three runs while the load average fell from a build and Firefox
# held ~95% of a core; without this record a noisy run looks like a regression.
machine_state() {
  echo "mountain-bench: [$1] load $(cut -d' ' -f1-3 /proc/loadavg)"
  command -v nvidia-smi >/dev/null && nvidia-smi --query-gpu=temperature.gpu,clocks.gr,clocks.mem,power.draw,pstate,clocks_throttle_reasons.active \
    --format=csv,noheader | sed "s/^/mountain-bench: [$1] gpu /"
  echo "mountain-bench: [$1] top cpu: $(ps -eo pcpu,comm --sort=-pcpu | sed -n '2,4p' | tr -s ' ' | paste -sd ',')"
}
# START COOL. Back-to-back runs began at 86 C with the thermal-slowdown flag set, and
# that alone moved one workload's idle GPU p95 from 7.58 to 11.44 ms (2026-09-29).
# Two runs are comparable only if both started below the same temperature.
COOL_C="${BENCH_COOL_C:-60}"
if command -v nvidia-smi >/dev/null; then
  t0=$(date +%s)
  while t=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits | head -1); [ "$t" -gt "$COOL_C" ]; do
    [ $(( $(date +%s) - t0 )) -ge 900 ] && { echo "mountain-bench: GPU still ${t} C after 15 min (> ${COOL_C} C). Refusing." >&2; exit 3; }
    sleep 10
  done
  echo "mountain-bench: GPU ${t} C <= ${COOL_C} C (cooled for $(( $(date +%s) - t0 )) s)"
fi
machine_state before
"$GODOT" --path "$REPO" --rendering-driver vulkan --resolution 1920x1080 \
  res://scenes/test/mountain_bench.tscn -- --out "$OUT" "${ARGS[@]}"
rc=$?
machine_state after
exit $rc