analyze_stress_test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. # Copyright 2013 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Produce metrics analyzing the output of a stress test
  6. source "$(dirname ${0})/stress_test_common"
  7. set -e
  8. # Given a token, search for and compute the percentiles from logfile.
  9. compute_percentiles() {
  10. if [ ! -z "${1}" ]; then
  11. local pctls=".5 .9 1"
  12. local lines=$(count_result ${1})
  13. for p in $pctls; do
  14. local count="$(echo "${lines} * $p" | bc -lq | cut -d. -f1)"
  15. echo -n $(cat ${log} \
  16. | grep ${1} \
  17. | cut -d' ' -f2 \
  18. | sort -n \
  19. | head -n$count \
  20. | tail -n1)
  21. echo -n "s "
  22. done
  23. fi
  24. }
  25. main() {
  26. if [ $# -lt 1 ]; then
  27. cat <<EOF
  28. USAGE: $(basename ${0}) logfile
  29. Analyze the logfile of a stress test and produce metrics.
  30. EOF
  31. exit 1
  32. fi
  33. local log="${1}"
  34. if [ ! -f "${log}" ]; then
  35. error "\"${log}\" not found"
  36. exit 1
  37. fi
  38. cat <<EOF
  39. $(count_result "PASS_COURGETTE") successful courgette patches
  40. $(count_result "FAIL_COURGETTE") failed courgette patches
  41. $(count_result "FAIL_DISASSEMBLE") failed to disassemble/assemble
  42. $(count_result "PASS_BSDIFF") succesful bsdiff patches
  43. $(count_result "FAIL_BSDIFF") failed bsdiff patches
  44. $(count_result "BEST_COURGETTE") patch(es) where courgette is smaller (bz2)
  45. $(count_result "BEST_BSDIFF") patch(es) where bsdiff is smaller (bz2)
  46. $(count_result "BEST_TIE") patch(es) where both are the same size (bz2)
  47. $(count_result "XZBEST_COURGETTE") patch(es) where courgette (xz) is smaller
  48. $(count_result "XZBEST_BSDIFF") patch(es) where bsdiff is smaller (xz)
  49. $(count_result "XZBEST_TIE") patch(es) where both are the same size (xz)
  50. EOF
  51. # Log file has the format "^SIZE courgette=... bsdiff=..."
  52. local courgette_total="$(cat "${log}" \
  53. | grep "^SIZE " \
  54. | cut -d' ' -f2 \
  55. | awk -F= 'BEGIN{sum=0} {sum += $2} END{print sum}')"
  56. echo "${courgette_total} bytes for a courgette payload (bz2)"
  57. local courgette_total_xz="$(cat "${log}" \
  58. | grep "^SIZE " \
  59. | cut -d' ' -f4 \
  60. | awk -F= 'BEGIN{sum=0} {sum += $2} END{print sum}')"
  61. echo "${courgette_total_xz} bytes for a courgette payload (xz)"
  62. local bsdiff_total="$(cat "${log}" \
  63. | grep "^SIZE " \
  64. | cut -d' ' -f3 \
  65. | awk -F= 'BEGIN{sum=0} {sum += $2} END{print sum}')"
  66. 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 (bz2)"
  71. local best_total_xz="$(cat "${log}" \
  72. | grep "^XZBEST_" \
  73. | awk 'BEGIN{sum=0} {sum += $2} END{print sum}')"
  74. echo "${best_total_xz} bytes for a best-choice payload (xz)"
  75. local pct="$(echo "100*${best_total}/${bsdiff_total}" \
  76. | bc -lq \
  77. | awk '{printf "%.2f\n", $0}')"
  78. echo "${pct}% of a bsdiff-only payload (bz2)"
  79. local pct="$(echo "100*${best_total_xz}/${bsdiff_total}" \
  80. | bc -lq \
  81. | awk '{printf "%.2f\n", $0}')"
  82. echo "${pct}% of a bsdiff-only payload (xz)"
  83. local savings="$((bsdiff_total - best_total))"
  84. echo "${savings} bytes saved by courgette (bz2)"
  85. local savings_xz="$((bsdiff_total - best_total_xz))"
  86. echo "${savings} bytes saved by courgette (xz)"
  87. local pct_savings="$(echo "100*${savings}/${bsdiff_total}" \
  88. | bc -lq \
  89. | awk '{printf "%.2f\n", $0}')"
  90. echo "${pct_savings}% savings (bz2)"
  91. local pct_savings="$(echo "100*${savings_xz}/${bsdiff_total}" \
  92. | bc -lq \
  93. | awk '{printf "%.2f\n", $0}')"
  94. echo "${pct_savings}% savings (xz)"
  95. echo "$(compute_percentiles "TIME_GEN")to generate a patch (50th 90th 100th)"
  96. echo "$(compute_percentiles "TIME_APPLY")to apply a patch (50th 90th 100th)"
  97. echo "$(compute_percentiles "TIME_BSDIFF")for bsdiff (50th 90th 100th)"
  98. echo "$(compute_percentiles "TIME_BSPATCH")for bspatch (50th 90th 100th)"
  99. }
  100. main "${@}"