How to show the sent TCP packet sizes on FreeBSD using Dtrace


June 2013.
How to show the sent TCP packet sizes on FreeBSD using Dtrace, grouped by program name.

As of 2013-06-19, the DTrace TCP provider is not available in FreeBSD, so we need a workaround.


#!/usr/sbin/dtrace -s

fbt::tcp_usr_send:entry
{
this->mh_len = args[2]->m_hdr.mh_len;
@[execname] = quantize(this->mh_len);
}

Sample output:

httpd
value ------------- Distribution ------------- count
2 | 0
4 |@ 30
8 | 0
16 |@ 56
32 | 2
64 |@@@ 136
128 |@@@@@ 201
256 |@@@ 131
512 |@@@ 133
1024 |@ 23
2048 | 19
4096 |@@@@@@@@@@@@@@@@@@@@@@ 905
8192 | 0

mysqld
value ------------- Distribution ------------- count
2 | 0
4 | 4
8 |@@ 67
16 | 0
32 |@ 30
64 |@@ 90
128 |@@ 84
256 |@ 27
512 |@ 50
1024 |@ 34
2048 |@ 35
4096 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1330
8192 | 0

nginx
value ------------- Distribution ------------- count
0 | 0
1 | 1
2 | 0
4 | 27
8 | 12
16 | 24
32 |@ 61
64 |@@@ 191
128 |@@@@ 278
256 |@@ 158
512 |@@@@ 325
1024 |@ 92
2048 |@ 86
4096 |@@@@@@@@@@@@@@@@@@@@@@@ 1766
8192 | 0

hostmaster1#

System:

FreeBSD hostmaster1.example.com 9.1-STABLE FreeBSD 9.1-STABLE #0 r248486: Thu Jun 13 00:23:59 CEST 2013 root@hostmaster1.example.com:/usr/obj/usr/src/sys/HOSTMASTER1 amd64