1#!/usr/sbin/dtrace -s
2/*
3 * rfsio.d - read FS I/O stats, with cache miss rate.
4 *           Written using DTrace (Solaris 10 3/05)
5 *
6 * This script provides statistics on the number of reads and the bytes
7 * read from filesystems (logical), and the number of bytes read from
8 * disk (physical). A summary is printed every five seconds by filesystem.
9 *
10 * A total miss-rate is also provided for the file system cache.
11 *
12 * 23-Apr-2006, ver 0.70
13 *
14 * USAGE:	rfsio.d
15 *
16 * IDEA: Richard McDougall, Solaris Internals 2nd Ed, FS Chapter.
17 *
18 * COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
19 *
20 * CDDL HEADER START
21 *
22 *  The contents of this file are subject to the terms of the
23 *  Common Development and Distribution License, Version 1.0 only
24 *  (the "License").  You may not use this file except in compliance
25 *  with the License.
26 *
27 *  You can obtain a copy of the license at Docs/cddl1.txt
28 *  or http://www.opensolaris.org/os/licensing.
29 *  See the License for the specific language governing permissions
30 *  and limitations under the License.
31 *
32 * CDDL HEADER END
33 *
34 * 19-Mar-2006  Brendan Gregg   Created this.
35 */
36
37#pragma D option quiet
38
39self int trace;
40uint64_t lbytes;
41uint64_t pbytes;
42
43dtrace:::BEGIN
44{
45	trace("Tracing...\n");
46}
47
48fbt::fop_read:entry
49/self->trace == 0/
50{
51	self->fs_mount = args[0]->v_vfsp == `rootvfs ? "/" :
52	    args[0]->v_vfsp->vfs_vnodecovered ?
53	    stringof(args[0]->v_vfsp->vfs_vnodecovered->v_path) : NULL;
54}
55
56fbt::fop_read:entry
57/self->fs_mount != NULL/
58{
59	@rio[self->fs_mount, "logical"] = count();
60	lbytes += args[1]->uio_resid;
61	self->size = args[1]->uio_resid;
62	self->uiop = args[1];
63}
64
65fbt::fop_read:return
66/self->size/
67{
68	@rbytes[self->fs_mount, "logical"] =
69	    sum(self->size - self->uiop->uio_resid);
70	self->size = 0;
71	self->uiop = 0;
72	self->fs_mount = 0;
73}
74
75io::bdev_strategy:start
76/self->size && args[0]->b_flags & B_READ/
77{
78	@rio[self->fs_mount, "physical"] = count();
79	@rbytes[self->fs_mount, "physical"] = sum(args[0]->b_bcount);
80	pbytes += args[0]->b_bcount;
81}
82
83profile:::tick-5s
84{
85	trunc(@rio, 20);
86	trunc(@rbytes, 20);
87	printf("\033[H\033[2J");
88	printf("\nRead IOPS (count)\n");
89	printa("%-32s %10s %10@d\n", @rio);
90	printf("\nRead Bandwidth (bytes)\n");
91	printa("%-32s %10s %10@d\n", @rbytes);
92	printf("\nTotal File System miss-rate: %d%%\n",
93	    lbytes ? 100 * pbytes / lbytes : 0);
94	trunc(@rbytes);
95	trunc(@rio);
96	lbytes = pbytes = 0;
97}
98