pub struct Profiler { /* private fields */ }Expand description
A bounded, cloneable span collector. It starts no threads, keeps no global state, and reads only the clock you give it.
Implementations§
Source§impl Profiler
impl Profiler
Sourcepub fn new(clock: impl Clock + 'static, capacity: usize) -> Self
pub fn new(clock: impl Clock + 'static, capacity: usize) -> Self
Keep up to capacity finished spans. Later spans are dropped and
counted, so every export shows incomplete coverage.
Sourcepub fn set_report_timing(&self, enabled: bool)
pub fn set_report_timing(&self, enabled: bool)
Time reports as well as checks, in spans started from now on.
Off by default because it reads the clock at every instrumented report.
With it on, each span records its longest ReportGap.
DiagnosticPulse turns it on.
Sourcepub fn metadata(&self, key: impl Into<String>, value: impl Into<String>)
pub fn metadata(&self, key: impl Into<String>, value: impl Into<String>)
Record a key/value pair, such as a configuration or build identity. A repeated key replaces the earlier value.
Sourcepub fn span(
&self,
node: impl Into<Option<NodeId>>,
task: impl Into<String>,
kind: SpanKind,
) -> Span
pub fn span( &self, node: impl Into<Option<NodeId>>, task: impl Into<String>, kind: SpanKind, ) -> Span
Start a span for one task. node ties it to a progress-tree phase; pass
None for work outside a tree.
use how_far_along::{Outcome, Unstoppable};
use how_far_really::profile::{Profiler, SpanKind, StdClock};
let profiler = Profiler::new(StdClock::new(), 16);
let span = profiler.span(None, "decode", SpanKind::Work);
let stop = span.instrument(Unstoppable);
// decode(&input, &stop)?;
span.finish(Outcome::Succeeded);
assert_eq!(profiler.snapshot().spans.len(), 1);Sourcepub fn measure_callback<R>(
&self,
task: impl Into<String>,
callback: impl FnOnce() -> R,
) -> R
pub fn measure_callback<R>( &self, task: impl Into<String>, callback: impl FnOnce() -> R, ) -> R
Run one callback inside a Callback span. A panic records the span as
abandoned and keeps unwinding.
Sourcepub fn cancellation_requested(&self)
pub fn cancellation_requested(&self)
Record when cancellation was actually requested. Call it next to the application’s cancel call, not when a callback notices.
Sourcepub fn operation_returned(&self)
pub fn operation_returned(&self)
Record when the operation returned, after every worker joined and cleanup finished.
Sourcepub fn snapshot(&self) -> Trace
pub fn snapshot(&self) -> Trace
Copy the finished spans. Active and dropped counts show what is missing.
Sourcepub fn try_snapshot(&self) -> Option<Trace>
pub fn try_snapshot(&self) -> Option<Trace>
snapshot without waiting: None if another thread
holds the collector’s lock. UI threads keep their last trace and retry.