xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Proc/rwbytype.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * rwbytype.d - read/write bytes by vnode type.
4  *              Written using DTrace (Solaris 10 3/05).
5  *
6  * This program identifies the vnode type of read/write activity - whether
7  * that is for regular files, sockets, character special devices, etc.
8  *
9  * $Id: rwbytype.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
10  *
11  * USAGE:       rwbytype.d    # hit Ctrl-C to end sample
12  *
13  * FIELDS:
14  *		PID		number of rwbytype
15  *		CMD		process name
16  *		VTYPE		vnode type (describes I/O type)
17  *		DIR		direction (Read/Write)
18  *		BYTES		bytes transferred
19  *
20  * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
21  *
22  * CDDL HEADER START
23  *
24  *  The contents of this file are subject to the terms of the
25  *  Common Development and Distribution License, Version 1.0 only
26  *  (the "License").  You may not use this file except in compliance
27  *  with the License.
28  *
29  *  You can obtain a copy of the license at Docs/cddl1.txt
30  *  or http://www.opensolaris.org/os/licensing.
31  *  See the License for the specific language governing permissions
32  *  and limitations under the License.
33  *
34  * CDDL HEADER END
35  *
36  * 18-Oct-2005  Brendan Gregg   Created this.
37  * 20-Apr-2006	   "      "	Last update.
38  */
39 
40 #pragma D option quiet
41 
42 typedef struct vtype2str {
43 	string code;
44 };
45 
46 translator struct vtype2str < int T > {
47 	/* the order has been picked for performance reasons */
48 	code =
49 	    T == 1 ? "reg"   :
50 	    T == 9 ? "sock"  :
51 	    T == 4 ? "chr"   :
52 	    T == 6 ? "fifo"  :
53 	    T == 8 ? "proc"  :
54 	    T == 2 ? "dir"   :
55 	    T == 3 ? "blk"   :
56 	    T == 5 ? "lnk"   :
57 	    T == 7 ? "door"  :
58 	    T == 10 ? "port" :
59 	    T == 11 ? "bad"  : "non";
60 };
61 
62 dtrace:::BEGIN
63 {
64 	printf("Tracing... Hit Ctrl-C to end.\n");
65 }
66 
67 fbt::fop_read:entry,
68 fbt::fop_write:entry
69 {
70 	self->type = xlate <struct vtype2str *>(args[0]->v_type)->code;
71 	self->size = args[1]->uio_resid;
72 	self->uiop = args[1];
73 }
74 
75 fbt::fop_read:return
76 /self->uiop/
77 {
78 	this->resid = self->uiop->uio_resid;
79 	@bytes[pid, execname, self->type, "R"] = sum(self->size - this->resid);
80 	self->type = 0;
81 	self->size = 0;
82 	self->uiop = 0;
83 }
84 
85 /* this is delibrately redundant code for performance reasons */
86 fbt::fop_write:return
87 /self->uiop/
88 {
89 	this->resid = self->uiop->uio_resid;
90 	@bytes[pid, execname, self->type, "W"] = sum(self->size - this->resid);
91 	self->type = 0;
92 	self->size = 0;
93 	self->uiop = 0;
94 }
95 
96 dtrace:::END
97 {
98 	printf("%-6s %-16s %6s %4s %9s\n",
99 	    "PID", "CMD", "VTYPE", "DIR", "BYTES");
100 	printa("%-6d %-16s %6s %4s %@9d\n", @bytes);
101 }
102