Skip to main content

DiagnosticPulse

Struct DiagnosticPulse 

Source
pub struct DiagnosticPulse { /* private fields */ }
Expand description

Measures a library’s checkpoints without changing its signature.

Wrap the PulseTree you would pass to the library, pass &measured instead, and finish the wrapper when the library returns:

use how_far_along::{Outcome, Phase, PulseTree, Total, Unstoppable};
use how_far_really::diagnostics::{DiagnosticPulse, Options};
use how_far_really::profile::{Profiler, StdClock};

let profiler = Profiler::new(StdClock::new(), 256);
let tree = PulseTree::new(Phase::new("encode", Total::Unknown), Unstoppable);
let measured = DiagnosticPulse::new(tree, &profiler);
let observer = measured.observer();
// let result = my_library::encode(&input, &measured);
measured.finish(Outcome::Succeeded)?;
let trace = profiler.snapshot().with_progress(observer.snapshot());
for finding in trace.diagnose(&Options::default()) {
    eprintln!("{finding}");
}

Every phase the library plans gets its own span, tied to its node in the tree. A phase’s span starts at its first check or report; a stage of a sequential split starts when the previous stage finished, and the first stage when the plan was made. So time spent before a stage’s first checkpoint is measured, and a stage that never checks at all still gets a span. Workers that share one phase share its span; give each worker its own Span when one worker’s long silence matters.

A phase that splits hands its time to its children: its own span ends at the split, and a sequential stage then records a SpanKind::Wait span while it coordinates them. A stage is thereby timed from entry to exit, and its children’s work never counts as its own missing checkpoints.

Pulse::share returns an instrumented owned view, so checks made inside code that owns its stop policy, such as a codec context, count toward the stage that handed it out. may_stop and may_report are always true, so libraries that skip calls on no-op pulses still make the calls measured. Creating one turns on Profiler::set_report_timing.

Implementations§

Source§

impl DiagnosticPulse

Source

pub fn new(tree: PulseTree, profiler: &Profiler) -> Self

Measure everything a library does through tree.

Source

pub fn observer(&self) -> Observer

A read-only view of the measured tree.

Source

pub fn finish(self, outcome: Outcome) -> Result<(), PlanError>

Record the operation’s outcome in the tree, and close the root’s span.

Trait Implementations§

Source§

impl Complete for DiagnosticPulse

Source§

fn complete_as(self, outcome: Outcome)

Record an explicitly chosen outcome, resolving unfinished observations. Join workers before calling this. Started but uncompleted children are abandoned; untouched children are skipped on success, not run on error.
Source§

fn complete<T, E>(self, result: Result<T, E>) -> Result<T, E>
where E: AsStopReason,

Classify the error with AsStopReason, record completion, and return the original result. Read more
Source§

fn complete_classified<T, E>( self, result: Result<T, E>, is_stop: impl FnOnce(&E) -> bool, ) -> Result<T, E>

Complete with an explicit classifier, for a foreign error type that Rust’s orphan rules keep from implementing AsStopReason.
Source§

fn complete_with<T, E>( self, body: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>
where E: AsStopReason,

Run a multi-step body with this owner, then complete the owner with the body’s result and return that result unchanged. Read more
Source§

fn complete_with_classified<T, E>( self, is_stop: impl FnOnce(&E) -> bool, body: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>

complete_with with an explicit classifier, for a foreign error type that cannot implement AsStopReason, such as an error wrapped with its source location.
Source§

impl Debug for DiagnosticPulse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Pulse for DiagnosticPulse

Source§

fn record_issue(&self, error: PlanError)

Record a reporting-protocol problem for optional diagnostics. This never changes cancellation or the operation’s return value. Ordinary sinks may ignore it; diagnostic wrappers retain bounded evidence.
Source§

fn split( &self, execution: Execution, parts: &[PhaseSpec<'_>], ) -> Result<Vec<Child<'_>>, PlanError>

Split this phase into weighted children, in declared order. Read more
Source§

fn start(&self) -> Result<(), PlanError>

Mark this phase running, without counting or ending planning. Implementations without lifecycle observations may ignore this.
Source§

fn set_total(&self, total: Total) -> Result<(), PlanError>

Revise a leaf’s denominator without changing completed units or weights. Unsupported implementations return an error instead of losing the update.
Source§

fn share(&self) -> Result<SharedPulse, PlanError>

Share all pulse capabilities with owned work, but never completion rights. Read more
Source§

impl Report for DiagnosticPulse

Source§

fn advance(&self, completed: u64)

Add completed finished units.
Source§

fn may_report(&self) -> bool

Whether reports have any effect. Read more
Source§

impl Stop for DiagnosticPulse

Source§

fn check(&self) -> Result<(), StopReason>

Check if the operation should stop. Read more
Source§

fn may_stop(&self) -> bool

Returns true if this stop can ever signal a stop. Read more
Source§

fn should_stop(&self) -> bool

Returns true if the operation should stop. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ProgressExt for T
where T: Stop + Report + ?Sized,

Source§

fn step(&self, completed: u64) -> Result<(), StopReason>

Count completed finished units, then check for cancellation. Read more
Source§

fn live(&self) -> Option<&Self>

The live pulse: this value, or None when it can neither stop nor report. Read more
Source§

fn split_array<const N: usize>( &self, execution: Execution, parts: [PhaseSpec<'_>; N], ) -> Result<[Child<'_>; N], PlanError>
where Self: Pulse,

Pulse::split into exactly N children, returned as an array. Read more
Source§

impl<T> ReportExt for T
where T: Report + ?Sized,

Source§

fn batched(self, threshold: NonZero<u64>) -> Batch<Self>
where Self: Sized,

Buffer one worker’s reports, publishing them in batches of at least threshold units, and the remainder on Batch::flush or drop. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.