A Rust tracepoint library for kernel scenarios, designed with goals similar to Linux tracepoints:
- Define events and fields with macros
- Manage tracepoints by subsystem and event at runtime
- Support enable/disable, filter expressions, and callbacks
- Provide both raw event buffering and human-readable output
- no_std compatible
Repository: https://github.com/Starry-OS/tracepoint
- Event definition: use
define_event_trace!to generate event metadata, call functions, and register functions in one place - Event management:
TracingEventsManager -> subsystem -> event - Event control: enable/disable, format/id/filter
- Filter expressions: compiled and evaluated against schema via
tp-lexer - Output pipeline:
TracePipeRaw+TraceEntryParser
[dependencies]
ktracepoint = "*"
static-keys = "0.8"This library scans event metadata through __start_tracepoint / __stop_tracepoint.
Merge the content of my_section.ld into your linker script and ensure the .tracepoint section is kept with KEEP.
You need to provide:
time_nowcpu_idcurrent_pidtrace_pipe_push_raw_recordtrace_cmdline_pushwrite_kernel_text
write_kernel_text is used for static key instruction patching.
use ktracepoint::{define_event_trace, KernelTraceOps};
define_event_trace!(
TEST,
TP_lock(Mutex<()>),
TP_kops(Kops),
TP_system(tracepoint_test),
TP_PROTO(a: u32, b: u32),
TP_STRUCT__entry { a: u32, b: u32 },
TP_fast_assign { a: a, b: b },
TP_ident(__entry),
TP_printk(format_args!("a={}, b={}", __entry.a, __entry.b))
);
// Generated functions: trace_TEST / register_trace_TEST / unregister_trace_TEST
trace_TEST(1, 2);Note: TP_STRUCT__entry participates in byte layout. Ensure your field layout matches expectations (think in C layout terms).
use ktracepoint::global_init_events;
static_keys::global_init();
let manager = global_init_events::<Mutex<()>, Kops>()?;let subsystem = manager.get_subsystem("tracepoint_test").unwrap();
let event = subsystem.get_event("TEST").unwrap();
event.enable_file().write('1');
event.tracepoint().enable_event();
event.filter_file().write("a > 8 && b > 5").unwrap();
// Read format and ID
let fmt = event.format_file().read();
let id = event.id_file().read();cd examples
cargo run --example usageExample code is in examples/usage.rs, covering:
- Event definition and triggering
- Event enabling and filtering
- Registering event/raw callbacks
- Reading
TracePipeRawsnapshots and parsing them into text
KernelTraceOpsTracePoint/TracePointMapTracingEventsManager/EventsSubsystem/EventInfoTracePipeRaw/TracePipeSnapshot/TracePipeOpsTraceCmdLineCache/TraceEntryParser