build-perf-test-wrapper.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/bin/bash
  2. #
  3. # Build performance test script wrapper
  4. #
  5. # Copyright (c) 2016, Intel Corporation.
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. # This script is a simple wrapper around the actual build performance tester
  10. # script. This script initializes the build environment, runs
  11. # oe-build-perf-test and archives the results.
  12. script=`basename $0`
  13. script_dir=$(realpath $(dirname $0))
  14. archive_dir=~/perf-results/archives
  15. usage () {
  16. cat << EOF
  17. Usage: $script [-h] [-c COMMITISH] [-C GIT_REPO]
  18. Optional arguments:
  19. -h show this help and exit.
  20. -a ARCHIVE_DIR archive results tarball here, give an empty string to
  21. disable tarball archiving (default: $archive_dir)
  22. -c COMMITISH test (checkout) this commit, <branch>:<commit> can be
  23. specified to test specific commit of certain branch
  24. -C GIT_REPO commit results into Git
  25. -d DOWNLOAD_DIR directory to store downloaded sources in
  26. -E EMAIL_ADDR send email report
  27. -g GLOBALRES_DIR where to place the globalres file
  28. -P GIT_REMOTE push results to a remote Git repository
  29. -R DEST rsync reports to a remote destination
  30. -w WORK_DIR work dir for this script
  31. (default: GIT_TOP_DIR/build-perf-test)
  32. -x create xml report (instead of json)
  33. EOF
  34. }
  35. get_os_release_var () {
  36. ( source /etc/os-release; eval echo '$'$1 )
  37. }
  38. # Parse command line arguments
  39. commitish=""
  40. oe_build_perf_test_extra_opts=()
  41. oe_git_archive_extra_opts=()
  42. while getopts "ha:c:C:d:E:g:P:R:w:x" opt; do
  43. case $opt in
  44. h) usage
  45. exit 0
  46. ;;
  47. a) mkdir -p "$OPTARG"
  48. archive_dir=`realpath -s "$OPTARG"`
  49. ;;
  50. c) commitish=$OPTARG
  51. ;;
  52. C) mkdir -p "$OPTARG"
  53. results_repo=`realpath -s "$OPTARG"`
  54. ;;
  55. d) download_dir=`realpath -s "$OPTARG"`
  56. ;;
  57. E) email_to="$OPTARG"
  58. ;;
  59. g) mkdir -p "$OPTARG"
  60. globalres_dir=`realpath -s "$OPTARG"`
  61. ;;
  62. P) oe_git_archive_extra_opts+=("--push" "$OPTARG")
  63. ;;
  64. R) rsync_dst="$OPTARG"
  65. ;;
  66. w) base_dir=`realpath -s "$OPTARG"`
  67. ;;
  68. x) oe_build_perf_test_extra_opts+=("--xml")
  69. ;;
  70. *) usage
  71. exit 1
  72. ;;
  73. esac
  74. done
  75. # Check positional args
  76. shift "$((OPTIND - 1))"
  77. if [ $# -ne 0 ]; then
  78. echo "ERROR: No positional args are accepted."
  79. usage
  80. exit 1
  81. fi
  82. # Open a file descriptor for flock and acquire lock
  83. LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock"
  84. if ! exec 3> "$LOCK_FILE"; then
  85. echo "ERROR: Unable to open loemack file"
  86. exit 1
  87. fi
  88. if ! flock -n 3; then
  89. echo "ERROR: Another instance of this script is running"
  90. exit 1
  91. fi
  92. echo "Running on `uname -n`"
  93. if ! git_topdir=$(git rev-parse --show-toplevel); then
  94. echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`"
  95. exit 1
  96. fi
  97. cd "$git_topdir"
  98. if [ -n "$commitish" ]; then
  99. echo "Running git fetch"
  100. git fetch &> /dev/null
  101. git checkout HEAD^0 &> /dev/null
  102. # Handle <branch>:<commit> format
  103. if echo "$commitish" | grep -q ":"; then
  104. commit=`echo "$commitish" | cut -d":" -f2`
  105. branch=`echo "$commitish" | cut -d":" -f1`
  106. else
  107. commit="$commitish"
  108. branch="$commitish"
  109. fi
  110. echo "Checking out $commitish"
  111. git branch -D $branch &> /dev/null
  112. if ! git checkout -f $branch &> /dev/null; then
  113. echo "ERROR: Git checkout failed"
  114. exit 1
  115. fi
  116. # Check that the specified branch really contains the commit
  117. commit_hash=`git rev-parse --revs-only $commit --`
  118. if [ -z "$commit_hash" -o "`git merge-base $branch $commit`" != "$commit_hash" ]; then
  119. echo "ERROR: branch $branch does not contain commit $commit"
  120. exit 1
  121. fi
  122. git reset --hard $commit > /dev/null
  123. fi
  124. # Determine name of the current branch
  125. branch=`git symbolic-ref HEAD 2> /dev/null`
  126. # Strip refs/heads/
  127. branch=${branch:11}
  128. # Setup build environment
  129. if [ -z "$base_dir" ]; then
  130. base_dir="$git_topdir/build-perf-test"
  131. fi
  132. echo "Using working dir $base_dir"
  133. if [ -z "$download_dir" ]; then
  134. download_dir="$base_dir/downloads"
  135. fi
  136. if [ -z "$globalres_dir" ]; then
  137. globalres_dir="$base_dir"
  138. fi
  139. timestamp=`date "+%Y%m%d%H%M%S"`
  140. git_rev=$(git rev-parse --short HEAD) || exit 1
  141. build_dir="$base_dir/build-$git_rev-$timestamp"
  142. results_dir="$base_dir/results-$git_rev-$timestamp"
  143. globalres_log="$globalres_dir/globalres.log"
  144. machine="qemux86"
  145. mkdir -p "$base_dir"
  146. source ./oe-init-build-env $build_dir >/dev/null || exit 1
  147. # Additional config
  148. auto_conf="$build_dir/conf/auto.conf"
  149. echo "MACHINE = \"$machine\"" > "$auto_conf"
  150. echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf"
  151. echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf"
  152. echo "DL_DIR = \"$download_dir\"" >> "$auto_conf"
  153. # Disabling network sanity check slightly reduces the variance of timing results
  154. echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf"
  155. # Possibility to define extra settings
  156. if [ -f "$base_dir/auto.conf.extra" ]; then
  157. cat "$base_dir/auto.conf.extra" >> "$auto_conf"
  158. fi
  159. # Run actual test script
  160. oe-build-perf-test --out-dir "$results_dir" \
  161. --globalres-file "$globalres_log" \
  162. "${oe_build_perf_test_extra_opts[@]}" \
  163. --lock-file "$base_dir/oe-build-perf.lock"
  164. case $? in
  165. 1) echo "ERROR: oe-build-perf-test script failed!"
  166. exit 1
  167. ;;
  168. 2) echo "NOTE: some tests failed!"
  169. ;;
  170. esac
  171. # Commit results to git
  172. if [ -n "$results_repo" ]; then
  173. echo -e "\nArchiving results in $results_repo"
  174. oe-git-archive \
  175. --git-dir "$results_repo" \
  176. --branch-name "{hostname}/{branch}/{machine}" \
  177. --tag-name "{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}" \
  178. --exclude "buildstats.json" \
  179. --notes "buildstats/{branch_name}" "$results_dir/buildstats.json" \
  180. "${oe_git_archive_extra_opts[@]}" \
  181. "$results_dir"
  182. # Generate test reports
  183. sanitized_branch=`echo $branch | tr / _`
  184. report_txt=`hostname`_${sanitized_branch}_${machine}.txt
  185. report_html=`hostname`_${sanitized_branch}_${machine}.html
  186. echo -e "\nGenerating test report"
  187. oe-build-perf-report -r "$results_repo" > $report_txt
  188. oe-build-perf-report -r "$results_repo" --html > $report_html
  189. # Send email report
  190. if [ -n "$email_to" ]; then
  191. echo "Emailing test report"
  192. os_name=`get_os_release_var PRETTY_NAME`
  193. "$script_dir"/oe-build-perf-report-email.py --to "$email_to" --subject "Build Perf Test Report for $os_name" --text $report_txt "${OE_BUILD_PERF_REPORT_EMAIL_EXTRA_ARGS[@]}"
  194. fi
  195. # Upload report files, unless we're on detached head
  196. if [ -n "$rsync_dst" -a -n "$branch" ]; then
  197. echo "Uploading test report"
  198. rsync $report_txt $report_html $rsync_dst
  199. fi
  200. fi
  201. echo -ne "\n\n-----------------\n"
  202. echo "Global results file:"
  203. echo -ne "\n"
  204. cat "$globalres_log"
  205. if [ -n "$archive_dir" ]; then
  206. echo -ne "\n\n-----------------\n"
  207. echo "Archiving results in $archive_dir"
  208. mkdir -p "$archive_dir"
  209. results_basename=`basename "$results_dir"`
  210. results_dirname=`dirname "$results_dir"`
  211. tar -czf "$archive_dir/`uname -n`-${results_basename}.tar.gz" -C "$results_dirname" "$results_basename"
  212. fi
  213. rm -rf "$build_dir"
  214. rm -rf "$results_dir"
  215. echo "DONE"