libbpf-async
A library for writing BPF programs in Async Rust, complementary for libbpf-rs, Rust wrapper for libbpf.
Currently, this provides Async-friendly APIs for BPF ring buffer.
To use in your project, add into your Cargo.toml
:
[dependencies]
libbpf-async = "0.1"
Example
#[tokio::main]
async fn main() {
let mut builder = TracerSkelBuilder::default();
let mut skel = builder.open().unwrap().load().unwrap();
let mut rb = libbpf_async::RingBuffer::new(skel.obj.map_mut("ringbuf").unwrap());
loop {
let mut buf = [0; 128];
let n = rb.read(&mut buf).await.unwrap();
// do something useful with the buffer
}
}
A working example code can be found here.