blob: fa71d4a2e9a82bc6429b9dc1a242acfcb5ccdcba [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
Andrew Geissler99467da2019-02-25 18:54:23 -060090if [ -n "$email_to" ]; then
91 if ! [ -x "$(command -v phantomjs)" ]; then
92 echo "ERROR: Sending email needs phantomjs."
93 exit 1
94 fi
95 if ! [ -x "$(command -v optipng)" ]; then
96 echo "ERROR: Sending email needs optipng."
97 exit 1
98 fi
99fi
100
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500101# Open a file descriptor for flock and acquire lock
102LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock"
103if ! exec 3> "$LOCK_FILE"; then
104 echo "ERROR: Unable to open lock file"
105 exit 1
106fi
107if ! flock -n 3; then
108 echo "ERROR: Another instance of this script is running"
109 exit 1
110fi
111
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600112echo "Running on `uname -n`"
113if ! git_topdir=$(git rev-parse --show-toplevel); then
114 echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`"
115 exit 1
116fi
117
118cd "$git_topdir"
119
120if [ -n "$commitish" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500121 echo "Running git fetch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600122 git fetch &> /dev/null
123 git checkout HEAD^0 &> /dev/null
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124
125 # Handle <branch>:<commit> format
126 if echo "$commitish" | grep -q ":"; then
127 commit=`echo "$commitish" | cut -d":" -f2`
128 branch=`echo "$commitish" | cut -d":" -f1`
129 else
130 commit="$commitish"
131 branch="$commitish"
132 fi
133
134 echo "Checking out $commitish"
135 git branch -D $branch &> /dev/null
136 if ! git checkout -f $branch &> /dev/null; then
137 echo "ERROR: Git checkout failed"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138 exit 1
139 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140
141 # Check that the specified branch really contains the commit
142 commit_hash=`git rev-parse --revs-only $commit --`
143 if [ -z "$commit_hash" -o "`git merge-base $branch $commit`" != "$commit_hash" ]; then
144 echo "ERROR: branch $branch does not contain commit $commit"
145 exit 1
146 fi
147 git reset --hard $commit > /dev/null
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600148fi
149
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500150# Determine name of the current branch
151branch=`git symbolic-ref HEAD 2> /dev/null`
152# Strip refs/heads/
153branch=${branch:11}
154
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155# Setup build environment
156if [ -z "$base_dir" ]; then
157 base_dir="$git_topdir/build-perf-test"
158fi
159echo "Using working dir $base_dir"
160
Andrew Geissler99467da2019-02-25 18:54:23 -0600161if [ -z "$download_dir" ]; then
162 download_dir="$base_dir/downloads"
163fi
164if [ -z "$globalres_dir" ]; then
165 globalres_dir="$base_dir"
166fi
167
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600168timestamp=`date "+%Y%m%d%H%M%S"`
169git_rev=$(git rev-parse --short HEAD) || exit 1
170build_dir="$base_dir/build-$git_rev-$timestamp"
171results_dir="$base_dir/results-$git_rev-$timestamp"
Andrew Geissler99467da2019-02-25 18:54:23 -0600172globalres_log="$globalres_dir/globalres.log"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600173machine="qemux86"
174
175mkdir -p "$base_dir"
176source ./oe-init-build-env $build_dir >/dev/null || exit 1
177
178# Additional config
179auto_conf="$build_dir/conf/auto.conf"
180echo "MACHINE = \"$machine\"" > "$auto_conf"
181echo 'BB_NUMBER_THREADS = "8"' >> "$auto_conf"
182echo 'PARALLEL_MAKE = "-j 8"' >> "$auto_conf"
Andrew Geissler99467da2019-02-25 18:54:23 -0600183echo "DL_DIR = \"$download_dir\"" >> "$auto_conf"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600184# Disabling network sanity check slightly reduces the variance of timing results
185echo 'CONNECTIVITY_CHECK_URIS = ""' >> "$auto_conf"
186# Possibility to define extra settings
187if [ -f "$base_dir/auto.conf.extra" ]; then
188 cat "$base_dir/auto.conf.extra" >> "$auto_conf"
189fi
190
191# Run actual test script
192oe-build-perf-test --out-dir "$results_dir" \
193 --globalres-file "$globalres_log" \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194 "${oe_build_perf_test_extra_opts[@]}" \
195 --lock-file "$base_dir/oe-build-perf.lock"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600196
197case $? in
198 1) echo "ERROR: oe-build-perf-test script failed!"
199 exit 1
200 ;;
201 2) echo "NOTE: some tests failed!"
202 ;;
203esac
204
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500205# Commit results to git
206if [ -n "$results_repo" ]; then
207 echo -e "\nArchiving results in $results_repo"
208 oe-git-archive \
209 --git-dir "$results_repo" \
210 --branch-name "{hostname}/{branch}/{machine}" \
211 --tag-name "{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}" \
212 --exclude "buildstats.json" \
213 --notes "buildstats/{branch_name}" "$results_dir/buildstats.json" \
214 "${oe_git_archive_extra_opts[@]}" \
215 "$results_dir"
216
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500217 # Generate test reports
218 sanitized_branch=`echo $branch | tr / _`
219 report_txt=`hostname`_${sanitized_branch}_${machine}.txt
220 report_html=`hostname`_${sanitized_branch}_${machine}.html
221 echo -e "\nGenerating test report"
222 oe-build-perf-report -r "$results_repo" > $report_txt
223 oe-build-perf-report -r "$results_repo" --html > $report_html
224
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500225 # Send email report
226 if [ -n "$email_to" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500227 echo "Emailing test report"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 os_name=`get_os_release_var PRETTY_NAME`
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500229 "$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[@]}"
230 fi
231
232 # Upload report files, unless we're on detached head
233 if [ -n "$rsync_dst" -a -n "$branch" ]; then
234 echo "Uploading test report"
235 rsync $report_txt $report_html $rsync_dst
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 fi
237fi
238
239
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600240echo -ne "\n\n-----------------\n"
241echo "Global results file:"
242echo -ne "\n"
243
244cat "$globalres_log"
245
246if [ -n "$archive_dir" ]; then
247 echo -ne "\n\n-----------------\n"
248 echo "Archiving results in $archive_dir"
249 mkdir -p "$archive_dir"
250 results_basename=`basename "$results_dir"`
251 results_dirname=`dirname "$results_dir"`
252 tar -czf "$archive_dir/`uname -n`-${results_basename}.tar.gz" -C "$results_dirname" "$results_basename"
253fi
254
255rm -rf "$build_dir"
256rm -rf "$results_dir"
257
258echo "DONE"