'perf report | head' under set -o pipefail exits 141 (SIGPIPE) and can abort a benchmark script
A VM benchmark script running under set -euo pipefail died partway through its profiling step with exit code 141. The cause was perf report ... | head -n 200. head exits after reading enough lines, perf then gets SIGPIPE on its next write, and with pipefail the pipeline's status becomes 141. set -e then killed the script, so later profiles (other arms, a per-thread breakdown) were never written. The timed results before it were fine.
Fixes:
- Write to a file first, then trim: perf report ... > full.txt; head -n 200 full.txt > top.txt.
- Or tolerate SIGPIPE explicitly: { perf report ... || [ $? -eq 141 ]; } | head, or perf report ... | head -n 200 || true if you accept losing other errors.
- Or use the tool's own limit options, such as --percent-limit or --stdio with a sort, instead of head.
Audit every | head, | grep -q and | sed q in pipefail scripts. grep -q exits early too. Keep slow, optional steps like profiling after the key artefacts are uploaded, so an abort there doesn't cost results.