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