
# prf: opmon profiling support
#
BIOSMAP=bios.map
OPMONMAP=opmon.map
PROFILE=oprofile
PRFTMP=""
UNIQ="+14"
LINE=NO
USAGE="usage: $0 help all line -m opmon.map -p oprofile -b bios.map > file"
while [ "$1" != "" ]; do
	case "$1" in
		*help*)	echo "$USAGE" >&2
			echo "setup: opdos opstart/opstop/opsave" >&2
			exit;;
		all)	UNIQ="";;
		line)	PRFTMP=/tmp/PRF$$; LINE=YES;;
		-m)	OPMONMAP=$2; shift;;
		*.map)	OPMONMAP=$1;;
		-p)	PROFILE=$2; shift;;
		-b)	BIOSMAP=$2; shift;;
		*)	echo "$USAGE" >&2
			exit;;
	esac
	shift
done
if [ ! -f $OPMONMAP ]; then
	echo "$0: $OPMONMAP not found" >&2
	exit
fi
if [ ! -f $PROFILE ]; then
	echo "ducp -a oprofile $PROFILE"
	ducp -a oprofile $PROFILE
	if [ ! -f $PROFILE ]; then
		echo "$0: $PROFILE not found" >&2
		exit
	fi
fi
if [ ! -f $BIOSMAP ]; then cat <<!! > $BIOSMAP
#		TABLE SIZE:SAMPLES
$		OPMON BASE
%		SYSTEM FLAGS
&		USER FLAGS
<		DOS SAMPLES
=		OPMON SAMPLES
>		BIOS SAMPLES
>A000:0000       BIOS A000:0000
>B000:0000       BIOS B000:0000
>C000:0000       BIOS C000:0000
>C400:0000       BIOS C400:0000
>C800:0000       BIOS C800:0000
>CC00:0000       BIOS CC00:0000
>D000:0000       BIOS D000:0000
>E000:0000       BIOS E000:0000
>F000:0000       BIOS F000:0000
>F000:1000       BIOS F000:1000
>F000:2000       BIOS F000:2000
>F000:3000       BIOS F000:3000
>F000:4000       BIOS F000:4000
>F000:5000       BIOS F000:5000
>F000:6000       BIOS F000:6000
>F000:7000       BIOS F000:7000
>F000:8000       BIOS F000:8000
>F000:9000       BIOS F000:9000
>F000:A000       BIOS F000:A000
>F000:B000       BIOS F000:B000
>F000:C000       BIOS F000:C000
>F000:D000       BIOS F000:D000
>F000:E000       BIOS F000:E000
>F000:F000       BIOS F000:F000
!!
fi
if [ $LINE = YES ]; then
	sed '/^Line/,/^Program/{
	/^Line/d
	/^Program/d
	/^$/d
	p
	}
	d' $OPMONMAP |
	awk -F' ' '{ print "="$2,"        ",$1,"\n="$4,"        ",$3,"\n="$6,"        ",$5,"\n="$8,"        ",$7 }' |
	sed '/^=[ ]*$/d' > $PRFTMP
fi
ed - $OPMONMAP <<!! | cat - $BIOSMAP $PROFILE $PRFTMP | sort | uniq -c $UNIQ
1,/Value/d
1d
\$d
\$d
1,\$s/^ /=/
1,/_dt/p
Q
!!
if [ $LINE = YES ]; then
	rm -f $PRFTMP
fi
