aboutsummaryrefslogtreecommitdiff
path: root/FS/vopstat
blob: a4c5af46d7dee26a392c0bd973b21d1be2ff128c (plain) (blame)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/sh
#
# vopstat - Trace the vnode interface.
#           Written using DTrace (Solaris 10 3/05)
#
# Author: Richard McDougall
#
# $Id: vopstat 3 2007-08-01 10:50:08Z brendan $
#
# USAGE:	vopstat [-t] [/mountname]
#
#		vopstat		# default output, summary each 5 secs
#		-t 		# trace activity as it occurs
#
# Example:
#
# ./vopstat
# 
# VOP Physical IO                                                   Count
# fop_fsync                                                           236
# 
# VOP Count                                                         Count
# fop_create                                                            1
# fop_fid                                                               1
# fop_lookup                                                            2
# fop_access                                                            3
# fop_read                                                              3
# fop_poll                                                             11
# fop_fsync                                                            31
# fop_putpage                                                          32
# fop_ioctl                                                           115
# fop_write                                                           517
# fop_rwlock                                                          520
# fop_rwunlock                                                        520
# fop_inactive                                                        529
# fop_getattr                                                        1057
# 
# VOP Wall Time                                                  mSeconds
# fop_fid                                                               0
# fop_access                                                            0
# fop_read                                                              0
# fop_poll                                                              0
# fop_lookup                                                            0
# fop_create                                                            0
# fop_ioctl                                                             0
# fop_putpage                                                           1
# fop_rwunlock                                                          1
# fop_rwlock                                                            1
# fop_inactive                                                          1
# fop_getattr                                                           2
# fop_write                                                            22
# fop_fsync                                                           504
# 
# COPYRIGHT: Copyright (c) 2006 Richard McDougall
#
# 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
#
# Shell Wrapper Concept by Brendan Gregg
#
# 08-Jan-2006	Richard McDougall	Created this.
# 23-Apr-2006	Brendan Gregg		Minor style tweaks.
# 23-Apr-2006	   "      "		Last update.


##############################
# --- Process Arguments ---
#

### default variables
opt_trace=0; opt_fs=0; opt_stats=1; opt_all=0

### process options
while getopts t name
do
	case $name in
	t)	opt_trace=1 ;;
	h|?)	cat <<-END >&2
		USAGE: voptrace [-t] [/mountpoint]
		        voptrace         # default output
		                 -t      # trace
		   eg,
		        voptrace -t      # trace all file systems
		        voptrace -t /tmp # trace /tmp
		        voptrace  /tmp   # summary stats for /tmp
		END
		exit 1
	esac
done
shift `expr $OPTIND - 1`
filesys="$1"

### option logic
if [ $opt_trace -eq 1 ]; then
	opt_stats=0
fi
if [ -z "$filesys" ]; then
	opt_all=1
fi

