tcplife.bt(8)
π tcplife.bt β the manual page, bestie edition π
okay so you found the tcplife.bt(8) page in the System Manager's Manual section and you're like "what is this". don't worry. I got you. no cap, this is one of my faves π«Ά
β¨ NAME β¨
tcplife.bt β trace TCP session lifespans with connection details. uses bpftrace/eBPF. it's giving "watch your TCP babies be born and also watch them leave" π
πΈ SYNOPSIS πΈ
tcplife
that's it. that's the whole vibe. no args, no flags, just run it π
π¦ DESCRIPTION π¦
okay so listen. this tool shows you the lifespan of TCP sessions that open and close while you're tracing, and it also shows the duration and throughput statistics. the way it does this is so smart: for efficiency, it only instruments TCP state changes, rather than every single packet. not me being obsessed with not doing extra work π iconic behaviour honestly.
the way it works: it uses the sock:inet_sock_set_state tracepoint, which was added in Linux 4.16. so if your kernel is ancient, this is gonna be a no from it, sorry bestie.
and because this uses BPF, only the root user can use this tool. like, root only. periodt. π₯
π REQUIREMENTS π
CONFIG_BPFbpftrace- the
sock:inet_sock_set_statetracepoint (Linux 4.16+)
miss any of these and the whole thing just does not slay, I'm sorry π
β EXAMPLES β
show TCP sessions with details:
# tcplife.bt
that's the entire example. chef's kiss. it just works β¨
π FIELDS π
PIDβ process IDCOMMβ process nameLADDRβ local IP address.DADDRβ remote IP address.LPORTβ local port.RPORTβ remote port.TX_KBβ total transmitted Kbytes.RX_KBβ total received Kbytes.MSβ lifespan of the session, in milliseconds.
nine fields. all bangers. no filler π§
π OVERHEAD π
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 that's the good news bestie π
but β and this is important β the overhead of the tool is relative to the rate of new TCP sessions. if that rate is high, over 10,000 per second, then there may be noticeable overhead just to print out 10k lines of formatted output per second. like, the printing alone. not even the tracing. the printing π
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 that. it's your vibe check π
as always, test and understand this tool's overhead for your types of workloads before production use. I am literally begging you. production is not the place to find out π
π SOURCE π
this tool originated from BCC:
https://github.com/iovisor/bcc
the BCC version has many command line options for customizing the output. (this one does not. we keep it simple here. minimalism era π )
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/iovisor/bpftrace
also look in the bpftrace distribution for a companion _examples.txt file containing example usage, output, and commentary for this tool. lowkey the commentary is the best part π
π OS π
Linux
just linux. that's the whole section. iykyk π§
π STABILITY π
Unstable β in development.
so like... it works, but it's still growing. be nice to it. it's doing its best π₯Ί
πΈ AUTHOR πΈ
Brendan Gregg
legend. icon. the moment. main character energy fr fr π
π SEE ALSO π
and that's the whole page bestie!! this came from USER COMMANDS, dated 2019-07-03, and it's the tcplife.bt(8) page β go trace some sessions, you got this, mwah π
β¨ππ¦
π¦ where this page comes from
- debian bookworm: bpftrace 0.17.0-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms