3 # vopstat - Trace the vnode interface.
4 # Written using DTrace (Solaris 10 3/05)
6 # Author: Richard McDougall
8 # $Id: vopstat 3 2007-08-01 10:50:08Z brendan $
10 # USAGE: vopstat [-t] [/mountname]
12 # vopstat # default output, summary each 5 secs
13 # -t # trace activity as it occurs
19 # VOP Physical IO Count
38 # VOP Wall Time mSeconds
54 # COPYRIGHT: Copyright (c) 2006 Richard McDougall
58 # The contents of this file are subject to the terms of the
59 # Common Development and Distribution License, Version 1.0 only
60 # (the "License"). You may not use this file except in compliance
63 # You can obtain a copy of the license at Docs/cddl1.txt
64 # or http://www.opensolaris.org/os/licensing.
65 # See the License for the specific language governing permissions
66 # and limitations under the License.
70 # Shell Wrapper Concept by Brendan Gregg
72 # 08-Jan-2006 Richard McDougall Created this.
73 # 23-Apr-2006 Brendan Gregg Minor style tweaks.
74 # 23-Apr-2006 " " Last update.
77 ##############################
78 # --- Process Arguments ---
82 opt_trace=0; opt_fs=0; opt_stats=1; opt_all=0
90 USAGE: voptrace [-t] [/mountpoint]
91 voptrace # default output
94 voptrace -t # trace all file systems
95 voptrace -t /tmp # trace /tmp
96 voptrace /tmp # summary stats for /tmp
101 shift `expr $OPTIND - 1`
105 if [ $opt_trace -eq 1 ]; then
108 if [ -z "$filesys" ]; then
112 #################################
113 # --- Main Program, DTrace ---
115 /usr/sbin/dtrace -n '
117 * Command line arguments
119 inline int OPT_fs = '$opt_fs';
120 inline int OPT_all = '$opt_all';
121 inline int OPT_trace = '$opt_trace';
122 inline int OPT_stats = '$opt_stats';
123 inline string FILESYS = "'$filesys'";
125 #pragma D option quiet
134 /* print main headers */
136 printf("\033[H\033[2J") : 1;
139 printf("%2s %-15s %-10s %51s %2s %8s %8s\n",
140 "", "Event", "Device", "Path", "RW", "Size", "Offset") : 1;
148 /* make D compiler happy */
149 @vop_iocnt[""] = count();
150 @vop_cnt[""] = count();
151 @vop_time[""] = sum(0);
161 /* Get vp: fop_open has a pointer to vp */
162 this->vpp = (vnode_t **)arg0;
163 self->vp = (vnode_t *)arg0;
164 self->vp = probefunc == "fop_open" ? (vnode_t *)*this->vpp : self->vp;
166 /* And the containing vfs */
167 this->vfsp = self->vp ? self->vp->v_vfsp : 0;
169 /* And the paths for the vp and containing vfs */
170 this->vfsvp = this->vfsp ?
171 (struct vnode *)((vfs_t *)this->vfsp)->vfs_vnodecovered : 0;
172 self->vfspath = this->vfsvp ? stringof(this->vfsvp->v_path) : "unknown";
174 /* Check if we should trace the root fs */
176 (FILESYS == "/" && this->vfsp &&
177 (this->vfsp == `rootvfs))) ? self->trace = 1 : self->trace;
179 /* Check if we should trace the fs */
180 (OPT_all || (self->vfspath == FILESYS)) ? self->trace = 1 : self->trace;
186 * Trace the entry point to each fop
191 self->path = (self->vp != NULL && self->vp->v_path) ?
192 stringof(self->vp->v_path) : "unknown";
194 /* Some fops has the len in arg2 */
195 (probefunc == "fop_getpage" ||
196 probefunc == "fop_putpage" ||
197 probefunc == "fop_none") ? self->len = arg2 : 1;
199 /* Some fops has the len in arg3 */
200 (probefunc == "fop_pageio" ||
201 probefunc == "fop_none") ? self->len = arg3 : 1;
203 /* Some fops has the len in arg4 */
204 (probefunc == "fop_addmap" ||
205 probefunc == "fop_map" ||
206 probefunc == "fop_delmap") ? self->len = arg4 : 1;
208 /* Some fops has the offset in arg1 */
209 (probefunc == "fop_addmap" ||
210 probefunc == "fop_map" ||
211 probefunc == "fop_getpage" ||
212 probefunc == "fop_putpage" ||
213 probefunc == "fop_seek" ||
214 probefunc == "fop_delmap") ? self->off = arg1 : 1;
216 /* Some fops has the offset in arg3 */
217 (probefunc == "fop_close" ||
218 probefunc == "fop_pageio") ? self->off = arg3 : 1;
220 /* Some fops has the offset in arg4 */
221 probefunc == "fop_frlock" ? self->off = arg4 : 1;
223 /* Some fops has the pathname in arg1 */
224 self->path = (probefunc == "fop_create" ||
225 probefunc == "fop_mkdir" ||
226 probefunc == "fop_rmdir" ||
227 probefunc == "fop_remove" ||
228 probefunc == "fop_lookup") ?
229 strjoin(self->path, strjoin("/", stringof(arg1))) : self->path;
232 printf("%2s %-15s %-10s %51s %2s %8d %8d\n",
233 "->", probefunc, "-", self->path, "-",
234 self->len, self->off) : 1;
236 self->type = probefunc;
237 self->vop_entry[probefunc] = timestamp;
244 printf("%2s %-15s %-10s %51s %2s %8d %8d\n",
245 "<-", probefunc, "-", self->path, "-",
246 self->len, self->off) : 1;
249 @vop_time[probefunc] =
250 sum(timestamp - self->vop_entry[probefunc]) : 1;
252 @vop_cnt[probefunc] = count() : 1;
266 /* Capture any I/O within this fop */
271 @vop_iocnt[self->type] = count() : 1;
274 printf("%2s %-15s %-10s %51s %2s %8d %8u\n",
275 "--", self->type, args[1]->dev_statname,
276 self->path, args[0]->b_flags & B_READ ? "R" : "W",
277 args[0]->b_bcount, args[0]->b_blkno) : 1;
283 /* Print top 20 only */
284 trunc(@vop_iocnt, 20);
285 trunc(@vop_time, 20);
287 /* Display microseconds */
288 normalize(@vop_time, 1000000);
289 printf("\033[H\033[2J");
290 printf("%-60s %10s\n", "VOP Physical IO", "Count");
291 printa("%-60s %10@d\n", @vop_iocnt);
293 printf("%-60s %10s\n", "VOP Count", "Count");
294 printa("%-60s %10@d\n", @vop_cnt);
296 printf("%-60s %10s\n", "VOP Wall Time", "mSeconds");
297 printa("%-60s %10@d\n", @vop_time);