:
#  FILE
#
#	tunebru    tune BRU for maximum performance
#
#  RCS CHANGE LOG 
#
#	tunebru,v
# Revision 1.5  1994/09/16  22:28:40  jeff
# Added "archive id" to MSG_SIZE, also print code letters to indicate
# if OVERWRITE PROTECT is active.
#
# Revision 1.4  1994/05/07  23:10:05  jeff
# Added RCS keywords.
#	
#
#  DESCRIPTION
#
#	This script will test BRU with various options, especially
#	the buffer options.  It will execute bru with the "time" 
#	command, and print the amount of time bru took to do
#	a backup.
#
#	By choosing the proper parameters, you can
#	"tune" bru for optimum performance
#
#	This script should be run on a "quiet" system, with
#	no other users.  Otherwise, the times may be affected
#	by other processes.
#
#
#		********* DISCLAIMER ***********

echo	"Please read this before you run "tunebru" ... 		

	You're on your own with this script.  No support is
	provided, since every system and backup device is
	different.  It's up to you to find the right
	combination of parameters that work best for your
	particular system.

	It's possible that some of these tests may cause your
	tape drive (or the system) to "hang".  This is probably
	due to deficiencies in your device driver.  Many device
	drivers cannot handle large buffer sizes.  If you use
	a buffer size that is too large, it can cause all kinds
	of "weird" errors.

	A large buffer size is not necessarily faster than a small one.
	The optimum buffer size depends on your operating system,
	bus architecture, tape device driver and other factors. 
	
	If you don't understand how this script works, read the
	bru manual.  It explains all the parameters."

#		********************************


echo "Do you wish to continue? (y/n): \c"
read ANSWER

case $ANSWER in
    [Yy] ) ;;
       * ) :
	   echo "tunebru test terminated"
	   exit 1
esac

#
# set various parameters
#
COUNT=0

if [ "$TESTDIR" = "" ]
then
	TESTDIR="."	# test directory to back up, make sure that this
			# directory contains enough data (at least 20 MB)
			# to be a realistic test
fi

if [ "$BRU" = "" ]
then
	BRU="bru"		# version of BRU to execute
fi

if [ "$BRUDEV" = "" ]
then
	BRUDEV=/dev/rct0	# default device to use
fi


RESULTS=tunebru.out	# where results are written
BUFSIZ=20		# buffer size in Kbytes

BRUTAB=/tmp/brutab$$	# location of brutab parameter file
export BRUTAB

BRUEXECLOG=/tmp/bruexeclog$$	# bru execution log
export BRUEXECLOG

touch $BRUEXECLOG
chmod 666 $BRUEXECLOG

#
# brutab parameters, adjust as necessary
#
SHMMAX=64		# max size of shared memory segment (Kbytes)
SHMSEG=5		# max # of shared memory segments
SHMALL=1500		# maximum amount of shared memory used (Kbytes)

#
# mkbrutab - make brutab file
#
mkbrutab () {
echo "${BRUDEV}\tshmmax=${SHMMAX}K shmseg=${SHMSEG} shmall=${SHMALL}K \\
\t\tshmcopy size=0 noautoscan" > $BRUTAB
echo "brutab parameters:" >> $RESULTS
cat $BRUTAB >> $RESULTS
}

echo "Test BRU for Optimum Performance - \c" > $RESULTS
date >> $RESULTS

echo "\n" >> $RESULTS
echo "          Device Name:\t${BRUDEV}" >> $RESULTS
echo "            Directory:\t${TESTDIR}" >> $RESULTS

echo "BRUEXECLOG = $BRUEXECLOG"
sleep 4

#
# test BRU with various buffer sizes
#
for BUFSIZ in 2 4 8 16 20 32 64 128 150 256 500	# adjust these as necessary
do
	COUNT=`expr $COUNT + 1`
	BRUCMD="${BRU} -c -b ${BUFSIZ}K -f ${BRUDEV} ${TESTDIR}"
	echo "\n\n********* BRU TEST # $COUNT **********" >> $RESULTS
	echo "Command:\t$BRUCMD" >> $RESULTS
	mkbrutab
	echo "Running bru test # $COUNT ... \c"
	echo "RESULTS:" >> $RESULTS
	>$BRUEXECLOG
	xargs $BRUCMD
	RC=$?
	if [ $RC -eq 0 ]
	then
		DONE_MSG=`grep "\[L182\]" $BRUEXECLOG`
		echo "DONE_MSG = $DONE_MSG"
		sleep 5
		>$BRUEXECLOG
		sync
		IFS=","
		set $DONE_MSG
		ELAPSED_TIME=$2
		TAPE_SPEED=$3
		echo "Elapsed time: $ELAPSED_TIME,  Tape Speed: $TAPE_SPEED" >> $RESULTS
		echo "COMPLETED, Tape Speed = $TAPE_SPEED"
	else
		echo "FAILED !!, EXIT CODE = $RC"
		echo "FAILED !!, EXIT CODE = $RC" >> $RESULTS
	fi
	rm -f $BRUTAB
done

exit 1	# jjj

#
# test BRU with double buffering
#
for BUFSIZ in 20 40 80 160 320		# adjust these as necessary
do
	for MULT in 1 2 3 4 5 6
	do
		COUNT=`expr $COUNT + 1`
		SHMMAX=`expr $BUFSIZ \* $MULT`
		BRUCMD="${BRU} -c -b ${BUFSIZ}K -D -f ${BRUDEV} ${TESTDIR}"
		echo "\n\n********* BRU TEST # $COUNT *********" >> $RESULTS
		echo "Command:\t$BRUCMD" >> $RESULTS
		mkbrutab
		echo "Running bru test # $COUNT ... \c"
		echo "RESULTS:" >> $RESULTS
		$BRUCMD
		if [ $? -lt 2 ]
		then
			DONE_MSG=`grep "\[L182\]" $BRUEXECLOG`
			IFS=","
			set $DONE_MSG
			ELAPSED_TIME=$2
			TAPE_SPEED=$3
			unset DONE_MSG
			echo "Elapsed time: $ELAPSED_TIME,  Tape Speed: $TAPE_SPEED" >> $RESULTS
			echo "COMPLETED, Tape Speed = $TAPE_SPEED"
		else
			echo "FAILED !!"
			echo "FAILED !!" >> $RESULTS
		fi
	done
done

rm -f $BRUEXECLOG $BRUTAB	# clean up

echo "\nAll tests completed"
echo "Results are stored in file '$RESULTS'"
