build-perf-test-wrapper.sh 7.3 KB

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