blob: 0a85e6e7081af08184615563c366a0147cf87ef6 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/bin/bash
2#
3# Build performance test script wrapper
4#
5# Copyright (c) 2016, Intel Corporation.
6#
Brad Bishopc342db32019-05-15 21:57:59 -04007# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008#
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`
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014script_dir=$(realpath $(dirname $0))
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015archive_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)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 -c COMMITISH test (checkout) this commit, <branch>:<commit> can be
26 specified to test specific commit of certain branch
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027 -C GIT_REPO commit results into Git
Andrew Geissler99467da2019-02-25 18:54:23 -060028 -d DOWNLOAD_DIR directory to store downloaded sources in
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 -E EMAIL_ADDR send email report
Andrew Geissler99467da2019-02-25 18:54:23 -060030 -g GLOBALRES_DIR where to place the globalres file
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 -P GIT_REMOTE push results to a remote Git repository
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 -R DEST rsync reports to a remote destination
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 -w WORK_DIR work dir for this script
34 (default: GIT_TOP_DIR/build-perf-test)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 -x create xml report (instead of json)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036EOF
37}
38
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039get_os_release_var () {
40 ( source /etc/os-release; eval echo '$'$1 )
41}
42
Patrick Williamsc0f7c042017-02-23 20:41:17 -060043
44# Parse command line arguments
45commitish=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046oe_build_perf_test_extra_opts=()
47oe_git_archive_extra_opts=()
Andrew Geissler99467da2019-02-25 18:54:23 -060048while getopts "ha:c:C:d:E:g:P:R:w:x" opt; do
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 case $opt in
50 h) usage
51 exit 0
52 ;;
Andrew Geissler99467da2019-02-25 18:54:23 -060053 a) mkdir -p "$OPTARG"
54 archive_dir=`realpath -s "$OPTARG"`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055 ;;
56 c) commitish=$OPTARG
57 ;;
Andrew Geissler99467da2019-02-25 18:54:23 -060058 C) mkdir -p "$OPTARG"
59 results_repo=`realpath -s "$OPTARG"`
60 ;;
61 d) download_dir=`realpath -s "$OPTARG"`
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 ;;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063 E) email_to="$OPTARG"
64 ;;
Andrew Geissler99467da2019-02-25 18:54:23 -060065 g) mkdir -p "$OPTARG"
66 globalres_dir=`realpath -s "$OPTARG"`
67 ;;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 P) oe_git_archive_extra_opts+=("--push" "$OPTARG")
69 ;;
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 R) rsync_dst="$OPTARG"
71 ;;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 w) base_dir=`realpath -s "$OPTARG"`
73 ;;
74 x) oe_build_perf_test_extra_opts+=("--xml")
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 ;;
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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090# Open a file descriptor for flock and acquire lock
91LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock"
92if ! exec 3> "$LOCK_FILE"; then
Andrew Geissler9aee5002022-03-30 16:27:02 +000093 echo "ERROR: Unable to open loemack file"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 exit 1
95fi
96if ! flock -n 3; then
97 echo "ERROR: Another instance of this script is running"
98 exit 1
99fi
100
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600101echo "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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 echo "Running git fetch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600111 git fetch &> /dev/null
112 git checkout HEAD^0 &> /dev/null
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113
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"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600127 exit 1
128 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500129
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
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137fi
138
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500139# Determine name of the current branch
140branch=`git symbolic-ref HEAD 2> /dev/null`
141# Strip refs/heads/
142branch=${branch:11}
143
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600144# Setup build environment
145if [ -z "$base_dir" ]; then
146 base_dir="$git_topdir/build-perf-test"
147fi
148echo "Using working dir $base_dir"
149
Andrew Geissler99467da2019-02-25 18:54:23 -0600150if [ -z "$download_dir" ]; then
151 download_dir="$base_dir/downloads"
152fi
153if [ -z "$globalres_dir" ]; then
154 globalres_dir="$base_dir"
155fi
156
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600157timestamp=`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"
Andrew Geissler99467da2019-02-25 18:54:23 -0600161globalres_log="$globalres_dir/globalres.log"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162machine="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"
Andrew Geissler99467da2019-02-25 18:54:23 -0600172echo "DL_DIR = \"$download_dir\"" >> "$auto_conf"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600173# 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" \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500183 "${oe_build_perf_test_extra_opts[@]}" \
184 --lock-file "$base_dir/oe-build-perf.lock"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600185
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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194# 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
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500206 # 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500214 # Send email report
215 if [ -n "$email_to" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500216 echo "Emailing test report"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500217 os_name=`get_os_release_var PRETTY_NAME`
Andrew Geissler9aee5002022-03-30 16:27:02 +0000218 "$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[@]}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500219 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500225 fi
226fi
227
228
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600229echo -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"