Want abstraction over USDT/SDT split in probes
FelixMcFelix opened this issue · comments
Kyle Simpson commented
Many of the DTrace probes we have in OPTE are structured such that they automatically switch between USDT and SDT probes depending on whether the crate is compiled for userland (cargo test
) or as part of the kernel module (xde
):
impl Port {
fn xyz_probe(&self, dir: Direction, pkt: &Packet<Parsed>, msg: String) {
cfg_if::cfg_if! {
if #[cfg(all(not(feature = "std"), not(test)))] {
/* SDT-specific arg conversion: String->CString, ... */
unsafe {
__dtrace_probe_xyz(
/* ... pointers to args ... */
);
}
} else if #[cfg(feature = "usdt")] {
/* USDT-specific arg conversion */
crate::opte_provider::xyz!(
|| (/* ... Rust-friendly args (references, owned types) ... */)
);
} else {
/* feature-flag-driven no-op */
let (..) = (dir, pkt, msg);
}
}
}
}
Many of the Port::*_probe
methods have a structure more or less in line with this, which leads to a lot of duplication and noise. We should define a macro or similar abstraction to simplify the implementation of {current, future} DTrace probes we choose to insert.