diff options
-rwxr-xr-x | scripts/contrib/test_build_time.sh | 237 | ||||
-rwxr-xr-x | scripts/contrib/test_build_time_worker.sh | 37 |
2 files changed, 274 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 | |||
47 | syntax() { | ||
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 | ||
73 | if [ "$1" = "" ] ; then | ||
74 | syntax | ||
75 | exit 250 | ||
76 | fi | ||
77 | |||
78 | if [ "$2" = "" ] ; then | ||
79 | syntax | ||
80 | exit 250 | ||
81 | fi | ||
82 | |||
83 | if [ "$3" = "" ] ; then | ||
84 | syntax | ||
85 | exit 250 | ||
86 | fi | ||
87 | |||
88 | if ! [[ "$2" =~ ^[0-9][0-9m.]*$ ]] ; then | ||
89 | echo "'$2' is not a valid number for threshold" | ||
90 | exit 250 | ||
91 | fi | ||
92 | |||
93 | if ! [[ "$3" =~ ^[0-9][0-9m.%]*$ ]] ; then | ||
94 | echo "'$3' is not a valid number for tolerance" | ||
95 | exit 250 | ||
96 | fi | ||
97 | |||
98 | if [ "$TEST_BUILDDIR" = "" ] ; then | ||
99 | echo "Please set TEST_BUILDDIR to a previously created build directory" | ||
100 | exit 250 | ||
101 | fi | ||
102 | |||
103 | if [ ! -d "$TEST_BUILDDIR" ] ; then | ||
104 | echo "TEST_BUILDDIR $TEST_BUILDDIR not found" | ||
105 | exit 250 | ||
106 | fi | ||
107 | |||
108 | git diff --quiet | ||
109 | if [ $? != 0 ] ; then | ||
110 | echo "Working tree is dirty, cannot proceed" | ||
111 | exit 251 | ||
112 | fi | ||
113 | |||
114 | if [ "$BB_ENV_EXTRAWHITE" != "" ] ; then | ||
115 | echo "WARNING: you are running after sourcing the build environment script, this is not recommended" | ||
116 | fi | ||
117 | |||
118 | runscript=$1 | ||
119 | timethreshold=$2 | ||
120 | tolerance=$3 | ||
121 | |||
122 | if [ "$4" != "" ] ; then | ||
123 | patchrevlist=`cat $4` | ||
124 | else | ||
125 | patchrevlist="" | ||
126 | fi | ||
127 | |||
128 | if [[ timethreshold == *m* ]] ; then | ||
129 | timethreshold=`echo $timethreshold | sed s/m/*60/ | bc` | ||
130 | fi | ||
131 | |||
132 | if [[ $tolerance == *m* ]] ; then | ||
133 | tolerance=`echo $tolerance | sed s/m/*60/ | bc` | ||
134 | elif [[ $tolerance == *%* ]] ; then | ||
135 | tolerance=`echo $tolerance | sed s/%//` | ||
136 | tolerance=`echo "scale = 2; (($tolerance * $timethreshold) / 100)" | bc` | ||
137 | fi | ||
138 | |||
139 | tmpdir=`grep "^TMPDIR" $TEST_BUILDDIR/conf/local.conf | sed -e 's/TMPDIR[ \t]*=[ \t\?]*"//' -e 's/"//'` | ||
140 | if [ "x$tmpdir" = "x" ]; then | ||
141 | echo "Unable to determine TMPDIR from $TEST_BUILDDIR/conf/local.conf, bailing out" | ||
142 | exit 250 | ||
143 | fi | ||
144 | sstatedir=`grep "^SSTATE_DIR" $TEST_BUILDDIR/conf/local.conf | sed -e 's/SSTATE_DIR[ \t\?]*=[ \t]*"//' -e 's/"//'` | ||
145 | if [ "x$sstatedir" = "x" ]; then | ||
146 | echo "Unable to determine SSTATE_DIR from $TEST_BUILDDIR/conf/local.conf, bailing out" | ||
147 | exit 250 | ||
148 | fi | ||
149 | |||
150 | if [ `expr length $tmpdir` -lt 4 ] ; then | ||
151 | echo "TMPDIR $tmpdir is less than 4 characters, bailing out" | ||
152 | exit 250 | ||
153 | fi | ||
154 | |||
155 | if [ `expr length $sstatedir` -lt 4 ] ; then | ||
156 | echo "SSTATE_DIR $sstatedir is less than 4 characters, bailing out" | ||
157 | exit 250 | ||
158 | fi | ||
159 | |||
160 | echo -n "About to wipe out TMPDIR $tmpdir, press Ctrl+C to break out... " | ||
161 | for i in 9 8 7 6 5 4 3 2 1 | ||
162 | do | ||
163 | echo -ne "\x08$i" | ||
164 | sleep 1 | ||
165 | done | ||
166 | echo | ||
167 | |||
168 | pushd . > /dev/null | ||
169 | |||
170 | rm -f pseudodone | ||
171 | echo "Removing TMPDIR $tmpdir..." | ||
172 | rm -rf $tmpdir | ||
173 | echo "Removing TMPDIR $tmpdir-*libc..." | ||
174 | rm -rf $tmpdir-*libc | ||
175 | echo "Removing SSTATE_DIR $sstatedir..." | ||
176 | rm -rf $sstatedir | ||
177 | echo "Removing ~/.ccache..." | ||
178 | rm -rf ~/.ccache | ||
179 | |||
180 | echo "Syncing..." | ||
181 | sync | ||
182 | sync | ||
183 | echo "Dropping VM cache..." | ||
184 | #echo 3 > /proc/sys/vm/drop_caches | ||
185 | sudo /sbin/sysctl -w vm.drop_caches=3 > /dev/null | ||
186 | |||
187 | if [ "$TEST_LOGDIR" = "" ] ; then | ||
188 | logdir="/tmp" | ||
189 | else | ||
190 | logdir="$TEST_LOGDIR" | ||
191 | fi | ||
192 | rev=`git rev-parse HEAD` | ||
193 | logfile="$logdir/timelog_$rev.log" | ||
194 | echo -n > $logfile | ||
195 | |||
196 | gitroot=`git rev-parse --show-toplevel` | ||
197 | cd $gitroot | ||
198 | for 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 | ||
210 | done | ||
211 | |||
212 | sync | ||
213 | echo "Quiescing for 5s..." | ||
214 | sleep 5 | ||
215 | |||
216 | echo "Running $runscript at $rev..." | ||
217 | timeoutfile=`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 | ||
219 | exitstatus=$PIPESTATUS | ||
220 | |||
221 | git reset --hard HEAD > /dev/null | ||
222 | popd > /dev/null | ||
223 | |||
224 | timeresult=`head -n1 $timeoutfile` | ||
225 | cat $timeoutfile | tee -a $logfile | ||
226 | rm $timeoutfile | ||
227 | |||
228 | if [ $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 | ||
232 | fi | ||
233 | |||
234 | ret=`echo "scale = 2; $timeresult > $timethreshold - $tolerance" | bc` | ||
235 | echo "Returning $ret" | tee -a $logfile | ||
236 | exit $ret | ||
237 | |||
diff --git a/scripts/contrib/test_build_time_worker.sh b/scripts/contrib/test_build_time_worker.sh new file mode 100755 index 0000000000..8e20a9ea7d --- /dev/null +++ b/scripts/contrib/test_build_time_worker.sh | |||
@@ -0,0 +1,37 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # This is an example script to be used in conjunction with test_build_time.sh | ||
4 | |||
5 | if [ "$TEST_BUILDDIR" = "" ] ; then | ||
6 | echo "TEST_BUILDDIR is not set" | ||
7 | exit 1 | ||
8 | fi | ||
9 | |||
10 | buildsubdir=`basename $TEST_BUILDDIR` | ||
11 | if [ ! -d $buildsubdir ] ; then | ||
12 | echo "Unable to find build subdir $buildsubdir in current directory" | ||
13 | exit 1 | ||
14 | fi | ||
15 | |||
16 | if [ -f oe-init-build-env ] ; then | ||
17 | . ./oe-init-build-env $buildsubdir | ||
18 | elif [ -f poky-init-build-env ] ; then | ||
19 | . ./poky-init-build-env $buildsubdir | ||
20 | else | ||
21 | echo "Unable to find build environment setup script" | ||
22 | exit 1 | ||
23 | fi | ||
24 | |||
25 | if [ -f ../meta/recipes-sato/images/core-image-sato.bb ] ; then | ||
26 | target="core-image-sato" | ||
27 | else | ||
28 | target="poky-image-sato" | ||
29 | fi | ||
30 | |||
31 | echo "Build started at `date "+%Y-%m-%d %H:%M:%S"`" | ||
32 | echo "bitbake $target" | ||
33 | bitbake $target | ||
34 | ret=$? | ||
35 | echo "Build finished at `date "+%Y-%m-%d %H:%M:%S"`" | ||
36 | exit $ret | ||
37 | |||