]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Net/tcpstat.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Net / tcpstat.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * tcpstat.d - print TCP statistics. Uses DTrace.
4  *
5  * This prints TCP statistics every second, retrieved from the MIB provider.
6  *
7  * $Id: tcpstat.d 3 2007-08-01 10:50:08Z brendan $
8  *
9  * USAGE:       tcpstat.d
10  *
11  * FIELDS:
12  *              TCP_out         TCP bytes sent
13  *              TCP_outRe       TCP bytes retransmitted
14  *              TCP_in          TCP bytes received
15  *              TCP_inDup       TCP bytes received duplicated
16  *              TCP_inUn        TCP bytes received out of order
17  *
18  * The above TCP statistics are documented in the mib2_tcp struct
19  * in the /usr/include/inet/mib2.h file; and also in the mib provider
20  * chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223.
21  *
22  * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
23  *
24  * CDDL HEADER START
25  *
26  *  The contents of this file are subject to the terms of the
27  *  Common Development and Distribution License, Version 1.0 only
28  *  (the "License").  You may not use this file except in compliance
29  *  with the License.
30  *
31  *  You can obtain a copy of the license at Docs/cddl1.txt
32  *  or http://www.opensolaris.org/os/licensing.
33  *  See the License for the specific language governing permissions
34  *  and limitations under the License.
35  *
36  * CDDL HEADER END
37  *
38  * 15-May-2005  Brendan Gregg   Created this.
39  * 15-May-2005     "      "     Last update.
40  */
41
42 #pragma D option quiet
43
44 /*
45  * Declare Globals
46  */
47 dtrace:::BEGIN
48 {
49         TCP_out = 0; TCP_outRe = 0;
50         TCP_in = 0; TCP_inDup = 0; TCP_inUn = 0;
51         LINES = 20; line = 0;
52 }
53
54 /*
55  * Print Header
56  */
57 profile:::tick-1sec { line--; }
58
59 profile:::tick-1sec
60 /line <= 0 /
61 {
62         printf("%11s %11s %11s %11s %11s\n",
63             "TCP_out", "TCP_outRe", "TCP_in", "TCP_inDup", "TCP_inUn");
64
65         line = LINES;
66 }
67
68 /*
69  * Save Data
70  */
71 mib:::tcpOutDataBytes           { TCP_out += arg0;   }
72 mib:::tcpRetransBytes           { TCP_outRe += arg0; }
73 mib:::tcpInDataInorderBytes     { TCP_in += arg0;    }
74 mib:::tcpInDataDupBytes         { TCP_inDup += arg0; }
75 mib:::tcpInDataUnorderBytes     { TCP_inUn += arg0;  }
76
77 /*
78  * Print Output
79  */
80 profile:::tick-1sec
81 {
82         printf("%11d %11d %11d %11d %11d\n",
83             TCP_out, TCP_outRe, TCP_in, TCP_inDup, TCP_inUn);
84
85         /* clear values */
86         TCP_out   = 0;
87         TCP_outRe = 0;
88         TCP_in    = 0;
89         TCP_inDup = 0;
90         TCP_inUn  = 0;
91 }