summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/build-perf-test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/contrib/build-perf-test.sh')
-rwxr-xr-xscripts/contrib/build-perf-test.sh369
1 files changed, 369 insertions, 0 deletions
diff --git a/scripts/contrib/build-perf-test.sh b/scripts/contrib/build-perf-test.sh
new file mode 100755
index 0000000000..cdd7885dca
--- /dev/null
+++ b/scripts/contrib/build-perf-test.sh
@@ -0,0 +1,369 @@
1#!/bin/bash
2#
3# This script runs a series of tests (with and without sstate) and reports build time (and tmp/ size)
4#
5# Build performance test script
6#
7# Copyright 2013 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22#
23#
24# AUTHORS:
25# Stefan Stanacar <stefanx.stanacar@intel.com>
26
27
28ME=$(basename $0)
29
30#
31# usage and setup
32#
33
34usage () {
35cat << EOT
36Usage: $ME [-h]
37 $ME [-c <commit>] [-v] [-m <val>] [-j <val>] [-t <val>] [-i <image-name>] [-d <path>]
38Options:
39 -h
40 Display this help and exit.
41 -c <commit>
42 git checkout <commit> before anything else
43 -v
44 Show bitbake output, don't redirect it to a log.
45 -m <machine>
46 Value for MACHINE. Default is qemux86.
47 -j <val>
48 Value for PARALLEL_MAKE. Default is 8.
49 -t <val>
50 Value for BB_NUMBER_THREADS. Default is 8.
51 -i <image-name>
52 Instead of timing against core-image-sato, use <image-name>
53 -d <path>
54 Use <path> as DL_DIR
55 -p <githash>
56 Cherry pick githash onto the commit
57
58Note: current working directory must be inside a poky git clone.
59
60EOT
61}
62
63
64if clonedir=$(git rev-parse --show-toplevel); then
65 cd $clonedir
66else
67 echo "The current working dir doesn't seem to be a poky git clone. Please cd there before running $ME"
68 exit 1
69fi
70
71IMAGE="core-image-sato"
72verbose=0
73dldir=
74commit=
75pmake=
76cherrypicks=
77while getopts "hvc:m:j:t:i:d:p:" opt; do
78 case $opt in
79 h) usage
80 exit 0
81 ;;
82 v) verbose=1
83 ;;
84 c) commit=$OPTARG
85 ;;
86 m) export MACHINE=$OPTARG
87 ;;
88 j) pmake=$OPTARG
89 ;;
90 t) export BB_NUMBER_THREADS=$OPTARG
91 ;;
92 i) IMAGE=$OPTARG
93 ;;
94 d) dldir=$OPTARG
95 ;;
96 p) cherrypicks="$cherrypicks $OPTARG"
97 ;;
98 *) usage
99 exit 1
100 ;;
101 esac
102done
103
104
105#drop cached credentials and test for sudo access without a password
106sudo -k -n ls > /dev/null 2>&1
107reqpass=$?
108if [ $reqpass -ne 0 ]; then
109 echo "The script requires sudo access to drop caches between builds (echo 3 > /proc/sys/vm/drop_caches)"
110 read -s -p "Please enter your sudo password: " pass
111 echo
112fi
113
114if [ -n "$commit" ]; then
115 echo "git checkout -f $commit"
116 git pull > /dev/null 2>&1
117 git checkout -f $commit || exit 1
118 git pull > /dev/null 2>&1
119fi
120
121if [ -n "$cherrypicks" ]; then
122 for c in $cherrypicks; do
123 git cherry-pick $c
124 done
125fi
126
127rev=$(git rev-parse --short HEAD) || exit 1
128OUTDIR="$clonedir/build-perf-test/results-$rev-`date "+%Y%m%d%H%M%S"`"
129BUILDDIR="$OUTDIR/build"
130resultsfile="$OUTDIR/results.log"
131bboutput="$OUTDIR/bitbake.log"
132myoutput="$OUTDIR/output.log"
133globalres="$clonedir/build-perf-test/globalres.log"
134
135mkdir -p $OUTDIR || exit 1
136
137log () {
138 local msg="$1"
139 echo "`date`: $msg" | tee -a $myoutput
140}
141
142
143#
144# Config stuff
145#
146
147branch=`git branch 2>&1 | grep "^* " | tr -d "* "`
148gitcommit=$(git rev-parse HEAD) || exit 1
149log "Running on $branch:$gitcommit"
150
151source ./oe-init-build-env $OUTDIR/build >/dev/null || exit 1
152cd $OUTDIR/build
153
154[ -n "$MACHINE" ] || export MACHINE="qemux86"
155[ -n "$BB_NUMBER_THREADS" ] || export BB_NUMBER_THREADS="8"
156
157if [ -n "$pmake" ]; then
158 export PARALLEL_MAKE="-j $pmake"
159else
160 export PARALLEL_MAKE="-j 8"
161fi
162
163if [ -n "$dldir" ]; then
164 echo "DL_DIR = \"$dldir\"" >> conf/local.conf
165else
166 echo "DL_DIR = \"$clonedir/build-perf-test/downloads\"" >> conf/local.conf
167fi
168
169# Sometimes I've noticed big differences in timings for the same commit, on the same machine
170# Disabling the network sanity check helps a bit (because of my crappy network connection and/or proxy)
171echo "CONNECTIVITY_CHECK_URIS =\"\"" >> conf/local.conf
172
173
174#
175# Functions
176#
177
178declare -a TIMES
179time_count=0
180declare -a SIZES
181size_count=0
182
183bbtime () {
184 local arg="$@"
185 log " Timing: bitbake ${arg}"
186
187 if [ $verbose -eq 0 ]; then
188 /usr/bin/time -v -o $resultsfile bitbake ${arg} >> $bboutput
189 else
190 /usr/bin/time -v -o $resultsfile bitbake ${arg}
191 fi
192 ret=$?
193 if [ $ret -eq 0 ]; then
194 t=`grep wall $resultsfile | sed 's/.*m:ss): //'`
195 log " TIME: $t"
196 TIMES[(( time_count++ ))]="$t"
197 else
198 log "ERROR: exit status was non-zero, will report time as 0."
199 TIMES[(( time_count++ ))]="0"
200 fi
201
202 #time by default overwrites the output file and we want to keep the results
203 #it has an append option but I don't want to clobber the results in the same file
204 i=`ls $OUTDIR/results.log* |wc -l`
205 mv $resultsfile "${resultsfile}.${i}"
206 log "More stats can be found in ${resultsfile}.${i}"
207}
208
209#we don't time bitbake here
210bbnotime () {
211 local arg="$@"
212 log " Running: bitbake ${arg}"
213 if [ $verbose -eq 0 ]; then
214 bitbake ${arg} >> $bboutput
215 else
216 bitbake ${arg}
217 fi
218 ret=$?
219 if [ $ret -eq 0 ]; then
220 log " Finished bitbake ${arg}"
221 else
222 log "ERROR: exit status was non-zero. Exit.."
223 exit $ret
224 fi
225
226}
227
228do_rmtmp() {
229 log " Removing tmp"
230 rm -rf bitbake.lock pseudodone conf/sanity_info cache tmp
231}
232do_rmsstate () {
233 log " Removing sstate-cache"
234 rm -rf sstate-cache
235}
236do_sync () {
237 log " Syncing and dropping caches"
238 sync; sync
239 if [ $reqpass -eq 0 ]; then
240 sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
241 else
242 echo "$pass" | sudo -S sh -c "echo 3 > /proc/sys/vm/drop_caches"
243 echo
244 fi
245 sleep 3
246}
247
248write_results() {
249 echo -n "`uname -n`,$branch:$gitcommit,`git describe`," >> $globalres
250 for i in "${TIMES[@]}"; do
251 echo -n "$i," >> $globalres
252 done
253 for i in "${SIZES[@]}"; do
254 echo -n "$i," >> $globalres
255 done
256 echo >> $globalres
257 sed -i '$ s/,$//' $globalres
258}
259
260####
261
262#
263# Test 1
264# Measure: Wall clock of "bitbake core-image-sato" and size of tmp/dir (w/o rm_work and w/ rm_work)
265# Pre: Downloaded sources, no sstate
266# Steps:
267# Part1:
268# - fetchall
269# - clean build dir
270# - time bitbake core-image-sato
271# - collect data
272# Part2:
273# - bitbake virtual/kernel -c cleansstate
274# - time bitbake virtual/kernel
275# Part3:
276# - add INHERIT to local.conf
277# - clean build dir
278# - build
279# - report size, remove INHERIT
280
281test1_p1 () {
282 log "Running Test 1, part 1/3: Measure wall clock of bitbake $IMAGE and size of tmp/ dir"
283 bbnotime $IMAGE -c fetchall
284 do_rmtmp
285 do_rmsstate
286 do_sync
287 bbtime $IMAGE
288 s=`du -s tmp | sed 's/tmp//' | sed 's/[ \t]*$//'`
289 SIZES[(( size_count++ ))]="$s"
290 log "SIZE of tmp dir is: $s"
291 log "Buildstats are saved in $OUTDIR/buildstats-test1"
292 mv tmp/buildstats $OUTDIR/buildstats-test1
293}
294
295
296test1_p2 () {
297 log "Running Test 1, part 2/3: bitbake virtual/kernel -c cleansstate and time bitbake virtual/kernel"
298 bbnotime virtual/kernel -c cleansstate
299 do_sync
300 bbtime virtual/kernel
301}
302
303test1_p3 () {
304 log "Running Test 1, part 3/3: Build $IMAGE w/o sstate and report size of tmp/dir with rm_work enabled"
305 echo "INHERIT += \"rm_work\"" >> conf/local.conf
306 do_rmtmp
307 do_rmsstate
308 do_sync
309 bbtime $IMAGE
310 sed -i 's/INHERIT += \"rm_work\"//' conf/local.conf
311 s=`du -s tmp | sed 's/tmp//' | sed 's/[ \t]*$//'`
312 SIZES[(( size_count++ ))]="$s"
313 log "SIZE of tmp dir is: $s"
314 log "Buildstats are saved in $OUTDIR/buildstats-test13"
315 mv tmp/buildstats $OUTDIR/buildstats-test13
316}
317
318
319#
320# Test 2
321# Measure: Wall clock of "bitbake core-image-sato" and size of tmp/dir
322# Pre: populated sstate cache
323
324test2 () {
325 # Assuming test 1 has run
326 log "Running Test 2: Measure wall clock of bitbake $IMAGE -c rootfs with sstate"
327 do_rmtmp
328 do_sync
329 bbtime $IMAGE -c rootfs
330}
331
332
333# Test 3
334# parsing time metrics
335#
336# Start with
337# i) "rm -rf tmp/cache; time bitbake -p"
338# ii) "rm -rf tmp/cache/default-glibc/; time bitbake -p"
339# iii) "time bitbake -p"
340
341
342test3 () {
343 log "Running Test 3: Parsing time metrics (bitbake -p)"
344 log " Removing tmp/cache && cache"
345 rm -rf tmp/cache cache
346 bbtime -p
347 log " Removing tmp/cache/default-glibc/"
348 rm -rf tmp/cache/default-glibc/
349 bbtime -p
350 bbtime -p
351}
352
353
354
355# RUN!
356
357test1_p1
358test1_p2
359test1_p3
360test2
361test3
362
363# if we got til here write to global results
364write_results
365
366log "All done, cleaning up..."
367
368do_rmtmp
369do_rmsstate