Project-specific review guidelines for bpftop. Reviewers (human and automated) should check these in addition to general code quality.
- Every
unsafeblock has a// SAFETY:comment that explains the invariant. - FFI boundaries (libbpf-rs, libbpf-sys) validate pointers and return codes
before use. No unchecked
ptr::readon user-influenced data. - File descriptors from BPF syscalls are wrapped in
OwnedFdso they cannot leak on error paths. - No
unwrap()orexpect()on fallible operations in runtime code paths. Useanyhowcontext instead.Mutex::lock().unwrap()is acceptable (poisoned locks indicate a bug). Tests may useunwrap().
- Changes to
src/bpf/pid_iter.bpf.cmust remain verifier-friendly: bounded loops, no unbounded memory access, only approved BPF helpers. - Do not edit
pid_iter.skel.rs— it is generated bybuild.rs. - If adding new BPF maps or programs, update the skeleton builder in
build.rs.
- This tool collects stats every second in a hot loop. Avoid allocations in
the per-tick update path (
app.rsupdate logic,bpf_program.rsstat collection). - Sorting and filtering happen on every frame. Keep the data set small and the comparisons cheap.
- Do not hold locks or block on I/O in the render path.
- UI code lives in
src/main.rs(rendering) andsrc/app.rs(state). Render functions take&mut Appfor scroll state and graph bounds, but should not perform I/O or modify application-level state beyond what the UI needs to display the current frame. - New widgets or views should follow the existing pattern: state in
App, rendering in a dedicated function called from the main draw closure. - Test that the UI does not panic on zero-length data (no BPF programs loaded, empty filter results).
- CI builds for both
x86_64-unknown-linux-gnuandaarch64-unknown-linux-gnu. Do not add platform-specific code without gating it behind#[cfg(target_arch = ...)]. - New dependencies must support both targets. Check before adding.
- Build changes must work with
cargoon both x86_64 and aarch64.
- Keep the dependency footprint small. This ships as a single static binary.
- New crates need justification — prefer the standard library or existing dependencies when possible.
- Flag any new crate that uses
unsafeor includes abuild.rswith native compilation.