summaryrefslogtreecommitdiff
path: root/build-time
blob: d675ca94eb2ea3b76a55c23c01d3ae7bc9abc2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/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=$!
	trap "kill $logpid" EXIT
	{ 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"