bench-all 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env bash
  2. # Run all benchmarks for this repo, and save the results to the
  3. # benchmark repo, which should be cloned at ../linux-kernel-module-cheat-benchmarks.
  4. set -eu
  5. . common
  6. bench_build=false
  7. bench_buildroot_baseline=false
  8. bench_gem5_build=false
  9. bench_linux_boot=false
  10. default_arch=x86_64
  11. update_repo=true
  12. set -- ${cli_bench_all:-} "$@"
  13. while getopts Aa:Bbglu OPT; do
  14. case "$OPT" in
  15. A)
  16. bench_build=true
  17. bench_buildroot_baseline=true
  18. bench_gem5_build=true
  19. bench_linux_boot=true
  20. ;;
  21. a)
  22. default_arch="$OPTARG"
  23. ;;
  24. b)
  25. bench_build=true
  26. ;;
  27. B)
  28. bench_buildroot_baseline=true
  29. ;;
  30. g)
  31. bench_gem5_build=true
  32. ;;
  33. l)
  34. bench_linux_boot=true
  35. ;;
  36. u)
  37. update_repo=false
  38. ;;
  39. ?)
  40. exit 2
  41. ;;
  42. esac
  43. done
  44. shift "$(($OPTIND - 1))"
  45. comment="${1:-}"
  46. # Create output directory.
  47. sha="$(git log -1 --format="%H")"
  48. benchmark_repo="${root_dir}/../linux-kernel-module-cheat-regression"
  49. mkdir -p "$benchmark_repo"
  50. last_dir="$(ls "$benchmark_repo" | grep -E '^[0-9]' | tail -n 1)"
  51. if [ -n "$last_dir" ]; then
  52. seq_id="$(("$(echo "$last_dir" | sed -E 's/_.*//')" + 1))"
  53. else
  54. seq_id=0
  55. fi
  56. seq_id="$(printf '%0.4d' "$seq_id")"
  57. sha="$(git log -1 --format="%H")"
  58. dir_basename="${seq_id}_${sha}"
  59. new_dir="${benchmark_repo}/${dir_basename}"
  60. mkdir "$new_dir"
  61. if "$bench_build"; then
  62. arch="$default_arch"
  63. suffix=bench
  64. set_common_vars "$arch" false "$suffix"
  65. rm -rf "$out_arch_dir"
  66. ./build -a "$arch" -B 'BR2_CCACHE=n' -s "$suffix"
  67. cp "${build_dir}/build-time.log" "${new_dir}/build-time-${arch}.log"
  68. rm -rf "$out_arch_dir"
  69. fi
  70. if "$bench_buildroot_baseline"; then
  71. cd "${root_dir}/buildroot"
  72. git clean -xdf
  73. make "qemu_${default_arch}_defconfig"
  74. printf '
  75. BR2_CCACHE=y
  76. BR2_TARGET_ROOTFS_CPIO=y
  77. BR2_TARGET_ROOTFS_EXT2=n
  78. ' >>.config
  79. make olddefconfig
  80. make source
  81. time env -u LD_LIBRARY_PATH make BR2_JLEVEL="$(nproc)"
  82. cp output/build/build-time.log "${new_dir}/baseline-build-time-${default_arch}.log"
  83. wc -c output/images/* > "${new_dir}/baseline-image-size-${default_arch}.log"
  84. git clean -xdf
  85. fi
  86. if "$bench_gem5_build"; then
  87. arches='x86_64 arm'
  88. for arch in $arches; do
  89. set_common_vars "$arch"
  90. cd "${root_dir}/gem5/gem5"
  91. git clean -xdf
  92. cd "${root_dir}/gem5"
  93. results_file="${gem5_run_out_dir}/bench-build.txt"
  94. rm "$results_file"
  95. common_bench_cmd "timeout 900 ./build -a '$arch'" "$results_file"
  96. cp "$results_file" "${new_dir}/gem5-bench-build-${arch}.txt"
  97. cd "${root_dir}/gem5/gem5"
  98. git clean -xdf
  99. done
  100. fi
  101. if "$bench_linux_boot"; then
  102. cd "${root_dir}"
  103. ./build-all
  104. ./bench-boot
  105. cp "$common_bench_boot" "$new_dir"
  106. fi
  107. if "$update_repo"; then
  108. if [ -n "$comment" ]; then
  109. echo "$comment" > "${new_dir}/README.adoc"
  110. fi
  111. echo ""
  112. cd "$benchmark_repo"
  113. git add .
  114. git commit -m "$dir_basename"
  115. git push
  116. fi