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] [-Y]
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
49 -Y Log session state changes to the systemd journal.
50
52 Trace all TCP sessions, and show all state changes:
53 # tcpstates
54
55 Include a timestamp column, and wide column output:
56 # tcpstates -tw
57
58 Trace connections to local ports 80 and 81 only:
59 # tcpstates -L 80,81
60
61 Trace connections to remote port 80 only:
62 # tcpstates -D 80
63
65 TIME Time of the change, in HH:MM:SS format.
66
67 TIME(s)
68 Time of the change, in seconds.
69
70 C-PID The current on-CPU process ID. This may show the process that
71 owns the TCP session if the state change executes in synchronous
72 process context, else it is likely to show the kernel (asynchro‐
73 nous state change).
74
75 C-COMM The current on-CPU process name. This may show the process that
76 owns the TCP session if the state change executes in synchronous
77 process context, else it is likely to show the kernel (asynchro‐
78 nous state change).
79
80 IP IP address family (4 or 6)
81
82 LADDR Local IP address.
83
84 RADDR Remote IP address.
85
86 LPORT Local port.
87
88 RPORT Remote port.
89
90 OLDSTATE
91 Previous TCP state.
92
93 NEWSTATE
94 New TCP state.
95
96 MS Duration of this state.
97
99 This traces the kernel TCP set state function, which should be called
100 much less often than send/receive tracing, and therefore have lower
101 overhead. The overhead of the tool is relative to the rate of new TCP
102 sessions: if this is high, over 10,000 per second, then there may be
103 noticeable overhead just to print out 10k lines of formatted output per
104 second.
105
106 You can find out the rate of new TCP sessions using "sar -n TCP 1", and
107 adding the active/s and passive/s columns.
108
109 As always, test and understand this tools overhead for your types of
110 workloads before production use.
111
113 This is from bcc.
114
115 https://github.com/iovisor/bcc
116
117 Also look in the bcc distribution for a companion _examples.txt file
118 containing example usage, output, and commentary for this tool.
119
121 Linux
122
124 Unstable - in development.
125
127 Brendan Gregg
128
130 tcpaccept(8), tcpconnect(8), tcptop(8), tcplife(8)
131
132
133
134USER COMMANDS 2018-03-20 tcpstates(8)