Home | History | Annotate | Line # | Download | only in Bin
      1 #!/usr/bin/sh
      2 #
      3 # dnlcstat - DNLC statistics.
      4 #            Written in DTrace (Solaris 10 3/05).
      5 #
      6 # The DNLC is the Directory Name Lookup Cache. Filename lookups often
      7 # return a hit from here, before needing to traverse the regular file
      8 # system cache or go to disk.
      9 #
     10 # $Id: dnlcstat,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $
     11 #
     12 # USAGE:	dnlcstat [interval [count]]
     13 #
     14 # FIELDS:
     15 #
     16 #		%hit	hit percentage for this sample
     17 #		hit	number of DNLC hits in this sample
     18 #		miss	number of DNLC misses in this sample
     19 #
     20 # SEE ALSO: 	CacheKit, http://www.brendangregg.com/cachekit.html
     21 #		(contains a dnlcstat written in Perl, which uses less CPU)
     22 #
     23 # COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
     24 #
     25 # CDDL HEADER START
     26 #
     27 #  The contents of this file are subject to the terms of the
     28 #  Common Development and Distribution License, Version 1.0 only
     29 #  (the "License").  You may not use this file except in compliance
     30 #  with the License.
     31 #
     32 #  You can obtain a copy of the license at Docs/cddl1.txt
     33 #  or http://www.opensolaris.org/os/licensing.
     34 #  See the License for the specific language governing permissions
     35 #  and limitations under the License.
     36 #
     37 # CDDL HEADER END
     38 #
     39 # 27-Mar-2004	Brendan Gregg	Created this.
     40 # 14-Jun-2005	   "      "  	Updated style.
     41 # 14-Jun-2005	   "      "  	Last update.
     42 #
     43 
     44 ##############################
     45 # --- Process Arguments ---
     46 #
     47 
     48 ### default values
     49 interval=1; count=-1
     50 
     51 ### check arguments
     52 if [ "$1" = "-h" -o "$1" = "--help" ]; then
     53 	cat <<-END >&2
     54 	USAGE: dnlcstat [interval [count]]
     55 	       dnlcstat          # 1 second samples, infinite
     56 	  eg,
     57 	       dnlcstat 1        # print every 1 second
     58 	       dnlcstat 5 6      # print every 5 seconds, 6 times
     59 	END
     60         exit 1
     61 fi
     62 
     63 ### argument logic
     64 if [ "$1" -gt 0 ]; then
     65         interval=$1; count=-1; shift
     66 fi
     67 if [ "$1" -gt 0 ]; then
     68         count=$1; shift
     69 fi
     70 if [ $interval -eq 0 ]; then
     71         interval=1
     72 fi
     73 
     74 
     75 #################################
     76 # --- Main Program, DTrace ---
     77 #
     78 /usr/sbin/dtrace -n '
     79  #pragma D option quiet
     80 
     81  /*
     82   * Command line arguments
     83   */
     84  inline int INTERVAL   = '$interval';
     85  inline int COUNTER    = '$count';
     86  inline int SCREEN = 21;
     87 
     88  int hits;			/* hits */
     89  int misses;			/* misses */
     90 
     91  /*
     92   * Initialise variables
     93   */
     94  dtrace:::BEGIN
     95  {
     96 	lines = SCREEN + 1;
     97 	counts = COUNTER;
     98 	secs = INTERVAL;
     99 	first = 1;
    100  }
    101 
    102  /*
    103   * Print header
    104   */
    105  dtrace:::BEGIN,
    106  tick-1sec
    107  /first || (secs == 0 && lines > SCREEN)/
    108  { 
    109 	printf("%10s %8s %8s\n","dnlc  %hit","hit","miss");
    110 	lines = 0;
    111 	first = 0;
    112  }
    113 
    114  /*
    115   * Probe DNLC lookups
    116   */
    117  fbt:genunix:dnlc_lookup:return
    118  {
    119 	hits   += arg1 == 0 ? 0 : 1;
    120 	misses += arg1 == 0 ? 1 : 0;
    121  }
    122 
    123  profile:::tick-1sec
    124  {
    125         secs--;
    126  }
    127 
    128 
    129  /*
    130   * Print output line
    131   */
    132  profile:::tick-1sec
    133  /secs == 0/
    134  {
    135 	/* calculate hit percent */
    136 	this->divide = misses + hits == 0 ? 1 : misses + hits;
    137 	ratio = hits * 100 / this->divide;
    138 
    139 	/* print output */
    140 	printf("%10d %8d %8d\n",ratio,hits,misses);
    141 
    142 	/* clear counters */
    143 	hits = 0;
    144 	misses = 0;
    145 
    146         /* process counts */
    147         secs = INTERVAL;
    148         counts--;
    149         lines++;
    150 
    151  }
    152 
    153  /*
    154   * End
    155   */
    156  profile:::tick-1sec
    157  /counts == 0/
    158  {
    159         exit(0);
    160  }
    161 '
    162 
    163