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