#!/bin/sh # What compiler instrumentation costs: zig build bench-llvm -Doptimize=ReleaseFast. # Arguments: ztrace, the bench tool (src/instr/bench.zig), the plugin, the # runtime, the targets directory. set -eu ztrace=$1 bench=$2 plugin=$3 rt=$4 targets=$5 tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT # target : argument when traced : argument when not : how many times more # work the second is. With no tracer a target runs too briefly to time at # the first. workloads="fib:24:35:199.006 sort:2000:400000:200 list:5000:1000000:200 bfs:3000:600000:200" selections="lines stores loads calls vars lines,calls,vars lines,calls,vars,stores edges cmps cyg" # The best of three runs: milliseconds, then whatever else the tool printed. best() { for _ in 1 2 3; do "$bench" "$@"; done | sort -n | head -1 } cat <<'EOF2' Per selection of `ztrace cc --instr`: events emitted at the traced workload idle time against the uninstrumented program, with no tracer ring the same into a ring drained and thrown away ns nanoseconds an event, into that ring B/event bytes of recording an event (`ztrace run`, a moment a line) B/line bytes of recording a source line executed rec/s events a second into the recording EOF2 for opt in -O0 -O2; do for w in $workloads; do IFS=: read -r name arg long scale <&1 | sed 's/.* \([0-9]*\) bytes.* \([0-9]*\) events\/s.*/\1 \2/') echo "$traced $recorded" | awk -v s="$s" -v start="$start" -v alone="$alone" -v scale="$scale" -v idle="$idle" -v lines="$lines" \ '{ printf " %-24s %9d %6.1fx %8.1fx %6.1f %8.1f %7.1f %9d\n", s, $2, (idle - start) / alone, ($1 - start) * scale / alone, ($1 - start - alone / scale) * 1e6 / $2, $(NF - 1) / $2, $(NF - 1) / lines, $NF }' done done done "$ztrace" cc --plugin "$plugin" --rt "$rt" -- clang -O0 "$targets/instr_sort.c" -o "$tmp/sort" echo echo "sort 2000 -O0, held at each line by the stop mask and resumed at once:" best --step "$tmp/sort" 2000 | awk '{ ms = $1; sub(/.* line=/, ""); printf " %d stops in %.0f ms: %.0f a second\n", $1, ms, $1 / ms * 1000 }'