home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 March B
/
SCO_CASTOR4RRT.iso
/
uccs
/
root.14
/
etc
/
conf
/
bin
/
idoptimize
next >
Wrap
Text File
|
1998-08-19
|
6KB
|
396 lines
#!/usr/bin/ksh
#ident "@(#)ktool:common/ktool/idtools/idoptimize 1.4"
function cleanup
{
case "$1" in
clobber)
rm -rf $OPTDIR/*
;;
'')
rm -f $OPTDIR/*.r
rm -f $OPTDIR/*.keep
rm -f $OPTDIR/*.blocks
rm -f $OPTDIR/log.*.o
;;
*)
usage
esac
}
function add_interface
{
set $xopt
INTFILE=$ROOT/etc/conf/interface.d/ddi.5-strict
grep '^calllog$' $INTFILE > /dev/null 2>&1 ||
ed - $INTFILE > /dev/null 2>&1 <<-\!
$
a
# added by idoptimize
calllog
.
w
q
!
}
function rm_interface
{
INTFILE=$ROOT/etc/conf/interface.d/ddi.5-strict
while grep 'added by idoptimize$' $INTFILE > /dev/null 2>&1
do
ed - $INTFILE > /dev/null 2>&1 <<-\!
/added by idoptimize/
d
d
w
q
!
done
}
function setup_logging
{
set $xopt
if [ -n "$fopt" ]
then
setup_function_logging "$@"
return $?
fi
rm -f $OPTDIR/call.log
if [ -n "$1" ]
then
for i
do
echo $i
done > $OPTDIR/block.log
else
echo all > $OPTDIR/block.log
fi
setup_rebuild
}
function setup_function_logging
{
rm -f $OPTDIR/block.log
add_interface
if [ -n "$1" ]
then
for i
do
echo $i
done > $OPTDIR/call.log
else
echo all > $OPTDIR/call.log
fi
( cd /usr/ccs/lib/fur; cc -DKERNEL -O -DNUMCALLS=$NUMCALLS -c calllog.c )
setup_rebuild
}
function setup_rebuild
{
if [ -n "$ROOT" -a "$ROOT" != / ]
then
touch $ROOT/etc/conf/.rebuild
else
idbuild > /dev/null 2>&1
fi
}
function turnoff_logging
{
set $xopt
rm_interface
setup_rebuild
rm -f $OPTDIR/block.log $OPTDIR/call.log
}
function staticize
{
set $xopt
if [ -z "$1" ]
then
set -- `modadmin -s | sed 's!^.*/!!'`
fi
for i
do
if grep '$static' $ROOT/etc/conf/sdevice.d/$i > /dev/null
then
echo $i already static
continue
fi
ed - $ROOT/etc/conf/sdevice.d/$i > /dev/null 2>&1 <<-\!
/version [0-9]/
a
# added by idoptimize
$static
.
w
q
!
done
}
function unstaticize
{
set $xopt
(
cd $ROOT/etc/conf/sdevice.d
if [ -z "$1" ]
then
set -- `grep -l 'added by idoptimize' *`
fi
for i
do
ed - $i > /dev/null 2>&1 <<-\!
/added by idoptimize/
d
d
w
q
!
done
)
}
function read_modlist
{
#set -- $(modadmin -s)
drvs="`modadmin -s | sed -n 's!^.*/!!p'` unix"
return
}
function error
{
echo "Error Processing Driver: $i" >&2
exit 1
}
function clearcalls
{
idreadlog -w CallCount CallSize > /dev/null 2>&1
}
function clearblocks
{
typeset i j
set $xopt
whence idreadlog > /dev/null 2>&1 || { print -u2 idreadlog not found; exit 1; }
if [ ! -d $OPTDIR ]
then
mkdir $OPTDIR
fi
cd $OPTDIR
if [ -z "$1" ]
then
read_modlist
set -- $drvs
fi
let j=0
for i
do
#set -x
#eval size=\$sizes$i
#[ -n "$size" ] || error $i
addr=${i}BlockCount
size=${i}BlockSize
idreadlog -w $addr $size > /dev/null 2>&1 && let j=j+1
set +x
done
if clearcalls || (( $j ))
then
return 0
else
print -u2 No logging information in kernel
return 1
fi
}
function getcalls
{
idreadlog -r CallCount CallSize 2>/dev/null | readlog > $OPTDIR/call.count 2>/dev/null
}
function getblocks
{
set $xopt
typeset i j
whence idreadlog > /dev/null 2>&1 || { print -u2 idreadlog not found; exit 1; }
if [ ! -d $OPTDIR ]
then
mkdir $OPTDIR
fi
cd $OPTDIR
if [ -z "$1" ]
then
read_modlist
set -- $drvs
fi
let j=0
for i
do
#eval size=\$sizes$i
#[ -n "$size" ] || error $i
addr=${i}BlockCount
size=${i}BlockSize
if [ "$i" = unix ]
then
DRIVER=unix.r
else
DRIVER=$i.r
fi
if [ -n "$mopt" ] && [ -f $i.blocks ]
then
if idreadlog -r $addr $size > $i.blocks.tmp 2>/dev/null
then
let j=j+1
else
rm $i.blocks.tmp
continue
fi
[ ! -s $i.blocks.tmp ] || fur -M $i.blocks -K $i.keep -o $i.order -r -f "$i.blocks $i.blocks.tmp" $DRIVER || error $i
rm -f $i.blocks.tmp
else
if idreadlog -r $addr $size > $i.blocks 2>/dev/null
then
let j=j+1
else
rm $i.blocks
continue
fi
[ ! -s $i.blocks ] || fur -K $i.keep -o $i.order -r -f $i.blocks $DRIVER
fi
if [ ! -s $i.blocks -o ! -s $i.order ]
then
rm -f $i.blocks $i.order
continue
fi
done
if getcalls || (( $j ))
then
setup_rebuild
return 0
else
print -u2 No logging information in kernel
return 1
fi
}
function usage
{
echo "Illegal option" >&2
echo "Usage:" >&2
echo "\tidoptimize -C [clobber] - clean up files - clobber removes\n\t\t\tuseful information but saves more space" >&2
echo "\tidoptimize -c [module]... - clear log files in running kernel" >&2
echo "\tidoptimize -f [module]... - next rebuild will set up function logging for modules" >&2
echo "\tidoptimize -g [-m] [module]... - get log files from running kernel\n\t\t\t\t-m merges into last log file" >&2
echo "\tidoptimize -L [module]... - next rebuild will turn off logging for modules" >&2
echo "\tidoptimize -l [module]... - next rebuild will set up logging for modules" >&2
echo "\tidoptimize -s [module]... - make all modules currently loaded, static" >&2
echo "\tidoptimize -u - undoes 'idoptimize -s'" >&2
exit 1
}
if [ "${ROOT:=/}" != "/" ]
then
ROOT=${ROOT}${MACH:+"/$MACH"}
fi
OPTDIR=$ROOT/etc/conf/optimize.d
if [ ! -d "$OPTDIR" ]
then
mkdir $OPTDIR
chmod 755 $OPTDIR
fi
clobber=
[ -n "$NUMCALLS" ] || NUMCALLS=65536
Copt=
copt=
fopt=
gopt=
Lopt=
lopt=
mopt=
sopt=
uopt=
xopt=+x
while getopts :CcfgLlmsux opt
do
case "$opt" in
C)
Copt=on
;;
c)
copt=on
;;
f)
fopt=on
;;
g)
gopt=on
;;
L)
Lopt=on
;;
l)
lopt=on
;;
m)
mopt=on
;;
s)
sopt=on
;;
u)
uopt=on
;;
x)
xopt=-x
;;
*)
usage
esac
done
PATH=/sbin:$ROOT/etc/conf/bin:$PATH:/etc/conf/bin
shiftval=`expr $OPTIND - 1`
shift $shiftval
set $xopt
if [ -n "$mopt" -a -z "$gopt" ]
then
usage
fi
if [ -n "$fopt" -a -z "$lopt" -a -z "$Lopt" ]
then
usage
fi
if [ "$Copt$copt$gopt$Lopt$lopt$sopt$uopt" != on ]
then
usage
fi
if [ -n "$Copt" ]
then
cleanup "$@"
fi
if [ -n "$copt" ]
then
clearblocks "$@"
fi
if [ -n "$gopt" ]
then
getblocks "$@"
fi
if [ -n "$Lopt" ]
then
turnoff_logging "$@"
fi
if [ -n "$lopt" ]
then
setup_logging "$@"
fi
if [ -n "$sopt" ]
then
staticize "$@"
fi
if [ -n "$uopt" ]
then
unstaticize "$@"
fi