Created
May 27, 2015 17:39
-
-
Save rzezeski/d96a7f406e3ed31b6aae to your computer and use it in GitHub Desktop.
[dtrace] TCP TIME_WAIT duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
dtrace -n ' | |
#pragma D option quiet | |
BEGIN { | |
printf("%4s %21s\tDURATION (secs)\n", "ZONE", "ADDR:PORT"); | |
} | |
tcp:::state-change | |
{ | |
this->last_state = tcp_state_string[args[5]->tcps_state]; | |
this->curr_state = tcp_state_string[args[3]->tcps_state]; | |
} | |
/* Upon entering the TIME_WAIT state record the current time so that a | |
duration may be calculated when the socket is finally closed. */ | |
tcp:::state-change | |
/this->curr_state == "state-time-wait"/ | |
{ | |
this->addr = args[3]->tcps_laddr; | |
this->port = args[3]->tcps_lport; | |
this->zone_id = args[1]->cs_zoneid; | |
waiting[this->addr, this->port] = timestamp; | |
conn_zone[this->addr, this->port] = this->zone_id; | |
} | |
/* This function is called from a kernel thread that fires | |
periodically so the associated zoneid, pid, and tid will not help. | |
Thus the conn_zone map is used. */ | |
fbt::tcp_time_wait_remove:entry | |
{ | |
this->addr = inet_ntop(AF_INET, &args[0]->tcp_connp->connua_v6addr.connua_laddr._S6_un._S6_u32[3]); | |
this->port = htons(args[0]->tcp_connp->u_port.connu_ports.connu_lport); | |
this->zone_id = conn_zone[this->addr, this->port]; | |
this->duration = timestamp - waiting[this->addr, this->port]; | |
printf("%4d %16s:%-5d\t%us\n", this->zone_id, this->addr, | |
this->port, this->duration / 1000000000); | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment