diff options
Diffstat (limited to 'scripts/contrib/build-perf-test.sh')
-rwxr-xr-x | scripts/contrib/build-perf-test.sh | 369 |
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 | |||
28 | ME=$(basename $0) | ||
29 | |||
30 | # | ||
31 | # usage and setup | ||
32 | # | ||
33 | |||
34 | usage () { | ||
35 | cat << EOT | ||
36 | Usage: $ME [-h] | ||
37 | $ME [-c <commit>] [-v] [-m <val>] [-j <val>] [-t <val>] [-i <image-name>] [-d <path>] | ||
38 | Options: | ||
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 | |||
58 | Note: current working directory must be inside a poky git clone. | ||
59 | |||
60 | EOT | ||
61 | } | ||
62 | |||
63 | |||
64 | if clonedir=$(git rev-parse --show-toplevel); then | ||
65 | cd $clonedir | ||
66 | else | ||
67 | echo "The current working dir doesn't seem to be a poky git clone. Please cd there before running $ME" | ||
68 | exit 1 | ||
69 | fi | ||
70 | |||
71 | IMAGE="core-image-sato" | ||
72 | verbose=0 | ||
73 | dldir= | ||
74 | commit= | ||
75 | pmake= | ||
76 | cherrypicks= | ||
77 | while 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 | ||
102 | done | ||
103 | |||
104 | |||
105 | #drop cached credentials and test for sudo access without a password | ||
106 | sudo -k -n ls > /dev/null 2>&1 | ||
107 | reqpass=$? | ||
108 | if [ $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 | ||
112 | fi | ||
113 | |||
114 | if [ -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 | ||
119 | fi | ||
120 | |||
121 | if [ -n "$cherrypicks" ]; then | ||
122 | for c in $cherrypicks; do | ||
123 | git cherry-pick $c | ||
124 | done | ||
125 | fi | ||
126 | |||
127 | rev=$(git rev-parse --short HEAD) || exit 1 | ||
128 | OUTDIR="$clonedir/build-perf-test/results-$rev-`date "+%Y%m%d%H%M%S"`" | ||
129 | BUILDDIR="$OUTDIR/build" | ||
130 | resultsfile="$OUTDIR/results.log" | ||
131 | bboutput="$OUTDIR/bitbake.log" | ||
132 | myoutput="$OUTDIR/output.log" | ||
133 | globalres="$clonedir/build-perf-test/globalres.log" | ||
134 | |||
135 | mkdir -p $OUTDIR || exit 1 | ||
136 | |||
137 | log () { | ||
138 | local msg="$1" | ||
139 | echo "`date`: $msg" | tee -a $myoutput | ||
140 | } | ||
141 | |||
142 | |||
143 | # | ||
144 | # Config stuff | ||
145 | # | ||
146 | |||
147 | branch=`git branch 2>&1 | grep "^* " | tr -d "* "` | ||
148 | gitcommit=$(git rev-parse HEAD) || exit 1 | ||
149 | log "Running on $branch:$gitcommit" | ||
150 | |||
151 | source ./oe-init-build-env $OUTDIR/build >/dev/null || exit 1 | ||
152 | cd $OUTDIR/build | ||
153 | |||
154 | [ -n "$MACHINE" ] || export MACHINE="qemux86" | ||
155 | [ -n "$BB_NUMBER_THREADS" ] || export BB_NUMBER_THREADS="8" | ||
156 | |||
157 | if [ -n "$pmake" ]; then | ||
158 | export PARALLEL_MAKE="-j $pmake" | ||
159 | else | ||
160 | export PARALLEL_MAKE="-j 8" | ||
161 | fi | ||
162 | |||
163 | if [ -n "$dldir" ]; then | ||
164 | echo "DL_DIR = \"$dldir\"" >> conf/local.conf | ||
165 | else | ||
166 | echo "DL_DIR = \"$clonedir/build-perf-test/downloads\"" >> conf/local.conf | ||
167 | fi | ||
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) | ||
171 | echo "CONNECTIVITY_CHECK_URIS =\"\"" >> conf/local.conf | ||
172 | |||
173 | |||
174 | # | ||
175 | # Functions | ||
176 | # | ||
177 | |||
178 | declare -a TIMES | ||
179 | time_count=0 | ||
180 | declare -a SIZES | ||
181 | size_count=0 | ||
182 | |||
183 | bbtime () { | ||
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 | ||
210 | bbnotime () { | ||
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 | |||
228 | do_rmtmp() { | ||
229 | log " Removing tmp" | ||
230 | rm -rf bitbake.lock pseudodone conf/sanity_info cache tmp | ||
231 | } | ||
232 | do_rmsstate () { | ||
233 | log " Removing sstate-cache" | ||
234 | rm -rf sstate-cache | ||
235 | } | ||
236 | do_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 | |||
248 | write_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 | |||
281 | test1_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 | |||
296 | test1_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 | |||
303 | test1_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 | |||
324 | test2 () { | ||
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 | |||
342 | test3 () { | ||
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 | |||
357 | test1_p1 | ||
358 | test1_p2 | ||
359 | test1_p3 | ||
360 | test2 | ||
361 | test3 | ||
362 | |||
363 | # if we got til here write to global results | ||
364 | write_results | ||
365 | |||
366 | log "All done, cleaning up..." | ||
367 | |||
368 | do_rmtmp | ||
369 | do_rmsstate | ||