d8307d
#!/usr/bin/bash
d8307d
# This script can be invoked as follows:
d8307d
#
d8307d
# glibc-bench-compare [options] <BUILD> [BUILD]
d8307d
#
d8307d
# Options may be one of the following:
d8307d
#
d8307d
# -t		The BUILD arguments are task ids and not a version-release string
d8307d
# -a ARCH	Do comparison for ARCH architecture
d8307d
#
d8307d
# If any of the above options are given, both BUILD arguments must be given.
d8307d
# Otherwise, if only one BUILD is specified, then it is compared against the
d8307d
# installed glibc.
d8307d
d8307d
# Silence the pushd/popd messages
d8307d
pushd() {
d8307d
	command pushd "$@" > /dev/null 2>&1
d8307d
}
d8307d
d8307d
popd() {
d8307d
	command popd "$@" > /dev/null 2>&1
d8307d
}
d8307d
d8307d
# Clean up any downloaded files before we exit
d8307d
trap "rm -rf /tmp/glibc-bench-compare.$BASHPID.*" EXIT
d8307d
d8307d
task=0
d8307d
arch=$(uname -i)
d8307d
options=0
d8307d
path=0
d8307d
installed=
d8307d
d8307d
# Look for any commandline options
d8307d
while getopts ":tpa:" opt; do
d8307d
	case $opt in
d8307d
		p)
d8307d
		path=1
d8307d
		;;
d8307d
		t)
d8307d
		task=1
d8307d
		options=1
d8307d
		echo "Not implemented."
d8307d
		exit 1
d8307d
		;;
d8307d
		a)
d8307d
		arch=$OPTARG
d8307d
		options=1
d8307d
		;;
d8307d
		*)
d8307d
		;;
d8307d
	esac
d8307d
done
d8307d
d8307d
# Done, now shift all option arguments out.
d8307d
shift $((OPTIND-1))
d8307d
d8307d
if [ $# -gt 2 ] || [ $# -eq 0 ] || [ $# -lt 2 -a $options -eq 1 ]; then
d8307d
	echo "Usage: $0 [OPTIONS] <old> [new]"
d8307d
	echo
d8307d
	echo "OPTIONS:"
d8307d
	echo -e "\t-t\tCompare two brew tasks"
d8307d
	echo -e "\t-a ARCH\tGet rpms for the ARCH architecture"
d8307d
	echo -e "\t-p\tCompare built rpms in two paths."
d8307d
	echo -e "\t\tThis minimally needs glibc, glibc-common and glibc-benchtests"
d8307d
	exit 1
d8307d
fi
d8307d
d8307d
if [ -z $2 ]; then
d8307d
	new="$1"
d8307d
	old=$(rpm --queryformat "%{VERSION}-%{RELEASE}\n" -q glibc | head -1)
d8307d
	installed=$old
d8307d
else
d8307d
	new="$2"
d8307d
	old="$1"
d8307d
fi
d8307d
d8307d
decompress_rpms() {
d8307d
	# We were given a path to the rpms.  Figure out the version-release and
d8307d
	# decompress the rpms.
d8307d
	if [ -n $1 ]; then
d8307d
		vr=$(rpm --queryformat="%{VERSION}-%{RELEASE}" -qp $1/glibc-2*.rpm | head -1)
d8307d
		mkdir $vr && pushd $vr
d8307d
	fi
d8307d
d8307d
	for r in $1*.rpm; do
d8307d
		( rpm2cpio $r | cpio -di ) > /dev/null
d8307d
	done
d8307d
d8307d
	if [ -n $1 ]; then
d8307d
		popd
d8307d
		echo $vr
d8307d
	fi
d8307d
}
d8307d
d8307d
# Get rpms for a build and decompress them
d8307d
get_build() {
d8307d
	echo "Processing build $1"
d8307d
	mkdir $1 && pushd $1
d8307d
	brew buildinfo "glibc-$1" |
d8307d
	sed -n -e "s|/mnt/koji\(.\+$arch.\+\)|http://kojipkgs.fedoraproject.org\1|p" |
d8307d
	while read url; do
d8307d
		echo "Downloading $url"
d8307d
		wget -q $url
d8307d
	done
d8307d
	decompress_rpms
d8307d
d8307d
	echo "Removing rpms"
d8307d
	rm -f $1/*.rpm
d8307d
d8307d
	popd
d8307d
}
d8307d
d8307d
# Run benchmarks for a build
d8307d
run_bench() {
d8307d
	if [ -z $1 ]; then
d8307d
		make DETAILED=1 ver=$installed prefix= -f /usr/libexec/glibc-benchtests/bench.mk bench
d8307d
	else
d8307d
		make DETAILED=1 ver=$1 prefix=$PWD -f $1/usr/libexec/glibc-benchtests/bench.mk bench
d8307d
	fi
d8307d
}
d8307d
d8307d
# Get absolute paths if needed, since we will change into the working directory
d8307d
# next.
d8307d
if [ $path -eq 1 ]; then
d8307d
	old_path=$(realpath $old)/
d8307d
	new_path=$(realpath $new)/
d8307d
fi
d8307d
d8307d
tmpdir=$(mktemp -p /tmp -d glibc-bench-compare.$$.XXXX)
d8307d
pushd $tmpdir
d8307d
d8307d
# Get both builds.
d8307d
if [ $path -eq 0 ]; then
d8307d
	if [ -z $installed ]; then
d8307d
		get_build $old
d8307d
	fi
d8307d
	get_build $new
d8307d
else
d8307d
	old=$(decompress_rpms $old_path)
d8307d
	new=$(decompress_rpms $new_path)
d8307d
fi
d8307d
d8307d
# make bench for each of those.
d8307d
if [ -z $installed ]; then
d8307d
	run_bench $old
d8307d
else
d8307d
	run_bench
d8307d
fi
d8307d
run_bench $new
d8307d
d8307d
# Now run the comparison script.
d8307d
$old/usr/libexec/glibc-benchtests/compare_bench.py $old/usr/libexec/glibc-benchtests/benchout.schema.json \
d8307d
	bench.$old.out bench.$new.out