#################################
# --- Main Program, DTrace ---
#
/usr/sbin/dtrace -n '
 /*
  * Command line arguments
  */
 inline int OPT_fs 	= '$opt_fs';
 inline int OPT_all 	= '$opt_all';
 inline int OPT_trace 	= '$opt_trace';
 inline int OPT_stats 	= '$opt_stats';
 inline string FILESYS 	= "'$filesys'";
 
 #pragma D option quiet

 /*
  * Print header
  */
 dtrace:::BEGIN 
 {
	last_event[""] = 0;

	/* print main headers */
	OPT_stats == 1 ?
		printf("\033[H\033[2J") : 1;

	OPT_trace == 1 ?
		printf("%2s %-15s %-10s %51s %2s %8s %8s\n", 
		    "", "Event", "Device", "Path", "RW", "Size", "Offset") : 1;
	self->path = "";
	self->trace = 0;
 }

 dtrace:::BEGIN
 /OPT_trace == 1/
 {
	/* make D compiler happy */
	@vop_iocnt[""] = count();
	@vop_cnt[""]   = count();
	@vop_time[""]  = sum(0);
	trunc(@vop_iocnt);
	trunc(@vop_cnt);
	trunc(@vop_time);
 }
 
 fbt::fop_*:entry
 {
 	self->trace = 0;

 	/* Get vp: fop_open has a pointer to vp */
 	this->vpp = (vnode_t **)arg0;
 	self->vp = (vnode_t *)arg0;
 	self->vp = probefunc == "fop_open" ? (vnode_t *)*this->vpp : self->vp;

 	/* And the containing vfs */
         this->vfsp = self->vp ? self->vp->v_vfsp : 0;

 	/* And the paths for the vp and containing vfs */
 	this->vfsvp = this->vfsp ?
	    (struct vnode *)((vfs_t *)this->vfsp)->vfs_vnodecovered : 0;
 	self->vfspath = this->vfsvp ? stringof(this->vfsvp->v_path) : "unknown";
 
 	/* Check if we should trace the root fs */
 	(OPT_all || 
 	    (FILESYS == "/" && this->vfsp &&
 	    (this->vfsp == `rootvfs))) ? self->trace = 1 : self->trace;
 
 	/* Check if we should trace the fs */
 	(OPT_all || (self->vfspath == FILESYS)) ? self->trace = 1 : self->trace;

	self->vfspath = 0;
 }
 
 /*
  * Trace the entry point to each fop
  */ 
 fbt::fop_*:entry
 /self->trace/
 {
 	self->path = (self->vp != NULL && self->vp->v_path) ?
	    stringof(self->vp->v_path) : "unknown";
 
 	/* Some fops has the len in arg2 */
 	(probefunc == "fop_getpage" ||
 	 probefunc == "fop_putpage" ||
 	 probefunc == "fop_none") ? self->len = arg2 : 1; 
 
 	/* Some fops has the len in arg3 */
 	(probefunc == "fop_pageio" ||
 	 probefunc == "fop_none") ? self->len = arg3 : 1; 
 
 	/* Some fops has the len in arg4 */
 	(probefunc == "fop_addmap" ||
 	 probefunc == "fop_map" ||
 	 probefunc == "fop_delmap") ? self->len = arg4 : 1; 
 
 	/* Some fops has the offset in arg1 */
 	(probefunc == "fop_addmap" ||
 	 probefunc == "fop_map" ||
 	 probefunc == "fop_getpage" ||
 	 probefunc == "fop_putpage" ||
 	 probefunc == "fop_seek" ||
 	 probefunc == "fop_delmap") ? self->off = arg1 : 1; 
 
 	/* Some fops has the offset in arg3 */
 	(probefunc == "fop_close" ||
 	 probefunc == "fop_pageio") ? self->off = arg3 : 1; 
 
 	/* Some fops has the offset in arg4 */
 	probefunc == "fop_frlock" ? self->off = arg4 : 1; 
 
 	/* Some fops has the pathname in arg1 */
 	self->path = (probefunc == "fop_create" ||
 	 probefunc == "fop_mkdir" ||
 	 probefunc == "fop_rmdir" ||
 	 probefunc == "fop_remove" ||
 	 probefunc == "fop_lookup") ?
 	    strjoin(self->path, strjoin("/", stringof(arg1))) : self->path;
 
	OPT_trace ?
 		printf("%2s %-15s %-10s %51s %2s %8d %8d\n", 
 		    "->", probefunc, "-", self->path, "-",
		    self->len, self->off) : 1;

 	self->type = probefunc;
 	self->vop_entry[probefunc] = timestamp;
 }
 
 fbt::fop_*:return
 /self->trace == 1/
 {
	OPT_trace ?
 		printf("%2s %-15s %-10s %51s %2s %8d %8d\n", 
		    "<-", probefunc, "-", self->path, "-",
		    self->len, self->off) : 1;

	OPT_stats == 1 ?
 		@vop_time[probefunc] =
			sum(timestamp - self->vop_entry[probefunc]) : 1;
	OPT_stats == 1 ?
 		@vop_cnt[probefunc] = count() : 1;

	self->path = 0;
	self->len = 0;
	self->off = 0;
 }

 fbt::fop_*:return
 {
	self->trace = 0;
	self->type = 0;
	self->vp = 0;
 }
 
 /* Capture any I/O within this fop */
 io:::start
 /self->trace/
 {
	OPT_stats == 1 ?
 		@vop_iocnt[self->type] = count() : 1;

	OPT_trace == 1?
	 	printf("%2s %-15s %-10s %51s %2s %8d %8u\n",
		    "--", self->type, args[1]->dev_statname,
		    self->path, args[0]->b_flags & B_READ ? "R" : "W",
		    args[0]->b_bcount, args[0]->b_blkno) : 1;
 }
 
 profile:::tick-5s
 /OPT_stats == 1/
 {
	/* Print top 20 only */
 	trunc(@vop_iocnt, 20);
 	trunc(@vop_time, 20);

	/* Display microseconds */
 	normalize(@vop_time, 1000000);
 	printf("\033[H\033[2J");
 	printf("%-60s %10s\n", "VOP Physical IO", "Count");
 	printa("%-60s %10@d\n", @vop_iocnt);
 	printf("\n");
 	printf("%-60s %10s\n", "VOP Count", "Count");
 	printa("%-60s %10@d\n", @vop_cnt);
 	printf("\n");
 	printf("%-60s %10s\n", "VOP Wall Time", "mSeconds");
 	printa("%-60s %10@d\n", @vop_time);

	/* Clear data */
 	trunc(@vop_iocnt);
 	trunc(@vop_cnt);
 	trunc(@vop_time);
 }
'