t / perf / bisect_regressionon commit Merge branch 'bw/protocol-v2' (1ba2fc6)
   1#!/bin/sh
   2
   3# Read a line coming from `./aggregate.perl --sort-by regression ...`
   4# and automatically bisect to find the commit responsible for the
   5# performance regression.
   6#
   7# Lines from `./aggregate.perl --sort-by regression ...` look like:
   8#
   9# +100.0% p7821-grep-engines-fixed.1 0.04(0.10+0.03) 0.08(0.11+0.08) v2.14.3 v2.15.1
  10# +33.3% p7820-grep-engines.1 0.03(0.08+0.02) 0.04(0.08+0.02) v2.14.3 v2.15.1
  11#
  12
  13die () {
  14        echo >&2 "error: $*"
  15        exit 1
  16}
  17
  18while [ $# -gt 0 ]; do
  19        arg="$1"
  20        case "$arg" in
  21        --help)
  22                echo "usage: $0 [--config file] [--subsection subsection]"
  23                exit 0
  24                ;;
  25        --config)
  26                shift
  27                GIT_PERF_CONFIG_FILE=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
  28                export GIT_PERF_CONFIG_FILE
  29                shift ;;
  30        --subsection)
  31                shift
  32                GIT_PERF_SUBSECTION="$1"
  33                export GIT_PERF_SUBSECTION
  34                shift ;;
  35        --*)
  36                die "unrecognised option: '$arg'" ;;
  37        *)
  38                die "unknown argument '$arg'"
  39                ;;
  40        esac
  41done
  42
  43read -r regression subtest oldtime newtime oldrev newrev
  44
  45test_script=$(echo "$subtest" | sed -e 's/\(.*\)\.[0-9]*$/\1.sh/')
  46test_number=$(echo "$subtest" | sed -e 's/.*\.\([0-9]*\)$/\1/')
  47
  48# oldtime and newtime are decimal number, not integers
  49
  50oldtime=$(echo "$oldtime" | sed -e 's/^\([0-9]\+\.[0-9]\+\).*$/\1/')
  51newtime=$(echo "$newtime" | sed -e 's/^\([0-9]\+\.[0-9]\+\).*$/\1/')
  52
  53test $(echo "$newtime" "$oldtime" | awk '{ print ($1 > $2) }') = 1 ||
  54        die "New time '$newtime' shoud be greater than old time '$oldtime'"
  55
  56tmpdir=$(mktemp -d -t bisect_regression_XXXXXX) || die "Failed to create temp directory"
  57echo "$oldtime" >"$tmpdir/oldtime" || die "Failed to write to '$tmpdir/oldtime'"
  58echo "$newtime" >"$tmpdir/newtime" || die "Failed to write to '$tmpdir/newtime'"
  59
  60# Bisecting must be performed from the top level directory (even with --no-checkout)
  61(
  62        toplevel_dir=$(git rev-parse --show-toplevel) || die "Failed to find top level directory"
  63        cd "$toplevel_dir" || die "Failed to cd into top level directory '$toplevel_dir'"
  64
  65        git bisect start --no-checkout "$newrev" "$oldrev" || die "Failed to start bisecting"
  66
  67        git bisect run t/perf/bisect_run_script "$test_script" "$test_number" "$tmpdir"
  68        res="$?"
  69
  70        git bisect reset
  71
  72        exit "$res"
  73)