#!/bin/sh
#
PATH=/usr/stress/perf/x11perfcomp:/usr/stress/perf:$PATH
export PATH

#
# Relevant files.
#
PRFOUT=prfout		# Output after running snapshot through prfpr
UPOUT=upout		# unixperf output
RESFILE=results		# Comparison of prfout and upout data
CUTOFF=			# Let prfcmp choose the cutoff unless it's provided
			# as an optional arg to this script.

#
# Process input args.
#
if [ "$1" = "" ]
then
	echo "usage: $0 <output_dir1> <output_dir2> <results_dir> [cutoff%]"
	exit
else
	OUTDIR1=$1
fi
#
if [ "$2" = "" ]
then
	echo "usage: $0 <output_dir1> <output_dir2> <results_dir> [cutoff%]"
	exit
else
	OUTDIR2=$2
fi
if [ "$3" = "" ]
then
	echo "usage: $0 <output_dir1> <output_dir2> <results_dir> [cutoff%]"
	exit
else
	RESDIR=$3
fi
if [ "$4" != "" ]
then
	CUTOFF=$4
fi
#
echo Comparing output directories $OUTDIR1 and $OUTDIR2
echo Results in $RESDIR/$RESFILE

#
# Make the results directory.
#
if [ -r "$RESDIR" ]
then
	echo Moving existing $RESDIR directory to $RESDIR.old
	if [ -r "$RESDIR.old" ]
	then
		rm -rf "$RESDIR.old"
	fi
	mv -f $RESDIR $RESDIR.old
fi
mkdir $RESDIR

#
# Copy the output dirs to the results directory for safe keeping.
#
cp -r $OUTDIR1 $RESDIR
cp -r $OUTDIR2 $RESDIR

#
# Use the test_list file from outdir1.
#
TEST_LIST=$RESDIR/$OUTDIR1/test_list

#
# Do the comparisons.
#
RESULTS=$RESDIR/$RESFILE
touch $RESULTS
grep -v "^#" $TEST_LIST | while read TEST etc
do
	echo Comparing $TEST data...
	echo "" >> $RESULTS
	echo "****************************** $TEST results ******************************" >> $RESULTS
	x11perfcomp -r  $RESDIR/$OUTDIR1/$TEST/$UPOUT		\
		        $RESDIR/$OUTDIR2/$TEST/$UPOUT		\
	                >> $RESULTS
	echo "" >> $RESULTS
	prfcmp $RESDIR/$OUTDIR1/$TEST/$PRFOUT			\
	       $RESDIR/$OUTDIR2/$TEST/$PRFOUT			\
	       >> $RESULTS $4
	echo "" >> $RESULTS
done

