ktracepoint
A Rust crate for implementing tracepoints in kernel. This crate provides a flexible and efficient way to add tracing capabilities to your kernel, similar to Linux kernel's tracepoint mechanism.
Features
- Define and manage kernel tracepoints with custom event data
- Hierarchical organization of tracepoints through subsystems
- Thread-safe implementation using mutexes
- Configurable tracepoint enable/disable functionality
- Customizable trace record formatting
- Support for tracing pipe for collecting trace records
- No-std compatible for kernel space usage
Usage
Basic Example
use Mutex;
use ;
// Define kernel operations
pub static TRACE_RAW_PIPE: =
new;
;
// Define tracepoint
define_event_trace!;
// Use the tracepoint in kernel code
See example in examples/usage.rs for a complete example.
Managing Tracepoints
// Initialize the tracing system in kernel module
let manager = .unwrap;
// Enable/disable tracepoints
let subsystem = manager.get_subsystem.unwrap;
let tracepoint_info = subsystem.get_event.unwrap;
tracepoint_info.enable_file.write; // Enable
tracepoint_info.enable_file.write; // Disable
// other operations
let tracepoint_map = manager.tracepoint_map;
// Iterate over all tracepoints
for in tracepoint_map.iter
Examples
See examples/usage.rs for a complete example of defining and using tracepoints.
cd examples
cargo run --example usage
Architecture
The crate provides several key components:
TracingEventsManager: Manages subsystems and their tracepointsEventsSubsystem: Groups related tracepointsEventInfo: Contains tracepoint metadata and controlTracePointEnableFile: Controls tracepoint enable/disable stateKernelTraceOps: Trait for implementing kernel-level operations
Safety
This crate is designed for kernel space usage and:
- Uses
#![no_std]for kernel compatibility - Provides safe abstractions for kernel tracepoint management
Example
- See DragonOS tracepoint for more details.
- See Hermit tracepoint for more details.