github.com/zcqzcg/fabric-ca@v2.0.0-alpha.0.20200416163940-d878ee6db75a+incompatible/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     benchcmp $BENCHMARK_FILE_NAME $NEW_BENCH_FILE_NAME | tee /tmp/bench-cmp.out
    22     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`
    23     for val in $vals
    24     do
    25       delta=$(($val + 0))
    26       if test $delta -gt 10; then
    27          echo "Performance of some of the benchmarks deteriorated by more than 10%"
    28          return 1
    29       fi
    30     done
    31     return 0
    32  }
    33  
    34  BENCHMARK_FILE_NAME=bench.results
    35  NEW_BENCH_FILE_NAME=bench.new
    36  if test -f $BENCHMARK_FILE_NAME; then
    37    cp $BENCHMARK_FILE_NAME $NEW_BENCH_FILE_NAME
    38  else
    39    echo "ERROR: Benchmark results file $BENCHMARK_FILE_NAME for current release is not found"
    40    exit 1
    41  fi
    42  
    43  cur_branch=`git branch | grep -e "^*" | awk '{print substr($0,3,length($0))}'`
    44  if test -z "$cur_branch"; then
    45    echo "ERROR: Failed to determine current git branch name"
    46    exit 1
    47  fi
    48  
    49  git fetch --all --tags --prune
    50  git checkout $prev_release -b branch-$prev_release
    51  if test $? -gt 0; then
    52     echo "ERROR: Failed to switch to previous release $prev_release"
    53     exit 1
    54  fi
    55  
    56  $GOPATH/src/github.com/hyperledger/fabric-ca/scripts/run_benchmarks
    57  if test $? -eq 0; then
    58     compareBenchmarks
    59     exit $?
    60  else
    61     echo "ERROR: failure running benchmarks for release $prev_release"
    62     exit 1
    63  fi
    64  git checkout $cur_branch
    65  git branch -D branch-$prev_release