#!/bin/sh
#
# $Revision: 1.3 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/dnlc,v $
# $Host: sys7.com $
# $UUID: 7c46d25b-5478-3e51-ae3c-e8b37b79bb3b $
#
#<dnlc: print Solaris directory/inode cache
#
# Your cache should have a hit rate of at least 93-95%.
# Sample output after around 11 days of uptime:
#
#     me% ./dnlc 
#     Directory/inode cache statistics
#     (See /usr/include/sys/dnlc.h for more information)
#     
#     maxphys:        3145728    Max physical request
#     ufs_ninode:      896000    Inode cache size
#     sq_max_size:        800    Streams queue
#     ncsize:          896000    Directory name cache size
#     ncstats:     1042252708    # of cache hits that we used
#     ncstats+4:     16276718    # of misses
#     ncstats+8:     16602182    # of enters done
#     ncstats+0xc:      47274    # of enters tried when already cached
#     ncstats+0x10:         0    # of long names tried to enter
#     ncstats+0x14:         0    # of long name tried to look up
#     ncstats+0x18:  22957937    # of times LRU list was empty
#     ncstats+0x1c:       227    # of purges of cache
#                          98    Hit rate percentage

PATH=/bin:/usr/bin
export PATH

cmd='
   BEGIN  { fmt = "%-13s %9d %s\n" }
   /:.../ { s = substr ($0, 30); printf fmt, $1, $2, s }
   /perc/ { s = substr ($0, 30); printf fmt, " ", $1, s }
'

echo 'Directory/inode cache statistics'
echo '(See /usr/include/sys/dnlc.h for more information)'
echo

adb -k /dev/ksyms /dev/mem <<END | expand | awk "$cmd"
maxphys/D"Max physical request"
ufs_ninode/D"Inode cache size"
sq_max_size/D"Streams queue"
ncsize/D"Directory name cache size"
nrnode/D"nrnode"
ncstats/D"# of cache hits that we used"
+/D"# of misses"
+/D"# of enters done"
+/D"# of enters tried when already cached"
+/D"# of long names tried to enter"
+/D"# of long name tried to look up"
+/D"# of times LRU list was empty"
+/D"# of purges of cache"
*ncstats%1000>a
*(ncstats+4)%1000>b
*(ncstats+14)%1000>c
<a+<b+<c>n
<a*0t100%<n=D"Hit rate percentage"
END

exit 0
