This PR adds documentation for User-Space, Statically Defined Tracing (USDT) as well as three tracepoints (including documentation and usage examples).
Context
The TRACEx
macros for tracepoints and build system changes for USDT were merged in #19866 earlier this year. Issue #20981 contains discussion about potential tracepoints and guidelines for adding them (also documented with this PR). USDT was a topic in a core-dev-meeting discussion on 21st Jan, 2021.
- collabora.com: An eBPF overview, part 1: Introduction
- collabora.com: An eBPF overview, part 2: Machine & bytecode
- Brendan D. Gregg’s blog posts, and book on on eBPF
- Brendan D. Gregg: Linux bcc/BPF Node.js USDT Tracing
USDT? Stablecoin?
User-space, Statically Defined Tracing (USDT) allows for more observability during development, debugging, code review, and production usage. The tracepoints make it possible to keep track of custom statistics and enable detailed monitoring of otherwise hidden internals and have little to no performance impact when unused. Linux kernels (4.x or newer) can hook into the tracepoints and execute eBPF programs in a kernel VM once the tracepoint is called.
This PR includes, for example, tracepoints for in- and outbound P2P messages.
0USDT and eBPF Overview
1======================
2
3 ┌──────────────────┐ ┌──────────────┐
4 │ tracing script │ │ bitcoind │
5 │==================│ 2. │==============│
6 │ eBPF │ tracing │ hooks │ │
7 │ code │ logic │ into┌─┤►tracepoint 1─┼───┐ 3.
8 └────┬───┴──▲──────┘ ├─┤►tracepoint 2 │ │ pass args
9 1. │ │ 4. │ │ ... │ │ to eBPF
10 User compiles │ │ pass data to │ └──────────────┘ │ program
11 Space & loads │ │ tracing script │ │
12 ─────────────────┼──────┼─────────────────┼────────────────────┼───
13 Kernel │ │ │ │
14 Space ┌──┬─▼──────┴─────────────────┴────────────┐ │
15 │ │ eBPF program │◄──────┘
16 │ └───────────────────────────────────────┤
17 │ eBPF kernel Virtual Machine (sandboxed) │
18 └──────────────────────────────────────────┘
19
201. The tracing script compiles the eBPF code and loads the eBFP program into a kernel VM
212. The eBPF program hooks into one or more tracepoints
223. When the tracepoint is called, the arguments are passed to the eBPF program
234. The eBPF program processes the arguments and returns data to the tracing script
The two main eBPF front-ends with support for USDT are bpftrace an BPF Compiler Collection (BCC). BCC is used for complex tools and daemons and bpftrace
is preferred for one-liners and shorter scripts. Example tracing scripts for both are provided with this PR.
This PR adds three tracepoints:
net:inbound_message
net:outbound_message
valildation:block_connected
See doc/tracing.md
and contrib/tracing/
for documentation and example tracing scripts.
Open Questions (Not in scope for this PR)
- How to use these tracepoints under macOS?
- Release builds with USDT support?
- Should and can the tracepoints be automatically tested?
Todo (before undraft)
- bcc example showing how to read raw P2P messages up to 32kb
- document that you need
sys/sdt.h
fromsystemtap
for USDT support in Bitcoin Core (apt install systemtap-sdt-dev
on debian-like). See https://github.com/bitcoin/bitcoin/pull/19866/commits/933ab8a720cb9b3341adec4109cffb6dc5b322a5 - release notes?