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