diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-10-28 10:56:16 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-10-28 10:56:16 +0100 |
commit | e8ae4b17bb1b17ac30730f940568f713ebe1cded (patch) | |
tree | 0b5df1382bb01cecd131e39d219bf1fceaa91b56 /build-time | |
parent | 6da82aea0a8a4dc53903cf69f7ca8ba008c69cb7 (diff) | |
download | scripts-e8ae4b17bb1b17ac30730f940568f713ebe1cded.tar.gz |
build-time: benchmark compile times
This script stores compile times while compiling a kernel. It was used
to determine the temperature performance after changing thermal paste.
Diffstat (limited to 'build-time')
-rwxr-xr-x | build-time | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/build-time b/build-time new file mode 100755 index 0000000..19d26b8 --- /dev/null +++ b/build-time @@ -0,0 +1,149 @@ +#!/bin/bash +# Watch CPU temperature while compiling +# +# Author: Peter Wu <lekensteyn@gmail.com> +# Created: 2013-07-31 + +GITREPO=${GITREPO:-$HOME/Linux-src/linux} +SRCDIR=${SRCDIR:-/tmp/linux-src} +BUILDDIR=${BUILDDIR:-/tmp/linux-build} +LOGDIR=${LOGDIR:-.} + +for arg; do + # Clear all arguments in order to print usage message. + case $arg in + --help|-h) + set -- + break + ;; + esac + if ! [[ $arg -gt 0 ]]; then + echo "Invalid number: $arg" >&2 + exit 1 + fi +done + +if [ $# -lt 2 ]; then + cat <<EOF +Usage: $0 repetitions cores1 [cores2 ... coresN] + +Use at least three repetitions to get a reliable average. Specify a +number of cores to test. For example, to compare a dual core against a +quad core CPU, I used the following: + + $0 3 4 8 12 16 + +Timings and results will be written to stdout. + +The following environment vars are available: + +# Path to Linux git repository (to fetch sources from). Unused if +# SRCDIR is given which contains a 'version' file. +GITREPO=$GITREPO + +# Directory to build the kernel from. If there is no 'version' file, +# the directory will be removed and created from sources in GITREPO. +SRCDIR=$SRCDIR + +# Output directory for object files. +BUILDDIR=$BUILDDIR + +# Directory to store temperature readings. +LOGDIR=$LOGDIR +EOF + exit 1 +fi + +# Begin logic + +if ! [ -e "$SRCDIR/version" ]; then + if [ -d "$SRCDIR/.git" ]; then + echo "$SRCDIR is a git repo, which I will not delete." >&2 + echo "Create the 'version' file in the SRCDIR directory" >&2 + echo "or specify a different target SRCDIR." >&2 + exit 1 + fi + rm -rf "$SRCDIR" + mkdir "$SRCDIR" + if ! (cd "$GITREPO" && git describe) > "$SRCDIR/version"; then + echo "$GITREPO is not a git repo? Aborting!" >&2 + exit 1 + fi + (cd "$GITREPO" && time git archive HEAD) | tar x -C "$SRCDIR" +fi +cat "$SRCDIR/version" + +mk() { + make -C "$SRCDIR" O="$BUILDDIR" "$@" +} + +get_temps() { + cat /sys/devices/platform/coretemp.0/temp*_input | + tr '\n' '\t' | sed 's/\t$/\n/' +} + +temp_logger() { + local name=$1 + mkdir -p "$LOGDIR" + while sleep 1; do + get_temps + done > "$LOGDIR/$name" +} + +run() { + local tag jobs sec1 sec2 logpid templog + + tag=$1 + jobs=$2 + templog="temps-$tag-$jobs" + + rm -rf "$BUILDDIR" + mkdir "$BUILDDIR" + + mk defconfig >/dev/null 2>&1 + + echo + echo "Running $tag-$jobs" + temp_logger "$templog" & logpid=$! + time { + sec1=$(date +%s) + mk -j$jobs bzImage modules >/dev/null 2>&1 + sec2=$(date +%s) + echo "jobs=$jobs secs=$((sec2-sec1))" + echo -n "loadavg: " + cut -d\ -f1-3 /proc/loadavg + } 2>&1 + kill $logpid; wait $logpid 2>/dev/null + + # Very simple statistics + echo "Temperature (min / avg / max):" + awk ' + { + for (i=0; i<NF; i++) { + sum[i] += $i / 1000; + if (max[i] < $i) max[i] = $i; + if (min[i] == "" || min[i] > $i) min[i] = $i; + } + count++; + } + END { + for (i in sum) { + avg = sum[i] / count; + print min[i] / 1000, "/", avg, "/", max[i] / 1000 + } + } + ' "$LOGDIR/$templog" +} + +resdir="res-$(date +%Y%m%d-%H%M%S)" +mkdir -v "$resdir" +cd "$resdir" + +trials=$1; shift +for ((trial_no=1; trial_no<=trials; trial_no++)); do + for jobs; do + run $trial_no $jobs + done +done + +#rm -rf "$BUILDDIR" "$SRCDIR" |