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` |
| 22 | archive_dir=~/perf-results/archives |
| 23 | |
| 24 | usage () { |
| 25 | cat << EOF |
| 26 | Usage: $script [-h] [-c COMMITISH] [-C GIT_REPO] |
| 27 | |
| 28 | Optional arguments: |
| 29 | -h show this help and exit. |
| 30 | -a ARCHIVE_DIR archive results tarball here, give an empty string to |
| 31 | disable tarball archiving (default: $archive_dir) |
| 32 | -c COMMITISH test (checkout) this commit |
| 33 | -C GIT_REPO commit results into Git |
| 34 | -w WORK_DIR work dir for this script |
| 35 | (default: GIT_TOP_DIR/build-perf-test) |
| 36 | EOF |
| 37 | } |
| 38 | |
| 39 | |
| 40 | # Parse command line arguments |
| 41 | commitish="" |
| 42 | while getopts "ha:c:C:w:" opt; do |
| 43 | case $opt in |
| 44 | h) usage |
| 45 | exit 0 |
| 46 | ;; |
| 47 | a) archive_dir=`realpath "$OPTARG"` |
| 48 | ;; |
| 49 | c) commitish=$OPTARG |
| 50 | ;; |
| 51 | C) results_repo=`realpath "$OPTARG"` |
| 52 | commit_results=("--commit-results" "$results_repo") |
| 53 | ;; |
| 54 | w) base_dir=`realpath "$OPTARG"` |
| 55 | ;; |
| 56 | *) usage |
| 57 | exit 1 |
| 58 | ;; |
| 59 | esac |
| 60 | done |
| 61 | |
| 62 | # Check positional args |
| 63 | shift "$((OPTIND - 1))" |
| 64 | if [ $# -ne 0 ]; then |
| 65 | echo "ERROR: No positional args are accepted." |
| 66 | usage |
| 67 | exit 1 |
| 68 | fi |
| 69 | |
| 70 | echo "Running on `uname -n`" |
| 71 | if ! git_topdir=$(git rev-parse --show-toplevel); then |
| 72 | echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`" |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | cd "$git_topdir" |
| 77 | |
| 78 | if [ -n "$commitish" ]; then |
| 79 | # Checkout correct revision |
| 80 | echo "Checking out $commitish" |
| 81 | git fetch &> /dev/null |
| 82 | git checkout HEAD^0 &> /dev/null |
| 83 | git branch -D $commitish &> /dev/null |
| 84 | if ! git checkout -f $commitish &> /dev/null; then |
| 85 | echo "Git checkout failed" |
| 86 | exit 1 |
| 87 | fi |
| 88 | fi |
| 89 | |
| 90 | # Setup build environment |
| 91 | if [ -z "$base_dir" ]; then |
| 92 | base_dir="$git_topdir/build-perf-test" |
| 93 | fi |
| 94 | echo "Using working dir $base_dir" |
| 95 | |
| 96 | timestamp=`date "+%Y%m%d%H%M%S"` |
| 97 | git_rev=$(git rev-parse --short HEAD) || exit 1 |
| 98 | build_dir="$base_dir/build-$git_rev-$timestamp" |
| 99 | results_dir="$base_dir/results-$git_rev-$timestamp" |
| 100 | globalres_log="$base_dir/globalres.log" |
| 101 | machine="qemux86" |
| 102 | |
| 103 | mkdir -p "$base_dir" |
| 104 | source ./oe-init-build-env $build_dir >/dev/null || exit 1 |
| 105 | |
| 106 | # Additional config |
| 107 | auto_conf="$build_dir/conf/auto.conf" |
| 108 | echo "MACHINE = \"$machine\"" > "$auto_conf" |
| 109 | echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf" |
| 110 | echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf" |
| 111 | echo "DL_DIR = \"$base_dir/downloads\"" >> "$auto_conf" |
| 112 | # Disabling network sanity check slightly reduces the variance of timing results |
| 113 | echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf" |
| 114 | # Possibility to define extra settings |
| 115 | if [ -f "$base_dir/auto.conf.extra" ]; then |
| 116 | cat "$base_dir/auto.conf.extra" >> "$auto_conf" |
| 117 | fi |
| 118 | |
| 119 | # Run actual test script |
| 120 | oe-build-perf-test --out-dir "$results_dir" \ |
| 121 | --globalres-file "$globalres_log" \ |
| 122 | --lock-file "$base_dir/oe-build-perf.lock" \ |
| 123 | "${commit_results[@]}" \ |
| 124 | --commit-results-branch "{tester_host}/{git_branch}/$machine" \ |
| 125 | --commit-results-tag "{tester_host}/{git_branch}/$machine/{git_commit_count}-g{git_commit}/{tag_num}" |
| 126 | |
| 127 | case $? in |
| 128 | 1) echo "ERROR: oe-build-perf-test script failed!" |
| 129 | exit 1 |
| 130 | ;; |
| 131 | 2) echo "NOTE: some tests failed!" |
| 132 | ;; |
| 133 | esac |
| 134 | |
| 135 | echo -ne "\n\n-----------------\n" |
| 136 | echo "Global results file:" |
| 137 | echo -ne "\n" |
| 138 | |
| 139 | cat "$globalres_log" |
| 140 | |
| 141 | if [ -n "$archive_dir" ]; then |
| 142 | echo -ne "\n\n-----------------\n" |
| 143 | echo "Archiving results in $archive_dir" |
| 144 | mkdir -p "$archive_dir" |
| 145 | results_basename=`basename "$results_dir"` |
| 146 | results_dirname=`dirname "$results_dir"` |
| 147 | tar -czf "$archive_dir/`uname -n`-${results_basename}.tar.gz" -C "$results_dirname" "$results_basename" |
| 148 | fi |
| 149 | |
| 150 | rm -rf "$build_dir" |
| 151 | rm -rf "$results_dir" |
| 152 | |
| 153 | echo "DONE" |