bpf-tracing: Rich diagnostics for eBPF
This is a tracing facility for eBPF that produces rich, event-based diagnostic information. Similar to bpftool, it reads the kernel's tracefs file system, parses the logs and emits them conveniently using the tracing crate.
Usage
To use bpf-tracing, add the following to your Cargo.toml:
[]
= "0.0.1"
[]
= "0.0.2"
Next, in your build.rs script, provide the bpf_tracing_include arguments to clang as follows:
let mut args = vec!;
args.extend;
new
.source
.clang_args
.build_and_generate
.unwrap;
clang_args_from_env reads the BPF_LOG environment variable, and falls back to RUST_LOG if it's not set. Note that bpf-tracing disables tracing at compile time, since logging is expensive in eBPF. Note that this example uses libbpf-rs, but other libraries work just as well.
In your eBPF program, you can now include the bpf_tracing.h header and call tracing functions.
int
Finally, in your Rust program, you'll have to enable bpf-tracing. It then starts reading the tracefs file system and continuously emits the tracing events.
try_init?;
License
This project is licensed under the GPL-3.0 license.