Files

77 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# The timed CLI sweeps: `format --check` (cold and warm cache) and `check`
# (default rules, and `--select error,warning,style`) over five opentitan
# trees, one binary at a time, three tries per cell, wall clock and peak RSS
# from `/usr/bin/time -l`.
#
# tools/perf/sweep.sh <lucisv-binary> <label> <opentitan-dir> <out-dir> \
# [tries] [trees]
#
# `trees` is a space-separated list, defaulting to all five; pass one tree to
# check a single cell (`sweeptable.py` reads whatever is there).
#
# Each cell writes `<out-dir>/<label>__<tree>__<command>__<cache>.txt`, which
# holds the three runs' `/usr/bin/time -l` blocks; `sweeptable.py` reads them.
# The formatter cache is a scratch `--cache-dir` under `<out-dir>`, so nothing
# is ever written into the corpus.
#
# Every `lucisv` invocation goes through `tools/guard.sh -m 8 -t 1800`.
set -u
BIN=${1:?usage: sweep.sh <binary> <label> <opentitan> <outdir> [tries]}
LABEL=${2:?}
OT=${3:?}
OUT=${4:?}
TRIES=${5:-3}
HERE=$(cd "$(dirname "$0")" && pwd)
GUARD="$HERE/../guard.sh"
CACHE="$OUT/fmtcache"
TREES=${6:-"hw/ip hw/top_earlgrey/ip hw/top_darjeeling/ip hw/dv hw/vendor"}
mkdir -p "$OUT"
# Cache warmth, per try, not per cell.
#
# Until take 5 §P0 this deleted `$CACHE` once before the *three* cold tries,
# so tries 2 and 3 read the store the first try had just written: two of every
# three "cold" numbers were warm. Now a cold try deletes the scratch cache
# immediately before itself, and a warm cell is primed by one explicit
# untimed run whose output is kept in the log but not counted. `sweeptable.py`
# prints the "N files from cache" each try reported, so a cold row that is not
# actually cold is visible rather than inferred.
#
# Only `$CACHE` — a scratch directory under `$OUT` — is ever removed. Nothing
# inside the corpus is touched.
run_cell() {
local tree=$1 name=$2 cache=$3
shift 3
local safe=${tree//\//_}
local log="$OUT/${LABEL}__${safe}__${name}__${cache}.txt"
: >"$log"
if [ "$cache" = warm ]; then
echo "--- prime (untimed, not a try) ---" >>"$log"
rm -rf "$CACHE"
"$GUARD" -m 8 -t 1800 -- "$BIN" "$@" >>"$log" 2>>"$log"
echo "--- prime exit $? ---" >>"$log"
fi
local i
for i in $(seq 1 "$TRIES"); do
if [ "$cache" = cold ]; then rm -rf "$CACHE"; fi
echo "--- try $i ---" >>"$log"
# `-l` puts the resource block on stderr; both streams are kept.
"$GUARD" -m 8 -t 1800 -- /usr/bin/time -l "$BIN" "$@" >>"$log" 2>>"$log"
echo "--- exit $? ---" >>"$log"
done
echo "$log"
}
for tree in $TREES; do
echo "== $LABEL $tree"
run_cell "$tree" format cold format --cache-dir "$CACHE" --check "$OT/$tree"
run_cell "$tree" format warm format --cache-dir "$CACHE" --check "$OT/$tree"
run_cell "$tree" check default check "$OT/$tree"
run_cell "$tree" check select check --select error,warning,style "$OT/$tree"
done