figures.sh
2.2 kB · shellscript · 68 lines
1#!/usr/bin/env bash23set -euo pipefail45HERE="$(cd "$(dirname "$0")" && pwd)"6[ -n "${CARGO_LOCK:-}" ] || exec "$HERE/cargo.sh" "$HERE/figures.sh" "$@"7cd "$HERE/.."89mkdir -p files/figures1011case "${1:-}" in12 check) cargo check -q -p figures --bins -p mrlyfig --tests; exit 0 ;;13 test) cargo test -q -p mrlyfig; exit 0 ;;14esac1516bench=017if [[ "${1:-}" == bench ]]; then bench=1; shift; fi1819if [[ $# -gt 0 ]]; then20 names=("$@")21 full=022else23 names=()24 while IFS= read -r name; do names+=("$name"); done < <(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "figures") | .targets[] | select(.kind[] == "bin") | .name')25 full=126fi2728BENCH_TMP="$(mktemp "${TMPDIR:-/tmp}/mrlyfig-bench.XXXXXX")"29export BENCH_TMP30trap 'rm -f "$BENCH_TMP"' EXIT3132if [[ $full -eq 1 ]]; then33 cargo build -q --profile fig -p figures --bins34else35 cargo build -q --profile fig -p figures "${names[@]/#/--bin=}"36fi37for name in "${names[@]}"; do38 for theme in dark light; do39 echo "$theme $name"40 done41done | xargs -P "$(sysctl -n hw.ncpu)" -n 2 sh -c '42s=$(perl -MTime::HiRes=time -e "print time")43c=044MRLYFIG_THEME="$0" perl -e "alarm 5; exec @ARGV; exit 127" "target/fig/$1" || c=$?45e=$(perl -MTime::HiRes=time -e "print time")46perl -e "printf qq{%.2f\t%s\t%s\t%s\n}, \$ARGV[1] - \$ARGV[0], \$ARGV[2], \$ARGV[3], \$ARGV[4]" "$s" "$e" "$1" "$0" "$c" >> "$BENCH_TMP"47' || true4849table="$(sort -rn "$BENCH_TMP" | awk -F'\t' '{m = ($4 == 142) ? " TIMEOUT" : ($4 == 0 ? "" : " FAIL"); printf "%8.2f %s %s%s\n", $1, $2, $3, m}')"50echo "$table"5152if [[ $full -eq 1 ]]; then53 out="$HERE/../../data/mrlyprod/figures"54 mkdir -p "$out"55 echo "$table" > "$out/bench.txt"56fi5758dark=$(ls files/figures/*-dark.png 2>/dev/null | wc -l | tr -d ' ')59light=$(ls files/figures/*-light.png 2>/dev/null | wc -l | tr -d ' ')60echo "$dark dark and $light light figures in files/figures"6162broke="$(awk -F'\t' '$4 != 0 && $4 != 142 {print "failed: " $2 " " $3}' "$BENCH_TMP")"63slow=$(awk -F'\t' '$4 == 142 || $1 > 5 {n++} END {print n + 0}' "$BENCH_TMP")64[[ -z "$broke" ]] || echo "$broke"65if [[ -n "$broke" ]] || { [[ $bench -eq 0 ]] && [[ $slow -gt 0 ]]; }; then66 [[ $slow -eq 0 ]] || echo "$slow runs over 5 s"67 exit 168fi