3 # dnlcstat - DNLC statistics.
4 # Written in DTrace (Solaris 10 3/05).
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.
10 # $Id: dnlcstat 3 2007-08-01 10:50:08Z brendan $
12 # USAGE: dnlcstat [interval [count]]
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
20 # SEE ALSO: CacheKit, http://www.brendangregg.com/cachekit.html
21 # (contains a dnlcstat written in Perl, which uses less CPU)
23 # COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
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
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.
39 # 27-Mar-2004 Brendan Gregg Created this.
40 # 14-Jun-2005 " " Updated style.
41 # 14-Jun-2005 " " Last update.
44 ##############################
45 # --- Process Arguments ---
52 if [ "$1" = "-h" -o "$1" = "--help" ]; then
54 USAGE: dnlcstat [interval [count]]
55 dnlcstat # 1 second samples, infinite
57 dnlcstat 1 # print every 1 second
58 dnlcstat 5 6 # print every 5 seconds, 6 times
64 if [ "$1" -gt 0 ]; then
65 interval=$1; count=-1; shift
67 if [ "$1" -gt 0 ]; then
70 if [ $interval -eq 0 ]; then
75 #################################
76 # --- Main Program, DTrace ---
79 #pragma D option quiet
82 * Command line arguments
84 inline int INTERVAL = '$interval';
85 inline int COUNTER = '$count';
86 inline int SCREEN = 21;
89 int misses; /* misses */
92 * Initialise variables
107 /first || (secs == 0 && lines > SCREEN)/
109 printf("%10s %8s %8s\n","dnlc %hit","hit","miss");
117 fbt:genunix:dnlc_lookup:return
119 hits += arg1 == 0 ? 0 : 1;
120 misses += arg1 == 0 ? 1 : 0;
135 /* calculate hit percent */
136 this->divide = misses + hits == 0 ? 1 : misses + hits;
137 ratio = hits * 100 / this->divide;
140 printf("%10d %8d %8d\n",ratio,hits,misses);