#!/bin/bash
# Measure an MP3 decoder change on the host and on hardware, in one command.
#
#   bash mp3measure                  # host Callgrind + ESP32-C6 + PSNR
#   bash mp3measure --gates          # also conformance, sanitizers, lint
#   bash mp3measure --skip-device    # host only, when no board is attached
#
# Everything the loop needs: host instruction counts against the last commit,
# the device time and Helix ratio from a real autoresearch run, the riscv32
# .text delta, and the PSNR tripwire. Step output goes to log files; the
# report itself stays short enough to read.
set -e
cd "$(dirname "$0")"

# NixOS cannot run the prebuilt clang-tool-chain binaries without this, and a
# missing shim shows up as an unrelated compiler failure three minutes in.
if [ -f "$HOME/.clud/tmp/nixcompat/env.sh" ]; then
    # shellcheck disable=SC1091
    source "$HOME/.clud/tmp/nixcompat/env.sh"
fi

if ! command -v uv &> /dev/null; then
    echo "uv not found. Install it: https://docs.astral.sh/uv/"
    exit 1
fi

uv run python ci/codec_cpu/report.py "$@"
