diff options
| -rwxr-xr-x | scripts/contrib/build-perf-test.sh | 301 |
1 files changed, 301 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..2d70cfae52 --- /dev/null +++ b/scripts/contrib/build-perf-test.sh | |||
| @@ -0,0 +1,301 @@ | |||
| 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 agains core-image-sato, use <image-name> | ||
| 53 | -d <path> | ||
| 54 | Use <path> as DL_DIR | ||
| 55 | |||
| 56 | Note: current working directory must be inside a poky git clone. | ||
| 57 | |||
| 58 | EOT | ||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | if clonedir=$(git rev-parse --show-toplevel); then | ||
| 63 | cd $clonedir | ||
| 64 | else | ||
| 65 | echo "The current working dir doesn't seem to be a poky git clone. Please cd there before running $ME" | ||
| 66 | exit 1 | ||
| 67 | fi | ||
| 68 | |||
| 69 | IMAGE="core-image-sato" | ||
| 70 | verbose=0 | ||
| 71 | dldir= | ||
| 72 | commit= | ||
| 73 | pmake= | ||
| 74 | while getopts "hvc:m:j:t:i:d:" opt; do | ||
| 75 | case $opt in | ||
| 76 | h) usage | ||
| 77 | exit 0 | ||
| 78 | ;; | ||
| 79 | v) verbose=1 | ||
| 80 | ;; | ||
| 81 | c) commit=$OPTARG | ||
| 82 | ;; | ||
| 83 | m) export MACHINE=$OPTARG | ||
| 84 | ;; | ||
| 85 | j) pmake=$OPTARG | ||
| 86 | ;; | ||
| 87 | t) export BB_NUMBER_THREADS=$OPTARG | ||
| 88 | ;; | ||
| 89 | i) IMAGE=$OPTARG | ||
| 90 | ;; | ||
| 91 | d) dldir=$OPTARG | ||
| 92 | ;; | ||
| 93 | *) usage | ||
| 94 | exit 1 | ||
| 95 | ;; | ||
| 96 | esac | ||
| 97 | done | ||
| 98 | |||
| 99 | |||
| 100 | #drop cached credentials and test for sudo access without a password | ||
| 101 | sudo -k -n ls > /dev/null 2>&1 | ||
| 102 | reqpass=$? | ||
| 103 | if [ $reqpass -ne 0 ]; then | ||
| 104 | echo "The script requires sudo access to drop caches between builds (echo 3 > /proc/sys/vm/drop_caches)" | ||
| 105 | read -s -p "Please enter your sudo password: " pass | ||
| 106 | echo | ||
| 107 | fi | ||
| 108 | |||
| 109 | if [ -n "$commit" ]; then | ||
| 110 | echo "git checkout $commit" | ||
| 111 | git checkout $commit || exit 1 | ||
| 112 | git pull || exit 1 | ||
| 113 | fi | ||
| 114 | |||
| 115 | rev=$(git rev-parse --short HEAD) || exit 1 | ||
| 116 | OUTDIR="$clonedir/build-perf-test/results-$rev-`date "+%Y%m%d%H%M%S"`" | ||
| 117 | BUILDDIR="$OUTDIR/build" | ||
| 118 | resultsfile="$OUTDIR/results.log" | ||
| 119 | bboutput="$OUTDIR/bitbake.log" | ||
| 120 | myoutput="$OUTDIR/output.log" | ||
| 121 | |||
| 122 | mkdir -p $OUTDIR || exit 1 | ||
| 123 | |||
| 124 | log () { | ||
| 125 | local msg="$1" | ||
| 126 | echo "`date`: $msg" | tee -a $myoutput | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | # | ||
| 131 | # Config stuff | ||
| 132 | # | ||
| 133 | |||
| 134 | log "Git revision is $rev" | ||
| 135 | |||
| 136 | source ./oe-init-build-env $OUTDIR/build >/dev/null | ||
| 137 | cd $OUTDIR/build | ||
| 138 | |||
| 139 | [ -n "$MACHINE" ] || export MACHINE="qemux86" | ||
| 140 | [ -n "$BB_NUMBER_THREADS" ] || export BB_NUMBER_THREADS="8" | ||
| 141 | |||
| 142 | if [ -n "$pmake" ]; then | ||
| 143 | export PARALLEL_MAKE="-j $pmake" | ||
| 144 | else | ||
| 145 | export PARALLEL_MAKE="-j 8" | ||
| 146 | fi | ||
| 147 | |||
| 148 | if [ -n "$dldir" ]; then | ||
| 149 | echo "DL_DIR = \"$dldir\"" >> conf/local.conf | ||
| 150 | else | ||
| 151 | echo "DL_DIR = \"$clonedir/build-perf-test/downloads\"" >> conf/local.conf | ||
| 152 | fi | ||
| 153 | |||
| 154 | # | ||
| 155 | # Functions | ||
| 156 | # | ||
| 157 | |||
| 158 | bbtime () { | ||
| 159 | log "Running and timing bitbake $1" | ||
| 160 | if [ $verbose -eq 0 ]; then | ||
| 161 | /usr/bin/time -v -o $resultsfile bitbake "$1" >> $bboutput | ||
| 162 | else | ||
| 163 | /usr/bin/time -v -o $resultsfile bitbake "$1" | ||
| 164 | fi | ||
| 165 | ret=$? | ||
| 166 | if [ $ret -eq 0 ]; then | ||
| 167 | log "Finished bitbake $1" | ||
| 168 | else | ||
| 169 | log "Exit status was non-zero. Exit..." | ||
| 170 | exit $ret | ||
| 171 | fi | ||
| 172 | |||
| 173 | log "Time: `grep wall $resultsfile`" | ||
| 174 | #time by default overwrites the output file and we want to keep the results | ||
| 175 | #it has an append option but I don't want to clobber the results in the same file | ||
| 176 | i=`ls $OUTDIR/results.log* |wc -l` | ||
| 177 | mv $resultsfile "${resultsfile}.${i}" | ||
| 178 | log "More stats can be found in ${resultsfile}.${i}" | ||
| 179 | } | ||
| 180 | |||
| 181 | #we don't time bitbake here | ||
| 182 | bbnotime () { | ||
| 183 | log "Running bitbake $1" | ||
| 184 | if [ $verbose -eq 0 ]; then | ||
| 185 | bitbake "$1" >> $bboutput | ||
| 186 | else | ||
| 187 | bitbake "$1" | ||
| 188 | fi | ||
| 189 | ret=$? | ||
| 190 | if [ $ret -eq 0 ]; then | ||
| 191 | log "Finished bitbake $1" | ||
| 192 | else | ||
| 193 | log "Exit status was non-zero. Exit.." | ||
| 194 | exit $? | ||
| 195 | fi | ||
| 196 | |||
| 197 | } | ||
| 198 | |||
| 199 | do_rmtmp() { | ||
| 200 | log "Removing tmp" | ||
| 201 | rm -rf bitbake.lock pseudone tmp conf/sanity_info | ||
| 202 | } | ||
| 203 | do_rmsstate () { | ||
| 204 | log "Removing sstate-cache" | ||
| 205 | rm -rf sstate-cache | ||
| 206 | } | ||
| 207 | do_sync () { | ||
| 208 | log "Syncing and dropping caches" | ||
| 209 | sync; sync | ||
| 210 | if [ $reqpass -eq 0 ]; then | ||
| 211 | sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" | ||
| 212 | else | ||
| 213 | echo "$pass" | sudo -S sh -c "echo 3 > /proc/sys/vm/drop_caches" | ||
| 214 | echo | ||
| 215 | fi | ||
| 216 | sleep 3 | ||
| 217 | } | ||
| 218 | |||
| 219 | #### | ||
| 220 | |||
| 221 | # | ||
| 222 | # Test 1 | ||
| 223 | # Measure: Wall clock of "bitbake core-image-sato" and size of tmp/dir (w/o rm_work and w/ rm_work) | ||
| 224 | # Pre: Downloaded sources, no sstate | ||
| 225 | # Steps: | ||
| 226 | # Part1: | ||
| 227 | # - fetchall | ||
| 228 | # - clean build dir | ||
| 229 | # - time bitbake core-image-sato | ||
| 230 | # - collect data | ||
| 231 | # Part2: | ||
| 232 | # - bitbake virtual/kernel -c | ||
| 233 | # - time bitbake virtual/kernel | ||
| 234 | # Part3: | ||
| 235 | # - add INHERIT to local.conf | ||
| 236 | # - clean build dir | ||
| 237 | # - build | ||
| 238 | # - report size, remove INHERIT | ||
| 239 | |||
| 240 | test1_p1 () { | ||
| 241 | log "Running Test 1, part 1/3: Measure wall clock of bitbake $IMAGE and size of tmp/ dir" | ||
| 242 | bbnotime "$IMAGE -c fetchall" | ||
| 243 | do_rmtmp | ||
| 244 | do_rmsstate | ||
| 245 | do_sync | ||
| 246 | bbtime "$IMAGE" | ||
| 247 | log "Size of tmp dir is: `du -hc tmp | grep total`" | ||
| 248 | log "Buildstats are saved in $OUTDIR/buildstats-test1" | ||
| 249 | mv tmp/buildstats $OUTDIR/buildstats-test1 | ||
| 250 | } | ||
| 251 | |||
| 252 | |||
| 253 | test1_p2 () { | ||
| 254 | log "Running Test 1, part 2/3: bitbake virtual/kernel -c clean && cleansstate and time bitbake virtual/kernel" | ||
| 255 | bbnotime "virtual/kernel -c clean" | ||
| 256 | bbnotime "virtual/kernel -c cleansstate" | ||
| 257 | do_sync | ||
| 258 | bbtime "virtual/kernel" | ||
| 259 | } | ||
| 260 | |||
| 261 | test1_p3 () { | ||
| 262 | log "Running Test 1, part 3/3: Build $IMAGE w/o sstate and report size of tmp/dir with rm_work enabled" | ||
| 263 | echo "INHERIT += \"rm_work\"" >> conf/local.conf | ||
| 264 | do_rmtmp | ||
| 265 | do_rmsstate | ||
| 266 | do_sync | ||
| 267 | bbtime "$IMAGE" | ||
| 268 | log "Size of tmp dir is: `du -hc tmp | grep total`" | ||
| 269 | sed -i 's/INHERIT += \"rm_work\"//' conf/local.conf | ||
| 270 | } | ||
| 271 | |||
| 272 | |||
| 273 | # | ||
| 274 | # Test 2 | ||
| 275 | # Measure: Wall clock of "bitbake core-image-sato" and size of tmp/dir | ||
| 276 | # Pre: populated sstate cache | ||
| 277 | |||
| 278 | test2 () { | ||
| 279 | #assuming test 1 has run | ||
| 280 | log "Running Test 2: Measure wall clock of bitbake $IMAGE -c rootfs with sstate" | ||
| 281 | do_rmtmp | ||
| 282 | do_sync | ||
| 283 | bbtime "$IMAGE -c rootfs" | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | # RUN! | ||
| 288 | |||
| 289 | test1_p1 | ||
| 290 | test1_p2 | ||
| 291 | test1_p3 | ||
| 292 | test2 | ||
| 293 | |||
| 294 | log "All done." | ||
| 295 | |||
| 296 | |||
| 297 | |||
| 298 | |||
| 299 | |||
| 300 | |||
| 301 | |||
