| @@ -2,8 +2,9 @@ |
| 2 | 2 | # Benchmark results over time (issue #101), for a dedicated, quiet machine |
| 3 | 3 | # (.toboggan/workflows/bench.yml). Runs scripts/bench.sh and |
| 4 | 4 | # scripts/bench-compile.sh, counts each benchmark's user-space |
| 5 | | −# instructions with `perf stat` (far less noisy than wall time; skipped |
| 6 | | −# without perf), and writes the results as one CSV per commit: |
| 5 | +# instructions with `perf stat` on one scheduler thread (the same to a few |
| 6 | +# parts in 10^8 from run to run, where wall time varies by percents; |
| 7 | +# skipped without perf), and writes the results as one CSV per commit: |
| 7 | 8 | # |
| 8 | 9 | # commit,benchmark,metric,value # metric: ms, compile_ms, instructions |
| 9 | 10 | # |
| @@ -17,8 +18,8 @@ |
| 17 | 18 | # Environment: LOUISE_BENCH_DIR, where results are kept (default |
| 18 | 19 | # ~/louise-bench): <commit>.csv, <commit>.report, and `index`, the commits |
| 19 | 20 | # in the order they ran. BENCH_THRESHOLD_MS (default 10) and |
| 20 | | −# BENCH_THRESHOLD_INSTRUCTIONS (default 2), in percent. BENCH_RUNS, as |
| 21 | | −# for bench.sh. |
| 21 | +# BENCH_THRESHOLD_INSTRUCTIONS (default 1), in percent. BENCH_RUNS, as |
| 22 | +# for bench.sh (instructions are counted once). |
| 22 | 23 | set -euo pipefail |
| 23 | 24 | cd "$(dirname "$0")/.." |
| 24 | 25 | |
| @@ -37,21 +38,24 @@ while read -r name ms; do echo "$commit,$name,ms,$ms"; done < "$work/run.txt" >> |
| 37 | 38 | while read -r name ms; do echo "$commit,$name,compile_ms,$ms"; done < "$work/compile.txt" >> "$csv" |
| 38 | 39 | # User-space instructions a program runs, or nothing if perf cannot count |
| 39 | 40 | # them (not installed, no counters, or perf_event_paranoid above 2). |
| 41 | +# - One scheduler thread: on 22, threads that steal or spin vary the count |
| 42 | +# by 0.3-1.5%; on one, it is the same to a few parts in 10^8. |
| 43 | +# - On a hybrid CPU perf reports one row per core type |
| 44 | +# (`cpu_core/instructions/u`, `cpu_atom/instructions/u`), each counting |
| 45 | +# while the program runs on that type: their sum is the total. |
| 46 | +# `--no-scale`: by default perf scales each row up as if its counter had |
| 47 | +# been multiplexed, which counted up to 30% too many, varying with the |
| 48 | +# time spent on each core type. |
| 40 | 49 | instructions() { |
| 41 | 50 | command -v perf >/dev/null || return 0 |
| 42 | | − perf stat -x, -e instructions:u -o "$work/perf.txt" "$@" >/dev/null || return 1 |
| 43 | | − awk -F, '$3 ~ /^instructions/ && $1 ~ /^[0-9]+$/ { print $1 }' "$work/perf.txt" |
| 51 | + LOUISE_THREADS=1 perf stat --no-scale -x, -e instructions:u -o "$work/perf.txt" "$@" >/dev/null || return 1 |
| 52 | + awk -F, '$3 ~ /instructions/ && $1 ~ /^[0-9]+$/ { n += $1; seen = 1 } |
| 53 | + END { if (seen) print n }' "$work/perf.txt" |
| 44 | 54 | } |
| 45 | 55 | if [ -n "$(instructions true)" ]; then |
| 46 | 56 | for program in tests/bench/*.lse; do |
| 47 | 57 | name="$(basename "$program" .lse)" |
| 48 | | − # The fewest of BENCH_RUNS: threads that steal or spin add some. |
| 49 | | − best="" |
| 50 | | − for _ in $(seq "${BENCH_RUNS:-3}"); do |
| 51 | | − n="$(instructions "$work/programs/$name")" |
| 52 | | − if [ -z "$best" ] || [ "$n" -lt "$best" ]; then best=$n; fi |
| 53 | | − done |
| 54 | | − echo "$commit,$name,instructions,$best" >> "$csv" |
| 58 | + echo "$commit,$name,instructions,$(instructions "$work/programs/$name")" >> "$csv" |
| 55 | 59 | done |
| 56 | 60 | else |
| 57 | 61 | echo "bench-track: perf cannot count instructions here, so they are not recorded" |
| @@ -67,7 +71,7 @@ report="$dir/$commit.report" |
| 67 | 71 | if [ -z "$previous" ] || [ ! -f "$dir/$previous.csv" ]; then |
| 68 | 72 | echo "bench-track: no previous results to compare with" | tee "$report" |
| 69 | 73 | else |
| 70 | | − awk -F, -v ms="${BENCH_THRESHOLD_MS:-10}" -v ins="${BENCH_THRESHOLD_INSTRUCTIONS:-2}" \ |
| 74 | + awk -F, -v ms="${BENCH_THRESHOLD_MS:-10}" -v ins="${BENCH_THRESHOLD_INSTRUCTIONS:-1}" \ |
| 71 | 75 | -v before="${previous:0:10}" -v after="${commit:0:10}" ' |
| 72 | 76 | FNR == 1 { next } |
| 73 | 77 | NR == FNR { old[$2 "," $3] = $4; next } |