1 #!/bin/bash 2 3 # Copyright 2013 The Chromium Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 # Produce metrics analyzing the output of a stress test 8 9 set -e 10 11 error() { 12 echo "error: ${@}" >&2 13 } 14 15 # Given a token, search for and count the instances of lines from the 16 # logfile that start with the token. 17 count_result() { 18 if [ ! -z "${1}" ]; then 19 echo $(cat "${log}" | grep "^${1} " | wc -l) 20 else 21 echo 0 22 fi 23 } 24 25 main() { 26 if [ $# -lt 1 ]; then 27 cat <<EOF 28 29 USAGE: $(basename ${0}) logfile 30 31 Analyze the logfile of a stress test and produce metrics. 32 33 EOF 34 exit 1 35 fi 36 37 local log="${1}" 38 if [ ! -f "${log}" ]; then 39 error "\"${log}\" not found" 40 exit 1 41 fi 42 43 cat <<EOF 44 $(count_result "PASS_COURGETTE") successful courgette patches 45 $(count_result "FAIL_COURGETTE") failed courgette patches 46 $(count_result "FAIL_DISASSEMBLE") failed to disassemble/assemble 47 $(count_result "PASS_BSDIFF") succesful bsdiff patches 48 $(count_result "FAIL_BSDIFF") failed bsdiff patches 49 $(count_result "BEST_COURGETTE") patch(es) where courgette is smaller 50 $(count_result "BEST_BSDIFF") patch(es) where bsdiff is smaller 51 $(count_result "BEST_TIE") patch(es) where both are the same size 52 EOF 53 54 # Log file has the format "^SIZE courgette=... bsdiff=..." 55 local courgette_total="$(cat "${log}" \ 56 | grep "^SIZE " \ 57 | cut -d' ' -f2 \ 58 | awk -F= 'BEGIN{sum=0} {sum += $2} END{print sum}')" 59 echo "${courgette_total} bytes for a courgette payload" 60 61 local bsdiff_total="$(cat "${log}" \ 62 | grep "^SIZE " \ 63 | cut -d' ' -f3 \ 64 | awk -F= 'BEGIN{sum=0} {sum += $2} END{print sum}')" 65 echo "${bsdiff_total} bytes for a bsdiff payload" 66 67 local best_total="$(cat "${log}" \ 68 | grep "^BEST_" \ 69 | awk 'BEGIN{sum=0} {sum += $2} END{print sum}')" 70 echo "${best_total} bytes for a best-choice payload" 71 72 local pct="$(echo "100*${best_total}/${bsdiff_total}" \ 73 | bc -lq \ 74 | awk '{printf "%.2f\n", $0}')" 75 echo "${pct}% of a bsdiff-only payload" 76 77 local savings="$((bsdiff_total - best_total))" 78 echo "${savings} bytes saved by courgette" 79 80 local pct_savings="$(echo "100*${savings}/${bsdiff_total}" \ 81 | bc -lq \ 82 | awk '{printf "%.2f\n", $0}')" 83 echo "${pct_savings}% savings" 84 } 85 86 main "${@}" 87