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