diff options
Diffstat (limited to 'scripts/contrib/build-perf-test-wrapper.sh')
| -rwxr-xr-x | scripts/contrib/build-perf-test-wrapper.sh | 247 |
1 files changed, 0 insertions, 247 deletions
diff --git a/scripts/contrib/build-perf-test-wrapper.sh b/scripts/contrib/build-perf-test-wrapper.sh deleted file mode 100755 index 0a85e6e708..0000000000 --- a/scripts/contrib/build-perf-test-wrapper.sh +++ /dev/null | |||
| @@ -1,247 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # | ||
| 3 | # Build performance test script wrapper | ||
| 4 | # | ||
| 5 | # Copyright (c) 2016, Intel Corporation. | ||
| 6 | # | ||
| 7 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 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` | ||
| 14 | script_dir=$(realpath $(dirname $0)) | ||
| 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) | ||
| 25 | -c COMMITISH test (checkout) this commit, <branch>:<commit> can be | ||
| 26 | specified to test specific commit of certain branch | ||
| 27 | -C GIT_REPO commit results into Git | ||
| 28 | -d DOWNLOAD_DIR directory to store downloaded sources in | ||
| 29 | -E EMAIL_ADDR send email report | ||
| 30 | -g GLOBALRES_DIR where to place the globalres file | ||
| 31 | -P GIT_REMOTE push results to a remote Git repository | ||
| 32 | -R DEST rsync reports to a remote destination | ||
| 33 | -w WORK_DIR work dir for this script | ||
| 34 | (default: GIT_TOP_DIR/build-perf-test) | ||
| 35 | -x create xml report (instead of json) | ||
| 36 | EOF | ||
| 37 | } | ||
| 38 | |||
| 39 | get_os_release_var () { | ||
| 40 | ( source /etc/os-release; eval echo '$'$1 ) | ||
| 41 | } | ||
| 42 | |||
| 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:d:E:g:P:R:w:x" opt; do | ||
| 49 | case $opt in | ||
| 50 | h) usage | ||
| 51 | exit 0 | ||
| 52 | ;; | ||
| 53 | a) mkdir -p "$OPTARG" | ||
| 54 | archive_dir=`realpath -s "$OPTARG"` | ||
| 55 | ;; | ||
| 56 | c) commitish=$OPTARG | ||
| 57 | ;; | ||
| 58 | C) mkdir -p "$OPTARG" | ||
| 59 | results_repo=`realpath -s "$OPTARG"` | ||
| 60 | ;; | ||
| 61 | d) download_dir=`realpath -s "$OPTARG"` | ||
| 62 | ;; | ||
| 63 | E) email_to="$OPTARG" | ||
| 64 | ;; | ||
| 65 | g) mkdir -p "$OPTARG" | ||
| 66 | globalres_dir=`realpath -s "$OPTARG"` | ||
| 67 | ;; | ||
| 68 | P) oe_git_archive_extra_opts+=("--push" "$OPTARG") | ||
| 69 | ;; | ||
| 70 | R) rsync_dst="$OPTARG" | ||
| 71 | ;; | ||
| 72 | w) base_dir=`realpath -s "$OPTARG"` | ||
| 73 | ;; | ||
| 74 | x) oe_build_perf_test_extra_opts+=("--xml") | ||
| 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 | |||
| 90 | # Open a file descriptor for flock and acquire lock | ||
| 91 | LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock" | ||
| 92 | if ! exec 3> "$LOCK_FILE"; then | ||
| 93 | echo "ERROR: Unable to open loemack file" | ||
| 94 | exit 1 | ||
| 95 | fi | ||
| 96 | if ! flock -n 3; then | ||
| 97 | echo "ERROR: Another instance of this script is running" | ||
| 98 | exit 1 | ||
| 99 | fi | ||
| 100 | |||
| 101 | echo "Running on `uname -n`" | ||
| 102 | if ! git_topdir=$(git rev-parse --show-toplevel); then | ||
| 103 | echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`" | ||
| 104 | exit 1 | ||
| 105 | fi | ||
| 106 | |||
| 107 | cd "$git_topdir" | ||
| 108 | |||
| 109 | if [ -n "$commitish" ]; then | ||
| 110 | echo "Running git fetch" | ||
| 111 | git fetch &> /dev/null | ||
| 112 | git checkout HEAD^0 &> /dev/null | ||
| 113 | |||
| 114 | # Handle <branch>:<commit> format | ||
| 115 | if echo "$commitish" | grep -q ":"; then | ||
| 116 | commit=`echo "$commitish" | cut -d":" -f2` | ||
| 117 | branch=`echo "$commitish" | cut -d":" -f1` | ||
| 118 | else | ||
| 119 | commit="$commitish" | ||
| 120 | branch="$commitish" | ||
| 121 | fi | ||
| 122 | |||
| 123 | echo "Checking out $commitish" | ||
| 124 | git branch -D $branch &> /dev/null | ||
| 125 | if ! git checkout -f $branch &> /dev/null; then | ||
| 126 | echo "ERROR: Git checkout failed" | ||
| 127 | exit 1 | ||
| 128 | fi | ||
| 129 | |||
| 130 | # Check that the specified branch really contains the commit | ||
| 131 | commit_hash=`git rev-parse --revs-only $commit --` | ||
| 132 | if [ -z "$commit_hash" -o "`git merge-base $branch $commit`" != "$commit_hash" ]; then | ||
| 133 | echo "ERROR: branch $branch does not contain commit $commit" | ||
| 134 | exit 1 | ||
| 135 | fi | ||
| 136 | git reset --hard $commit > /dev/null | ||
| 137 | fi | ||
| 138 | |||
| 139 | # Determine name of the current branch | ||
| 140 | branch=`git symbolic-ref HEAD 2> /dev/null` | ||
| 141 | # Strip refs/heads/ | ||
| 142 | branch=${branch:11} | ||
| 143 | |||
| 144 | # Setup build environment | ||
| 145 | if [ -z "$base_dir" ]; then | ||
| 146 | base_dir="$git_topdir/build-perf-test" | ||
| 147 | fi | ||
| 148 | echo "Using working dir $base_dir" | ||
| 149 | |||
| 150 | if [ -z "$download_dir" ]; then | ||
| 151 | download_dir="$base_dir/downloads" | ||
| 152 | fi | ||
| 153 | if [ -z "$globalres_dir" ]; then | ||
| 154 | globalres_dir="$base_dir" | ||
| 155 | fi | ||
| 156 | |||
| 157 | timestamp=`date "+%Y%m%d%H%M%S"` | ||
| 158 | git_rev=$(git rev-parse --short HEAD) || exit 1 | ||
| 159 | build_dir="$base_dir/build-$git_rev-$timestamp" | ||
| 160 | results_dir="$base_dir/results-$git_rev-$timestamp" | ||
| 161 | globalres_log="$globalres_dir/globalres.log" | ||
| 162 | machine="qemux86" | ||
| 163 | |||
| 164 | mkdir -p "$base_dir" | ||
| 165 | source ./oe-init-build-env $build_dir >/dev/null || exit 1 | ||
| 166 | |||
| 167 | # Additional config | ||
| 168 | auto_conf="$build_dir/conf/auto.conf" | ||
| 169 | echo "MACHINE = \"$machine\"" > "$auto_conf" | ||
| 170 | echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf" | ||
| 171 | echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf" | ||
| 172 | echo "DL_DIR = \"$download_dir\"" >> "$auto_conf" | ||
| 173 | # Disabling network sanity check slightly reduces the variance of timing results | ||
| 174 | echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf" | ||
| 175 | # Possibility to define extra settings | ||
| 176 | if [ -f "$base_dir/auto.conf.extra" ]; then | ||
| 177 | cat "$base_dir/auto.conf.extra" >> "$auto_conf" | ||
| 178 | fi | ||
| 179 | |||
| 180 | # Run actual test script | ||
| 181 | oe-build-perf-test --out-dir "$results_dir" \ | ||
| 182 | --globalres-file "$globalres_log" \ | ||
| 183 | "${oe_build_perf_test_extra_opts[@]}" \ | ||
| 184 | --lock-file "$base_dir/oe-build-perf.lock" | ||
| 185 | |||
| 186 | case $? in | ||
| 187 | 1) echo "ERROR: oe-build-perf-test script failed!" | ||
| 188 | exit 1 | ||
| 189 | ;; | ||
| 190 | 2) echo "NOTE: some tests failed!" | ||
| 191 | ;; | ||
| 192 | esac | ||
| 193 | |||
| 194 | # Commit results to git | ||
| 195 | if [ -n "$results_repo" ]; then | ||
| 196 | echo -e "\nArchiving results in $results_repo" | ||
| 197 | oe-git-archive \ | ||
| 198 | --git-dir "$results_repo" \ | ||
| 199 | --branch-name "{hostname}/{branch}/{machine}" \ | ||
| 200 | --tag-name "{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}" \ | ||
| 201 | --exclude "buildstats.json" \ | ||
| 202 | --notes "buildstats/{branch_name}" "$results_dir/buildstats.json" \ | ||
| 203 | "${oe_git_archive_extra_opts[@]}" \ | ||
| 204 | "$results_dir" | ||
| 205 | |||
| 206 | # Generate test reports | ||
| 207 | sanitized_branch=`echo $branch | tr / _` | ||
| 208 | report_txt=`hostname`_${sanitized_branch}_${machine}.txt | ||
| 209 | report_html=`hostname`_${sanitized_branch}_${machine}.html | ||
| 210 | echo -e "\nGenerating test report" | ||
| 211 | oe-build-perf-report -r "$results_repo" > $report_txt | ||
| 212 | oe-build-perf-report -r "$results_repo" --html > $report_html | ||
| 213 | |||
| 214 | # Send email report | ||
| 215 | if [ -n "$email_to" ]; then | ||
| 216 | echo "Emailing test report" | ||
| 217 | os_name=`get_os_release_var PRETTY_NAME` | ||
| 218 | "$script_dir"/oe-build-perf-report-email.py --to "$email_to" --subject "Build Perf Test Report for $os_name" --text $report_txt "${OE_BUILD_PERF_REPORT_EMAIL_EXTRA_ARGS[@]}" | ||
| 219 | fi | ||
| 220 | |||
| 221 | # Upload report files, unless we're on detached head | ||
| 222 | if [ -n "$rsync_dst" -a -n "$branch" ]; then | ||
| 223 | echo "Uploading test report" | ||
| 224 | rsync $report_txt $report_html $rsync_dst | ||
| 225 | fi | ||
| 226 | fi | ||
| 227 | |||
| 228 | |||
| 229 | echo -ne "\n\n-----------------\n" | ||
| 230 | echo "Global results file:" | ||
| 231 | echo -ne "\n" | ||
| 232 | |||
| 233 | cat "$globalres_log" | ||
| 234 | |||
| 235 | if [ -n "$archive_dir" ]; then | ||
| 236 | echo -ne "\n\n-----------------\n" | ||
| 237 | echo "Archiving results in $archive_dir" | ||
| 238 | mkdir -p "$archive_dir" | ||
| 239 | results_basename=`basename "$results_dir"` | ||
| 240 | results_dirname=`dirname "$results_dir"` | ||
| 241 | tar -czf "$archive_dir/`uname -n`-${results_basename}.tar.gz" -C "$results_dirname" "$results_basename" | ||
| 242 | fi | ||
| 243 | |||
| 244 | rm -rf "$build_dir" | ||
| 245 | rm -rf "$results_dir" | ||
| 246 | |||
| 247 | echo "DONE" | ||
