github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/scripts/compare_benchmarks (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  # This script compares benchmarks results of the current and previous release.
     8  # It assumes that the bench.results file containing current release's benchmark results
     9  # already exists. It checks out the specified previous release, runs the benchmarks
    10  # and compares the benchmark results of the current and previous release. It prints a message
    11  # if the performance deteriorated by more than 10%
    12  
    13  if test -z "$1"; then
    14    echo "ERROR: git label for the previous release must be specifed. Usage: compare_benchmarks <git label of previous release>"
    15    exit 1
    16  else
    17    prev_release=$1
    18  fi
    19  
    20  function compareBenchmarks() {
    21     go get golang.org/x/tools/cmd/benchcmp
    22     benchcmp $BENCHMARK_FILE_NAME $NEW_BENCH_FILE_NAME | tee /tmp/bench-cmp.out
    23     vals=`cat /tmp/bench-cmp.out | while read line; do echo $line | grep -e "^Benchmark" | tr -s " " | cut -d " " -f 4 | grep -e "^+"| awk '{print substr($0,2,length($0)-5)}'; done`
    24     for val in $vals
    25     do
    26       delta=$(($val + 0))
    27       if test $delta -gt 10; then
    28          echo "Performance of some of the benchmarks deteriorated by more than 10%"
    29          return 1
    30       fi
    31     done
    32     return 0
    33  }
    34  
    35  BENCHMARK_FILE_NAME=bench.results
    36  NEW_BENCH_FILE_NAME=bench.new
    37  if test -f $BENCHMARK_FILE_NAME; then
    38    cp $BENCHMARK_FILE_NAME $NEW_BENCH_FILE_NAME
    39  else
    40    echo "ERROR: Benchmark results file $BENCHMARK_FILE_NAME for current release is not found"
    41    exit 1
    42  fi
    43  
    44  cur_branch=`git branch | grep -e "^*" | awk '{print substr($0,3,length($0))}'`
    45  if test -z "$cur_branch"; then
    46    echo "ERROR: Failed to determine current git branch name"
    47    exit 1
    48  fi
    49  
    50  git fetch --all --tags --prune
    51  git checkout $prev_release -b branch-$prev_release
    52  if test $? -gt 0; then
    53     echo "ERROR: Failed to switch to previous release $prev_release"
    54     exit 1
    55  fi
    56  
    57  $GOPATH/src/github.com/hyperledger/fabric-ca/scripts/run_benchmarks
    58  if test $? -eq 0; then
    59     compareBenchmarks
    60     exit $?
    61  else
    62     echo "ERROR: failure running benchmarks for release $prev_release"
    63     exit 1
    64  fi
    65  git checkout $cur_branch
    66  git branch -D branch-$prev_release