summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/test_build_time.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/contrib/test_build_time.sh')
-rwxr-xr-xscripts/contrib/test_build_time.sh237
1 files changed, 237 insertions, 0 deletions
diff --git a/scripts/contrib/test_build_time.sh b/scripts/contrib/test_build_time.sh
new file mode 100755
index 0000000000..9e5725ae54
--- /dev/null
+++ b/scripts/contrib/test_build_time.sh
@@ -0,0 +1,237 @@
1#!/bin/bash
2
3# Build performance regression test script
4#
5# Copyright 2011 Intel Corporation
6# All rights reserved.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21#
22#
23# DESCRIPTION
24# This script is intended to be used in conjunction with "git bisect run"
25# in order to find regressions in build time, however it can also be used
26# independently. It cleans out the build output directories, runs a
27# specified worker script (an example is test_build_time_worker.sh) under
28# TIME(1), logs the results to TEST_LOGDIR (default /tmp) and returns a
29# value telling "git bisect run" whether the build time is good (under
30# the specified threshold) or bad (over it). There is also a tolerance
31# option but it is not particularly useful as it only subtracts the
32# tolerance from the given threshold and uses it as the actual threshold.
33#
34# It is also capable of taking a file listing git revision hashes to be
35# test-applied to the repository in order to get past build failures that
36# would otherwise cause certain revisions to have to be skipped; if a
37# revision does not apply cleanly then the script assumes it does not
38# need to be applied and ignores it.
39#
40# Please see the help output (syntax below) for some important setup
41# instructions.
42#
43# AUTHORS
44# Paul Eggleton <paul.eggleton@linux.intel.com>
45
46
47syntax() {
48 echo "syntax: $0 <script> <time> <tolerance> [patchrevlist]"
49 echo ""
50 echo " script - worker script file (if in current dir, prefix with ./)"
51 echo " time - time threshold (in seconds, suffix m for minutes)"
52 echo " tolerance - tolerance (in seconds, suffix m for minutes or % for"
53 echo " percentage, can be 0)"
54 echo " patchrevlist - optional file listing revisions to apply as patches on top"
55 echo ""
56 echo "You must set TEST_BUILDDIR to point to a previously created build directory,"
57 echo "however please note that this script will wipe out the TMPDIR defined in"
58 echo "TEST_BUILDDIR/conf/local.conf as part of its initial setup (as well as your"
59 echo "~/.ccache)"
60 echo ""
61 echo "To get rid of the sudo prompt, please add the following line to /etc/sudoers"
62 echo "(use 'visudo' to edit this; also it is assumed that the user you are running"
63 echo "as is a member of the 'wheel' group):"
64 echo ""
65 echo "%wheel ALL=(ALL) NOPASSWD: /sbin/sysctl -w vm.drop_caches=[1-3]"
66 echo ""
67 echo "Note: it is recommended that you disable crond and any other process that"
68 echo "may cause significant CPU or I/O usage during build performance tests."
69}
70
71# Note - we exit with 250 here because that will tell git bisect run that
72# something bad happened and stop
73if [ "$1" = "" ] ; then
74 syntax
75 exit 250
76fi
77
78if [ "$2" = "" ] ; then
79 syntax
80 exit 250
81fi
82
83if [ "$3" = "" ] ; then
84 syntax
85 exit 250
86fi
87
88if ! [[ "$2" =~ ^[0-9][0-9m.]*$ ]] ; then
89 echo "'$2' is not a valid number for threshold"
90 exit 250
91fi
92
93if ! [[ "$3" =~ ^[0-9][0-9m.%]*$ ]] ; then
94 echo "'$3' is not a valid number for tolerance"
95 exit 250
96fi
97
98if [ "$TEST_BUILDDIR" = "" ] ; then
99 echo "Please set TEST_BUILDDIR to a previously created build directory"
100 exit 250
101fi
102
103if [ ! -d "$TEST_BUILDDIR" ] ; then
104 echo "TEST_BUILDDIR $TEST_BUILDDIR not found"
105 exit 250
106fi
107
108git diff --quiet
109if [ $? != 0 ] ; then
110 echo "Working tree is dirty, cannot proceed"
111 exit 251
112fi
113
114if [ "$BB_ENV_EXTRAWHITE" != "" ] ; then
115 echo "WARNING: you are running after sourcing the build environment script, this is not recommended"
116fi
117
118runscript=$1
119timethreshold=$2
120tolerance=$3
121
122if [ "$4" != "" ] ; then
123 patchrevlist=`cat $4`
124else
125 patchrevlist=""
126fi
127
128if [[ timethreshold == *m* ]] ; then
129 timethreshold=`echo $timethreshold | sed s/m/*60/ | bc`
130fi
131
132if [[ $tolerance == *m* ]] ; then
133 tolerance=`echo $tolerance | sed s/m/*60/ | bc`
134elif [[ $tolerance == *%* ]] ; then
135 tolerance=`echo $tolerance | sed s/%//`
136 tolerance=`echo "scale = 2; (($tolerance * $timethreshold) / 100)" | bc`
137fi
138
139tmpdir=`grep "^TMPDIR" $TEST_BUILDDIR/conf/local.conf | sed -e 's/TMPDIR[ \t]*=[ \t\?]*"//' -e 's/"//'`
140if [ "x$tmpdir" = "x" ]; then
141 echo "Unable to determine TMPDIR from $TEST_BUILDDIR/conf/local.conf, bailing out"
142 exit 250
143fi
144sstatedir=`grep "^SSTATE_DIR" $TEST_BUILDDIR/conf/local.conf | sed -e 's/SSTATE_DIR[ \t\?]*=[ \t]*"//' -e 's/"//'`
145if [ "x$sstatedir" = "x" ]; then
146 echo "Unable to determine SSTATE_DIR from $TEST_BUILDDIR/conf/local.conf, bailing out"
147 exit 250
148fi
149
150if [ `expr length $tmpdir` -lt 4 ] ; then
151 echo "TMPDIR $tmpdir is less than 4 characters, bailing out"
152 exit 250
153fi
154
155if [ `expr length $sstatedir` -lt 4 ] ; then
156 echo "SSTATE_DIR $sstatedir is less than 4 characters, bailing out"
157 exit 250
158fi
159
160echo -n "About to wipe out TMPDIR $tmpdir, press Ctrl+C to break out... "
161for i in 9 8 7 6 5 4 3 2 1
162do
163 echo -ne "\x08$i"
164 sleep 1
165done
166echo
167
168pushd . > /dev/null
169
170rm -f pseudodone
171echo "Removing TMPDIR $tmpdir..."
172rm -rf $tmpdir
173echo "Removing TMPDIR $tmpdir-*libc..."
174rm -rf $tmpdir-*libc
175echo "Removing SSTATE_DIR $sstatedir..."
176rm -rf $sstatedir
177echo "Removing ~/.ccache..."
178rm -rf ~/.ccache
179
180echo "Syncing..."
181sync
182sync
183echo "Dropping VM cache..."
184#echo 3 > /proc/sys/vm/drop_caches
185sudo /sbin/sysctl -w vm.drop_caches=3 > /dev/null
186
187if [ "$TEST_LOGDIR" = "" ] ; then
188 logdir="/tmp"
189else
190 logdir="$TEST_LOGDIR"
191fi
192rev=`git rev-parse HEAD`
193logfile="$logdir/timelog_$rev.log"
194echo -n > $logfile
195
196gitroot=`git rev-parse --show-toplevel`
197cd $gitroot
198for patchrev in $patchrevlist ; do
199 echo "Applying $patchrev"
200 patchfile=`mktemp`
201 git show $patchrev > $patchfile
202 git apply --check $patchfile &> /dev/null
203 if [ $? != 0 ] ; then
204 echo " ... patch does not apply without errors, ignoring"
205 else
206 echo "Applied $patchrev" >> $logfile
207 git apply $patchfile &> /dev/null
208 fi
209 rm $patchfile
210done
211
212sync
213echo "Quiescing for 5s..."
214sleep 5
215
216echo "Running $runscript at $rev..."
217timeoutfile=`mktemp`
218/usr/bin/time -o $timeoutfile -f "%e\nreal\t%E\nuser\t%Us\nsys\t%Ss\nmaxm\t%Mk" $runscript 2>&1 | tee -a $logfile
219exitstatus=$PIPESTATUS
220
221git reset --hard HEAD > /dev/null
222popd > /dev/null
223
224timeresult=`head -n1 $timeoutfile`
225cat $timeoutfile | tee -a $logfile
226rm $timeoutfile
227
228if [ $exitstatus != 0 ] ; then
229 # Build failed, exit with 125 to tell git bisect run to skip this rev
230 echo "*** Build failed (exit code $exitstatus), skipping..." | tee -a $logfile
231 exit 125
232fi
233
234ret=`echo "scale = 2; $timeresult > $timethreshold - $tolerance" | bc`
235echo "Returning $ret" | tee -a $logfile
236exit $ret
237