tcplife.bt(8)
β¨ tcplife.bt β the manual page, but make it cute β¨
okay bestie, so this is tcplife.bt(8) from the System Manager's Manual, and it's literally the most main-character way to watch TCP sessions be born and die. let's get into it π
πΈ NAME πΈ
tcplife.bt β trace TCP session lifespans with connection details. uses bpftrace/eBPF. no cap.
π SYNOPSIS π
tcplife
that's it. that's the whole vibe. one word and she's off π¦
π DESCRIPTION π
so this tool shows you the lifespan of TCP sessions that open and close while tracing, plus the duration and throughput statistics. it's giving full glow-up, full lifecycle, start to finish π
and because it's efficient (she's not doing the most, she's doing the right amount), this tool only instruments TCP state changes, rather than all packets. obsessed.
the way it works: it uses the sock:inet_sock_set_state tracepoint, which was added in Linux 4.16. periodt.
Since this uses BPF, only the root user can use this tool. like, root or nothing, bestie. π
β REQUIREMENTS β
CONFIG_BPFbpftrace- the
sock:inet_sock_set_statetracepoint (Linux 4.16+)
that's the whole checklist, you got this π«Ά
π EXAMPLES π
show TCP sessions with details:
# tcplife.bt
boom. iconic. β¨
π₯ FIELDS π₯
here's the tea on every column she prints:
PIDβ Process IDCOMMβ Process nameLADDRβ Local IP address.LPORTβ Local port.RADDRβ Remote IP address.RPORTβ Remote port.TX_KBβ Total transmitted Kbytes.RX_KBβ Total received Kbytes.MSβ Lifespan of the session, in milliseconds.
nine columns of pure information π
π OVERHEAD π
ngl, this one matters. this traces the kernel TCP set state function, which should be called much less often than send/receive tracing, and therefore has lower overhead. so like, lowkey chill.
but the overhead of the tool is relative to the rate of new TCP sessions: if this is high, over 10,000 per second, then there may be noticeable overhead just to print out 10k lines of formatted output per second. that's a LOT of lines, bestie, she's typing as fast as she can π
you can find out the rate of new TCP sessions using "sar -n TCP 1", and adding the active/s and passive/s columns. do the math, it's giving arithmetic.
As always, test and understand this tools overhead for your types of workloads before production use. fr fr, don't skip this step. π¨
π§ SOURCE π§
this tool originated from BCC:
https://github.com/iovisor/bcc
the BCC version has many command line options for customizing the output. she's got range.
this bpftrace version originated from the book "BPF Performance Tools", published by Addison Wesley (2019):
http://www.brendangregg.com/bpf-performance-tools-book.html
see the book for more documentation on this tool. it's a whole read, highly recommend π
this bpftrace version is in the bpftrace repository:
https://github.com/bpftrace/bpftrace
also look in the bpftrace distribution for a companion _examples.txt file containing example usage, output, and commentary for this tool. iykyk π
π OS π
Linux. obviously. π§
π«Ά STABILITY π«Ά
Unstable β in development.
she's still growing, okay?? we love a work in progress π±
π AUTHOR π
Brendan Gregg
the legend himself. we stan. π β¨
πΈ SEE ALSO πΈ
and that's the whole page, bestie π¦π
cute sign-off: this page came from USER COMMANDS, dated 2019-07-03, and it's filed under the name tcplife.bt(8) β go forth and trace those lifespans, you've got this πβ¨π
π¦ where this page comes from
- alpine 3.24: bpftrace-tools-doc 0.26.1-r0 Β· Apache-2.0
- arch rolling: bpftrace 0.27.0-2 Β· Apache-2.0
- centos-stream 10: bpftrace 0.26.1-1.el10 Β· Apache-2.0
- centos-stream 9: bpftrace 0.26.1-1.el9 Β· ASL 2.0
- nixos 26.05: bpftrace 0.25.1
- nixpkgs unstable: bpftrace 0.27.1
- ubuntu resolute: bpftrace 0.25.0-1ubuntu1 Β· Apache-2.0
- ubuntu stonking: bpftrace 0.25.0-1ubuntu2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms