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