Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add netns info for each connection in tcpretrans.bt #2889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tools/tcpretrans.bt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
BEGIN
{
printf("Tracing tcp retransmits. Hit Ctrl-C to end.\n");
printf("%-8s %-8s %20s %21s %6s\n", "TIME", "PID", "LADDR:LPORT",
"RADDR:RPORT", "STATE");
printf("%-8s %-8s %-10s %20s %21s %6s\n", "TIME", "PID", "NETNS",
"LADDR:LPORT", "RADDR:RPORT", "STATE");

// See include/net/tcp_states.h:
@tcp_states[1] = "ESTABLISHED";
Expand Down Expand Up @@ -71,10 +71,11 @@ kprobe:tcp_retransmit_skb

$state = $sk->__sk_common.skc_state;
$statestr = @tcp_states[$state];
$netns = $sk->__sk_common.skc_net.net->ns.inum;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fields access compatible with reasonably old kernels?


time("%H:%M:%S ");
printf("%-8d %14s:%-6d %14s:%-6d %6s\n", pid, $saddr, $lport,
$daddr, $dport, $statestr);
printf("%-8d %-10u %14s:%-6d %14s:%-6d %6s\n", pid, $netns, $saddr,
$lport, $daddr, $dport, $statestr);
}
}

Expand Down
18 changes: 9 additions & 9 deletions tools/tcpretrans_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ This tool traces the kernel TCP retransmit function to show details of these
retransmits. For example:

# ./tcpretrans.bt
TIME PID LADDR:LPORT RADDR:RPORT STATE
01:55:05 0 10.153.223.157:22 69.53.245.40:34619 ESTABLISHED
01:55:05 0 10.153.223.157:22 69.53.245.40:34619 ESTABLISHED
01:55:17 0 10.153.223.157:22 69.53.245.40:22957 ESTABLISHED
[...]
TIME PID NETNS LADDR:LPORT RADDR:RPORT STATE
21:54:32 0 4026531992 192.168.5.1:29716 192.168.5.2:80 SYN_SENT
21:54:36 0 4026531992 192.168.5.1:29718 192.168.5.2:80 SYN_SENT
21:54:36 59827 4026532261 192.168.5.2:80 192.168.5.1:29718 ESTABLISHED

This output shows three TCP retransmits, the first two were for an IPv4
connection from 10.153.223.157 port 22 to 69.53.245.40 port 34619. The TCP
state was "ESTABLISHED" at the time of the retransmit. The on-CPU PID at the
time of the retransmit is printed, in this case 0 (the kernel, which will
be the case most of the time).
connection from 192.168.5.1 to 192.168.5.2 port 80. The TCP state was
"SYN_SENT" at the time of the retransmit. The on-CPU PID at the time of
the retransmit is printed, in this case 0 (the kernel, which will
be the case most of the time). The NETNS column shows which netns this
connection belongs.

Retransmits are usually a sign of poor network health, and this tool is
useful for their investigation. Unlike using tcpdump, this tool has very
Expand Down
Loading