pub trait Profiler: Send + Sync {
// Required methods
fn enabled(&self, target: &str) -> bool;
fn enter(&self, data: &SpanData) -> SpanId;
fn exit(&self, id: SpanId, elapsed_ns: u64);
fn counter(&self, name: &'static str, value: u64);
fn histogram(&self, name: &'static str, value_us: u64);
}Expand description
Profiler trait - kernel defines mechanism, drivers implement policy.
Following the Logger pattern: the kernel provides the trait interface,
and drivers (e.g., shared/trace/) implement it with the tracing
ecosystem.
§Thread Safety
Implementations must be Send + Sync as the profiler is accessed from
multiple threads concurrently. Implementations should minimize locking
to avoid blocking hot paths.
§Example
use reovim_kernel::api::v1::*;
struct MyProfiler;
impl Profiler for MyProfiler {
fn enabled(&self, _target: &str) -> bool {
true // Always enabled
}
fn enter(&self, data: &SpanData) -> SpanId {
println!("Entering span: {}", data.name);
data.id
}
fn exit(&self, _id: SpanId, elapsed_ns: u64) {
println!("Exiting span, elapsed: {}ns", elapsed_ns);
}
fn counter(&self, name: &'static str, value: u64) {
println!("Counter {}: {}", name, value);
}
fn histogram(&self, name: &'static str, value_us: u64) {
println!("Histogram {}: {}us", name, value_us);
}
}Required Methods§
Sourcefn enabled(&self, target: &str) -> bool
fn enabled(&self, target: &str) -> bool
Check if profiling is enabled for the given target.
Called before creating a span to avoid allocation overhead.
If this returns false, ProfileScope will be a no-op.
§Arguments
target- The module/target path (e.g.,runner::input)
Sourcefn exit(&self, id: SpanId, elapsed_ns: u64)
fn exit(&self, id: SpanId, elapsed_ns: u64)
Exit a span with timing information.
Called when a profiling scope ends. The driver should record the elapsed time and close the span.
§Arguments
id- The span ID returned fromenter()elapsed_ns- Elapsed time in nanoseconds