]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Proc/rwbbypid.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Proc / rwbbypid.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * rwbbypid.d - read/write bytes by PID.
4  *              Written using DTrace (Solaris 10 3/05)
5  *
6  * This script tracks the bytes read and written at the syscall level
7  * by processes, printing the totals in a report. This is tracking the
8  * successful number of bytes read or written.
9  *
10  * $Id: rwbbypid.d 3 2007-08-01 10:50:08Z brendan $
11  *
12  * USAGE:       rwbbypid.d              # hit Ctrl-C to end sample
13  *
14  * FIELDS:
15  *              PID             process ID
16  *              CMD             process name
17  *              DIR             direction, Read or Write
18  *              BYTES           total bytes
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  * 28-Jun-2005  Brendan Gregg   Created this.
37  * 20-Apr-2006     "      "     Last update.
38  */
39
40 #pragma D option quiet
41
42 dtrace:::BEGIN
43 {
44         printf("Tracing... Hit Ctrl-C to end.\n");
45 }
46
47 sysinfo:::readch
48 {
49         @bytes[pid, execname, "R"] = sum(arg0);
50 }
51
52 sysinfo:::writech
53 {
54         @bytes[pid, execname, "W"] = sum(arg0);
55 }
56
57 dtrace:::END
58 {
59         printf("%6s %-24s %4s %16s\n", "PID", "CMD", "DIR", "BYTES");
60         printa("%6d %-24s %4s %@16d\n", @bytes);
61 }