xref: /titanic_41/usr/src/cmd/dtrace/demo/tcp/tcpbytesstat.d (revision 9cd928fe5e3ea4e05f64cfb380beb54b2623e7dc)
1*9cd928feSAlan Maguire #!/usr/sbin/dtrace -s
2*9cd928feSAlan Maguire /*
3*9cd928feSAlan Maguire  * CDDL HEADER START
4*9cd928feSAlan Maguire  *
5*9cd928feSAlan Maguire  * The contents of this file are subject to the terms of the
6*9cd928feSAlan Maguire  * Common Development and Distribution License (the "License").
7*9cd928feSAlan Maguire  * You may not use this file except in compliance with the License.
8*9cd928feSAlan Maguire  *
9*9cd928feSAlan Maguire  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*9cd928feSAlan Maguire  * or http://www.opensolaris.org/os/licensing.
11*9cd928feSAlan Maguire  * See the License for the specific language governing permissions
12*9cd928feSAlan Maguire  * and limitations under the License.
13*9cd928feSAlan Maguire  *
14*9cd928feSAlan Maguire  * When distributing Covered Code, include this CDDL HEADER in each
15*9cd928feSAlan Maguire  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*9cd928feSAlan Maguire  * If applicable, add the following below this CDDL HEADER, with the
17*9cd928feSAlan Maguire  * fields enclosed by brackets "[]" replaced with your own identifying
18*9cd928feSAlan Maguire  * information: Portions Copyright [yyyy] [name of copyright owner]
19*9cd928feSAlan Maguire  *
20*9cd928feSAlan Maguire  * CDDL HEADER END
21*9cd928feSAlan Maguire  */
22*9cd928feSAlan Maguire /*
23*9cd928feSAlan Maguire  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*9cd928feSAlan Maguire  */
25*9cd928feSAlan Maguire 
26*9cd928feSAlan Maguire #pragma D option quiet
27*9cd928feSAlan Maguire 
28*9cd928feSAlan Maguire tcp:::receive
29*9cd928feSAlan Maguire {
30*9cd928feSAlan Maguire 	@bytes[args[2]->ip_saddr, args[4]->tcp_dport] =
31*9cd928feSAlan Maguire 	    sum(args[2]->ip_plength - args[4]->tcp_offset);
32*9cd928feSAlan Maguire }
33*9cd928feSAlan Maguire 
34*9cd928feSAlan Maguire tcp:::send
35*9cd928feSAlan Maguire {
36*9cd928feSAlan Maguire 	@bytes[args[2]->ip_daddr, args[4]->tcp_sport] =
37*9cd928feSAlan Maguire 	    sum(args[2]->ip_plength - args[4]->tcp_offset);
38*9cd928feSAlan Maguire }
39*9cd928feSAlan Maguire 
40*9cd928feSAlan Maguire profile:::tick-1sec
41*9cd928feSAlan Maguire {
42*9cd928feSAlan Maguire 	printf("\n   %-32s %16s\n", "HOST", "BYTES/s");
43*9cd928feSAlan Maguire 	printa("   %-32s %@16d\n", @bytes);
44*9cd928feSAlan Maguire 	trunc(@bytes);
45*9cd928feSAlan Maguire }
46