Apps Developer Tools: Website/webstore link is hidden properly to avoid glitch when...
[chromium-blink-merge.git] / courgette / analyze_stress_test
blob6aff656e887f6754dd49a2707e2aeb70ede3b28f
1 #!/bin/bash
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.
7 # Produce metrics analyzing the output of a stress test
9 set -e
11 error() {
12 echo "error: ${@}" >&2
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
25 main() {
26 if [ $# -lt 1 ]; then
27 cat <<EOF
29 USAGE: $(basename ${0}) logfile
31 Analyze the logfile of a stress test and produce metrics.
33 EOF
34 exit 1
37 local log="${1}"
38 if [ ! -f "${log}" ]; then
39 error "\"${log}\" not found"
40 exit 1
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
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"
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"
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"
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"
77 local savings="$((bsdiff_total - best_total))"
78 echo "${savings} bytes saved by courgette"
80 local pct_savings="$(echo "100*${savings}/${bsdiff_total}" \
81 | bc -lq \
82 | awk '{printf "%.2f\n", $0}')"
83 echo "${pct_savings}% savings"
86 main "${@}"