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 13script=`basename $0` 14script_dir=$(realpath $(dirname $0)) 15archive_dir=~/perf-results/archives 16 17usage () { 18cat << EOF 19Usage: $script [-h] [-c COMMITISH] [-C GIT_REPO] 20 21Optional 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) 36EOF 37} 38 39get_os_release_var () { 40 ( source /etc/os-release; eval echo '$'$1 ) 41} 42 43 44# Parse command line arguments 45commitish="" 46oe_build_perf_test_extra_opts=() 47oe_git_archive_extra_opts=() 48while 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 80done 81 82# Check positional args 83shift "$((OPTIND - 1))" 84if [ $# -ne 0 ]; then 85 echo "ERROR: No positional args are accepted." 86 usage 87 exit 1 88fi 89 90# Open a file descriptor for flock and acquire lock 91LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock" 92if ! exec 3> "$LOCK_FILE"; then 93 echo "ERROR: Unable to open loemack file" 94 exit 1 95fi 96if ! flock -n 3; then 97 echo "ERROR: Another instance of this script is running" 98 exit 1 99fi 100 101echo "Running on `uname -n`" 102if ! 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 105fi 106 107cd "$git_topdir" 108 109if [ -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 137fi 138 139# Determine name of the current branch 140branch=`git symbolic-ref HEAD 2> /dev/null` 141# Strip refs/heads/ 142branch=${branch:11} 143 144# Setup build environment 145if [ -z "$base_dir" ]; then 146 base_dir="$git_topdir/build-perf-test" 147fi 148echo "Using working dir $base_dir" 149 150if [ -z "$download_dir" ]; then 151 download_dir="$base_dir/downloads" 152fi 153if [ -z "$globalres_dir" ]; then 154 globalres_dir="$base_dir" 155fi 156 157timestamp=`date "+%Y%m%d%H%M%S"` 158git_rev=$(git rev-parse --short HEAD) || exit 1 159build_dir="$base_dir/build-$git_rev-$timestamp" 160results_dir="$base_dir/results-$git_rev-$timestamp" 161globalres_log="$globalres_dir/globalres.log" 162machine="qemux86" 163 164mkdir -p "$base_dir" 165source ./oe-init-build-env $build_dir >/dev/null || exit 1 166 167# Additional config 168auto_conf="$build_dir/conf/auto.conf" 169echo "MACHINE = \"$machine\"" > "$auto_conf" 170echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf" 171echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf" 172echo "DL_DIR = \"$download_dir\"" >> "$auto_conf" 173# Disabling network sanity check slightly reduces the variance of timing results 174echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf" 175# Possibility to define extra settings 176if [ -f "$base_dir/auto.conf.extra" ]; then 177 cat "$base_dir/auto.conf.extra" >> "$auto_conf" 178fi 179 180# Run actual test script 181oe-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 186case $? in 187 1) echo "ERROR: oe-build-perf-test script failed!" 188 exit 1 189 ;; 190 2) echo "NOTE: some tests failed!" 191 ;; 192esac 193 194# Commit results to git 195if [ -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 226fi 227 228 229echo -ne "\n\n-----------------\n" 230echo "Global results file:" 231echo -ne "\n" 232 233cat "$globalres_log" 234 235if [ -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" 242fi 243 244rm -rf "$build_dir" 245rm -rf "$results_dir" 246 247echo "DONE" 248