blob: fa71d4a2e9a82bc6429b9dc1a242acfcb5ccdcba [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/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
90if [ -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
101# 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
112echo "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
121 echo "Running git fetch"
122 git fetch &> /dev/null
123 git checkout HEAD^0 &> /dev/null
124
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"
138 exit 1
139 fi
140
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
148fi
149
150# Determine name of the current branch
151branch=`git symbolic-ref HEAD 2> /dev/null`
152# Strip refs/heads/
153branch=${branch:11}
154
155# Setup build environment
156if [ -z "$base_dir" ]; then
157 base_dir="$git_topdir/build-perf-test"
158fi
159echo "Using working dir $base_dir"
160
161if [ -z "$download_dir" ]; then
162 download_dir="$base_dir/downloads"
163fi
164if [ -z "$globalres_dir" ]; then
165 globalres_dir="$base_dir"
166fi
167
168timestamp=`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"
172globalres_log="$globalres_dir/globalres.log"
173machine="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"
183echo "DL_DIR = \"$download_dir\"" >> "$auto_conf"
184# 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" \
194 "${oe_build_perf_test_extra_opts[@]}" \
195 --lock-file "$base_dir/oe-build-perf.lock"
196
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
205# 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
217 # 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
225 # Send email report
226 if [ -n "$email_to" ]; then
227 echo "Emailing test report"
228 os_name=`get_os_release_var PRETTY_NAME`
229 "$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
236 fi
237fi
238
239
240echo -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"