summaryrefslogtreecommitdiff
path: root/glibc-bench-compare
blob: 84e3abad4facae2981cd93acb25662812c0ef5d5 (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
151
152
153
#!/usr/bin/bash
# This script can be invoked as follows:
#
# glibc-bench-compare [options] <BUILD> [BUILD]
#
# Options may be one of the following:
#
# -t		The BUILD arguments are task ids and not a version-release string
# -a ARCH	Do comparison for ARCH architecture
#
# If any of the above options are given, both BUILD arguments must be given.
# Otherwise, if only one BUILD is specified, then it is compared against the
# installed glibc.

# Silence the pushd/popd messages
pushd() {
	command pushd "$@" > /dev/null 2>&1
}

popd() {
	command popd "$@" > /dev/null 2>&1
}

# Clean up any downloaded files before we exit
trap "rm -rf /tmp/glibc-bench-compare.$BASHPID.*" EXIT

task=0
arch=$(uname -i)
options=0
path=0
installed=

# Look for any commandline options
while getopts ":tpa:" opt; do
	case $opt in
		p)
		path=1
		;;
		t)
		task=1
		options=1
		echo "Not implemented."
		exit 1
		;;
		a)
		arch=$OPTARG
		options=1
		;;
		*)
		;;
	esac
done

# Done, now shift all option arguments out.
shift $((OPTIND-1))

if [ $# -gt 2 ] || [ $# -eq 0 ] || [ $# -lt 2 -a $options -eq 1 ]; then
	echo "Usage: $0 [OPTIONS] <old> [new]"
	echo
	echo "OPTIONS:"
	echo -e "\t-t\tCompare two brew tasks"
	echo -e "\t-a ARCH\tGet rpms for the ARCH architecture"
	echo -e "\t-p\tCompare built rpms in two paths."
	echo -e "\t\tThis minimally needs glibc, glibc-common and glibc-benchtests"
	exit 1
fi

if [ -z $2 ]; then
	new="$1"
	old=$(rpm --queryformat "%{VERSION}-%{RELEASE}\n" -q glibc | head -1)
	installed=$old
else
	new="$2"
	old="$1"
fi

decompress_rpms() {
	# We were given a path to the rpms.  Figure out the version-release and
	# decompress the rpms.
	if [ -n $1 ]; then
		vr=$(rpm --queryformat="%{VERSION}-%{RELEASE}" -qp $1/glibc-2*.rpm | head -1)
		mkdir $vr && pushd $vr
	fi

	for r in $1*.rpm; do
		( rpm2cpio $r | cpio -di ) > /dev/null
	done

	if [ -n $1 ]; then
		popd
		echo $vr
	fi
}

# Get rpms for a build and decompress them
get_build() {
	echo "Processing build $1"
	mkdir $1 && pushd $1
	brew buildinfo "glibc-$1" |
	sed -n -e "s|/mnt/koji\(.\+$arch.\+\)|http://kojipkgs.fedoraproject.org\1|p" |
	while read url; do
		echo "Downloading $url"
		wget -q $url
	done
	decompress_rpms

	echo "Removing rpms"
	rm -f $1/*.rpm

	popd
}

# Run benchmarks for a build
run_bench() {
	if [ -z $1 ]; then
		make DETAILED=1 ver=$installed prefix= -f /usr/libexec/glibc-benchtests/bench.mk bench
	else
		make DETAILED=1 ver=$1 prefix=$PWD -f $1/usr/libexec/glibc-benchtests/bench.mk bench
	fi
}

# Get absolute paths if needed, since we will change into the working directory
# next.
if [ $path -eq 1 ]; then
	old_path=$(realpath $old)/
	new_path=$(realpath $new)/
fi

tmpdir=$(mktemp -p /tmp -d glibc-bench-compare.$$.XXXX)
pushd $tmpdir

# Get both builds.
if [ $path -eq 0 ]; then
	if [ -z $installed ]; then
		get_build $old
	fi
	get_build $new
else
	old=$(decompress_rpms $old_path)
	new=$(decompress_rpms $new_path)
fi

# make bench for each of those.
if [ -z $installed ]; then
	run_bench $old
else
	run_bench
fi
run_bench $new

# Now run the comparison script.
$old/usr/libexec/glibc-benchtests/compare_bench.py $old/usr/libexec/glibc-benchtests/benchout.schema.json \
	bench.$old.out bench.$new.out