1tcpstates(8) System Manager's Manual tcpstates(8)
2
3
4
6 tcpstates - Trace TCP session state changes with durations. Uses Linux
7 eBPF/bcc.
8
10 tcpstates [-h] [-T] [-t] [-w] [-s] [-D PORTS] [-L PORTS]
11
13 This tool traces TCP session state changes while tracing, and prints
14 details including the duration in each state. This can help explain the
15 latency of TCP connections: whether the time is spent in the ESTAB‐
16 LISHED state (data transfer), or initialization state (SYN_SENT), etc.
17
18 This tool works using the sock:inet_sock_set_state tracepoint, which
19 was added to Linux 4.16. Linux 4.16 also included extra state transi‐
20 tions so that all TCP transitions could be observed by this tracepoint.
21
22 Only TCP state changes are traced, so it is expected that the overhead
23 of this tool is much lower than typical send/receive tracing.
24
25 Since this uses BPF, only the root user can use this tool.
26
28 CONFIG_BPF and bcc, and the sock:inet_sock_set_state tracepoint.
29
31 -h Print usage message.
32
33 -s Comma separated values output (parseable).
34
35 -t Include a timestamp column (seconds).
36
37 -T Include a time column (HH:MM:SS).
38
39 -w Wide column output (fits IPv6 addresses).
40
41 -L PORTS
42 Comma-separated list of local ports to trace (filtered in-ker‐
43 nel).
44
45 -D PORTS
46 Comma-separated list of destination ports to trace (filtered in-
47 kernel).
48
50 Trace all TCP sessions, and show all state changes:
51 # tcpstates
52
53 Include a timestamp column, and wide column output:
54 # tcpstates -tw
55
56 Trace connections to local ports 80 and 81 only:
57 # tcpstates -L 80,81
58
59 Trace connections to remote port 80 only:
60 # tcpstates -D 80
61
63 TIME Time of the change, in HH:MM:SS format.
64
65 TIME(s)
66 Time of the change, in seconds.
67
68 C-PID The current on-CPU process ID. This may show the process that
69 owns the TCP session if the state change executes in synchronous
70 process context, else it is likely to show the kernel (asynchro‐
71 nous state change).
72
73 C-COMM The current on-CPU process name. This may show the process that
74 owns the TCP session if the state change executes in synchronous
75 process context, else it is likely to show the kernel (asynchro‐
76 nous state change).
77
78 IP IP address family (4 or 6)
79
80 LADDR Local IP address.
81
82 DADDR Remote IP address.
83
84 LPORT Local port.
85
86 DPORT Destination port.
87
88 OLDSTATE
89 Previous TCP state.
90
91 NEWSTATE
92 New TCP state.
93
94 MS Duration of this state.
95
97 This traces the kernel TCP set state function, which should be called
98 much less often than send/receive tracing, and therefore have lower
99 overhead. The overhead of the tool is relative to the rate of new TCP
100 sessions: if this is high, over 10,000 per second, then there may be
101 noticeable overhead just to print out 10k lines of formatted output per
102 second.
103
104 You can find out the rate of new TCP sessions using "sar -n TCP 1", and
105 adding the active/s and passive/s columns.
106
107 As always, test and understand this tools overhead for your types of
108 workloads before production use.
109
111 This is from bcc.
112
113 https://github.com/iovisor/bcc
114
115 Also look in the bcc distribution for a companion _examples.txt file
116 containing example usage, output, and commentary for this tool.
117
119 Linux
120
122 Unstable - in development.
123
125 Brendan Gregg
126
128 tcpaccept(8), tcpconnect(8), tcptop(8), tcplife(8)
129
130
131
132USER COMMANDS 2018-03-20 tcpstates(8)