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 |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 36 | -d DOWNLOAD_DIR directory to store downloaded sources in |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 37 | -E EMAIL_ADDR send email report |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 38 | -g GLOBALRES_DIR where to place the globalres file |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | -P GIT_REMOTE push results to a remote Git repository |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | -R DEST rsync reports to a remote destination |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | -w WORK_DIR work dir for this script |
| 42 | (default: GIT_TOP_DIR/build-perf-test) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 43 | -x create xml report (instead of json) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | EOF |
| 45 | } |
| 46 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | get_os_release_var () { |
| 48 | ( source /etc/os-release; eval echo '$'$1 ) |
| 49 | } |
| 50 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | |
| 52 | # Parse command line arguments |
| 53 | commitish="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | oe_build_perf_test_extra_opts=() |
| 55 | oe_git_archive_extra_opts=() |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 56 | while getopts "ha:c:C:d:E:g:P:R:w:x" opt; do |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | case $opt in |
| 58 | h) usage |
| 59 | exit 0 |
| 60 | ;; |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 61 | a) mkdir -p "$OPTARG" |
| 62 | archive_dir=`realpath -s "$OPTARG"` |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 63 | ;; |
| 64 | c) commitish=$OPTARG |
| 65 | ;; |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 66 | C) mkdir -p "$OPTARG" |
| 67 | results_repo=`realpath -s "$OPTARG"` |
| 68 | ;; |
| 69 | d) download_dir=`realpath -s "$OPTARG"` |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | ;; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 71 | E) email_to="$OPTARG" |
| 72 | ;; |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 73 | g) mkdir -p "$OPTARG" |
| 74 | globalres_dir=`realpath -s "$OPTARG"` |
| 75 | ;; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | P) oe_git_archive_extra_opts+=("--push" "$OPTARG") |
| 77 | ;; |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | R) rsync_dst="$OPTARG" |
| 79 | ;; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 80 | w) base_dir=`realpath -s "$OPTARG"` |
| 81 | ;; |
| 82 | x) oe_build_perf_test_extra_opts+=("--xml") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | ;; |
| 84 | *) usage |
| 85 | exit 1 |
| 86 | ;; |
| 87 | esac |
| 88 | done |
| 89 | |
| 90 | # Check positional args |
| 91 | shift "$((OPTIND - 1))" |
| 92 | if [ $# -ne 0 ]; then |
| 93 | echo "ERROR: No positional args are accepted." |
| 94 | usage |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 98 | if [ -n "$email_to" ]; then |
| 99 | if ! [ -x "$(command -v phantomjs)" ]; then |
| 100 | echo "ERROR: Sending email needs phantomjs." |
| 101 | exit 1 |
| 102 | fi |
| 103 | if ! [ -x "$(command -v optipng)" ]; then |
| 104 | echo "ERROR: Sending email needs optipng." |
| 105 | exit 1 |
| 106 | fi |
| 107 | fi |
| 108 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 109 | # Open a file descriptor for flock and acquire lock |
| 110 | LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock" |
| 111 | if ! exec 3> "$LOCK_FILE"; then |
| 112 | echo "ERROR: Unable to open lock file" |
| 113 | exit 1 |
| 114 | fi |
| 115 | if ! flock -n 3; then |
| 116 | echo "ERROR: Another instance of this script is running" |
| 117 | exit 1 |
| 118 | fi |
| 119 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 120 | echo "Running on `uname -n`" |
| 121 | if ! git_topdir=$(git rev-parse --show-toplevel); then |
| 122 | echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`" |
| 123 | exit 1 |
| 124 | fi |
| 125 | |
| 126 | cd "$git_topdir" |
| 127 | |
| 128 | if [ -n "$commitish" ]; then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 129 | echo "Running git fetch" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 130 | git fetch &> /dev/null |
| 131 | git checkout HEAD^0 &> /dev/null |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | |
| 133 | # Handle <branch>:<commit> format |
| 134 | if echo "$commitish" | grep -q ":"; then |
| 135 | commit=`echo "$commitish" | cut -d":" -f2` |
| 136 | branch=`echo "$commitish" | cut -d":" -f1` |
| 137 | else |
| 138 | commit="$commitish" |
| 139 | branch="$commitish" |
| 140 | fi |
| 141 | |
| 142 | echo "Checking out $commitish" |
| 143 | git branch -D $branch &> /dev/null |
| 144 | if ! git checkout -f $branch &> /dev/null; then |
| 145 | echo "ERROR: Git checkout failed" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | exit 1 |
| 147 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 148 | |
| 149 | # Check that the specified branch really contains the commit |
| 150 | commit_hash=`git rev-parse --revs-only $commit --` |
| 151 | if [ -z "$commit_hash" -o "`git merge-base $branch $commit`" != "$commit_hash" ]; then |
| 152 | echo "ERROR: branch $branch does not contain commit $commit" |
| 153 | exit 1 |
| 154 | fi |
| 155 | git reset --hard $commit > /dev/null |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | fi |
| 157 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 158 | # Determine name of the current branch |
| 159 | branch=`git symbolic-ref HEAD 2> /dev/null` |
| 160 | # Strip refs/heads/ |
| 161 | branch=${branch:11} |
| 162 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 163 | # Setup build environment |
| 164 | if [ -z "$base_dir" ]; then |
| 165 | base_dir="$git_topdir/build-perf-test" |
| 166 | fi |
| 167 | echo "Using working dir $base_dir" |
| 168 | |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 169 | if [ -z "$download_dir" ]; then |
| 170 | download_dir="$base_dir/downloads" |
| 171 | fi |
| 172 | if [ -z "$globalres_dir" ]; then |
| 173 | globalres_dir="$base_dir" |
| 174 | fi |
| 175 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 176 | timestamp=`date "+%Y%m%d%H%M%S"` |
| 177 | git_rev=$(git rev-parse --short HEAD) || exit 1 |
| 178 | build_dir="$base_dir/build-$git_rev-$timestamp" |
| 179 | results_dir="$base_dir/results-$git_rev-$timestamp" |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 180 | globalres_log="$globalres_dir/globalres.log" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 181 | machine="qemux86" |
| 182 | |
| 183 | mkdir -p "$base_dir" |
| 184 | source ./oe-init-build-env $build_dir >/dev/null || exit 1 |
| 185 | |
| 186 | # Additional config |
| 187 | auto_conf="$build_dir/conf/auto.conf" |
| 188 | echo "MACHINE = \"$machine\"" > "$auto_conf" |
| 189 | echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf" |
| 190 | echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf" |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame^] | 191 | echo "DL_DIR = \"$download_dir\"" >> "$auto_conf" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 192 | # Disabling network sanity check slightly reduces the variance of timing results |
| 193 | echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf" |
| 194 | # Possibility to define extra settings |
| 195 | if [ -f "$base_dir/auto.conf.extra" ]; then |
| 196 | cat "$base_dir/auto.conf.extra" >> "$auto_conf" |
| 197 | fi |
| 198 | |
| 199 | # Run actual test script |
| 200 | oe-build-perf-test --out-dir "$results_dir" \ |
| 201 | --globalres-file "$globalres_log" \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 202 | "${oe_build_perf_test_extra_opts[@]}" \ |
| 203 | --lock-file "$base_dir/oe-build-perf.lock" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 204 | |
| 205 | case $? in |
| 206 | 1) echo "ERROR: oe-build-perf-test script failed!" |
| 207 | exit 1 |
| 208 | ;; |
| 209 | 2) echo "NOTE: some tests failed!" |
| 210 | ;; |
| 211 | esac |
| 212 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 213 | # Commit results to git |
| 214 | if [ -n "$results_repo" ]; then |
| 215 | echo -e "\nArchiving results in $results_repo" |
| 216 | oe-git-archive \ |
| 217 | --git-dir "$results_repo" \ |
| 218 | --branch-name "{hostname}/{branch}/{machine}" \ |
| 219 | --tag-name "{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}" \ |
| 220 | --exclude "buildstats.json" \ |
| 221 | --notes "buildstats/{branch_name}" "$results_dir/buildstats.json" \ |
| 222 | "${oe_git_archive_extra_opts[@]}" \ |
| 223 | "$results_dir" |
| 224 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 225 | # Generate test reports |
| 226 | sanitized_branch=`echo $branch | tr / _` |
| 227 | report_txt=`hostname`_${sanitized_branch}_${machine}.txt |
| 228 | report_html=`hostname`_${sanitized_branch}_${machine}.html |
| 229 | echo -e "\nGenerating test report" |
| 230 | oe-build-perf-report -r "$results_repo" > $report_txt |
| 231 | oe-build-perf-report -r "$results_repo" --html > $report_html |
| 232 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | # Send email report |
| 234 | if [ -n "$email_to" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 235 | echo "Emailing test report" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 236 | os_name=`get_os_release_var PRETTY_NAME` |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 237 | "$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[@]}" |
| 238 | fi |
| 239 | |
| 240 | # Upload report files, unless we're on detached head |
| 241 | if [ -n "$rsync_dst" -a -n "$branch" ]; then |
| 242 | echo "Uploading test report" |
| 243 | rsync $report_txt $report_html $rsync_dst |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 244 | fi |
| 245 | fi |
| 246 | |
| 247 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 248 | echo -ne "\n\n-----------------\n" |
| 249 | echo "Global results file:" |
| 250 | echo -ne "\n" |
| 251 | |
| 252 | cat "$globalres_log" |
| 253 | |
| 254 | if [ -n "$archive_dir" ]; then |
| 255 | echo -ne "\n\n-----------------\n" |
| 256 | echo "Archiving results in $archive_dir" |
| 257 | mkdir -p "$archive_dir" |
| 258 | results_basename=`basename "$results_dir"` |
| 259 | results_dirname=`dirname "$results_dir"` |
| 260 | tar -czf "$archive_dir/`uname -n`-${results_basename}.tar.gz" -C "$results_dirname" "$results_basename" |
| 261 | fi |
| 262 | |
| 263 | rm -rf "$build_dir" |
| 264 | rm -rf "$results_dir" |
| 265 | |
| 266 | echo "DONE" |