Wrapper

Struct Wrapper 

Source
pub struct Wrapper<T>(pub T);
Expand description

Generic wrapper to facilitate the addition of new methods to the wrapped type.

Tuple Fields§

§0: T

Implementations§

Source§

impl<K> Wrapper<BTreeMap<K, Histogram<u64>>>

Source

pub fn aggregate<G>(&self, f: impl Fn(&K) -> G) -> TimingsView<G>
where G: Ord,

Combines histogram values according to sets of keys that yield the same value when f is applied.

Source

pub fn add(&mut self, other: TimingsView<K>)
where K: Ord,

Combines the histograms of self with those of another TimingsView.

Source

pub fn summary_stats(&self) -> Wrapper<BTreeMap<K, SummaryStats>>
where K: Ord + Clone,

Produces a map whose values are the SummaryStats of self’s histogram values.

Source§

impl Wrapper<BTreeMap<SpanGroup, Histogram<u64>>>

Source

pub fn aggregator_is_consistent<G>(&self, f: impl Fn(&SpanGroup) -> G) -> bool
where G: Ord,

Checks whether an aggregation function f used in Self::aggregate is consistent according to the following definition:

  • the values resulting from applying f to span groups are called aggregate keys
  • the sets of span groups corresponding to each aggregate key are called aggregates.
  • an aggregation function is consistent if and only if, for each aggregate, all the span groups in the aggregate have the same callsite.
Source

pub fn span_group_to_parent(&self) -> BTreeMap<SpanGroup, Option<SpanGroup>>

Returns a map that associates each SpanGroup to its parent.

Source§

impl<T> Wrapper<T>

Source

pub fn wrap(value: T) -> Wrapper<T>

Source

pub fn value(&self) -> &T

Source§

impl<K, V> Wrapper<BTreeMap<K, V>>

Source

pub fn map_values<V1, BV>( &self, f: impl FnMut(&BV) -> V1, ) -> Wrapper<BTreeMap<K, V1>>
where K: Ord + Clone, V: Borrow<BV>,

Returns a new Wrapper<BTreeMap> with the same keys as self and values corresponding to the invocation of function f on the original values.

Examples found in repository?
examples/doc_sync.rs (line 32)
26fn main() {
27    let latencies = LatencyTrace::activated_default()
28        .unwrap()
29        .measure_latencies(f);
30
31    println!("\nLatency stats below are in microseconds");
32    for (span_group, stats) in latencies.map_values(summary_stats) {
33        println!("  * {:?}, {:?}", span_group, stats);
34    }
35
36    // A shorter way to print the summary stats, with uglier formatting.
37    println!("\nDebug print of `latencies.map_values(summary_stats)`:");
38    println!("{:?}", latencies.map_values(summary_stats));
39}
More examples
Hide additional examples
examples/doc_async.rs (line 33)
27fn main() {
28    let latencies = LatencyTrace::activated_default()
29        .unwrap()
30        .measure_latencies_tokio(f);
31
32    println!("\nLatency stats below are in microseconds");
33    for (span_group, stats) in latencies.map_values(summary_stats) {
34        println!("  * {:?}, {:?}", span_group, stats);
35    }
36
37    // A shorter way to print the summary stats, with uglier formatting.
38    println!("\nDebug print of `latencies.map_values(summary_stats)`:");
39    println!("{:?}", latencies.map_values(summary_stats));
40}
examples/doc_sync_probed.rs (line 39)
26fn main() {
27    let probed = LatencyTrace::activated_default()
28        .unwrap()
29        .measure_latencies_probed(f)
30        .unwrap();
31
32    // Let the function run for some time before probing latencies.
33    thread::sleep(Duration::from_micros(16000));
34
35    let latencies1 = probed.probe_latencies();
36    let latencies2 = probed.wait_and_report();
37
38    println!("\nlatencies1 in microseconds");
39    for (span_group, stats) in latencies1.map_values(summary_stats) {
40        println!("  * {:?}, {:?}", span_group, stats);
41    }
42
43    println!("\nlatencies2 in microseconds");
44    for (span_group, stats) in latencies2.map_values(summary_stats) {
45        println!("  * {:?}, {:?}", span_group, stats);
46    }
47}
examples/doc_async_probed.rs (line 40)
27fn main() {
28    let probed = LatencyTrace::activated_default()
29        .unwrap()
30        .measure_latencies_probed_tokio(f)
31        .unwrap();
32
33    // Let the function run for some time before probing latencies.
34    thread::sleep(Duration::from_micros(48000));
35
36    let latencies1 = probed.probe_latencies();
37    let latencies2 = probed.wait_and_report();
38
39    println!("\nlatencies1 in microseconds");
40    for (span_group, stats) in latencies1.map_values(summary_stats) {
41        println!("  * {:?}, {:?}", span_group, stats);
42    }
43
44    println!("\nlatencies2 in microseconds");
45    for (span_group, stats) in latencies2.map_values(summary_stats) {
46        println!("  * {:?}, {:?}", span_group, stats);
47    }
48}
examples/doc_sync_layered.rs (line 55)
32fn main() {
33    // LatencyTrace instance from which latency statistics will be extracted later.
34    let lt = LatencyTrace::default();
35
36    // Clone of the above that will be used as a `tracing_subscriber::layer::Layer` that can be
37    // composed with other tracing layers. Add a filter so that only spans with level `INFO` or
38    // higher priority (lower level) are aggregated.
39    let ltl = lt.clone().with_filter(LevelFilter::INFO);
40
41    // `tracing_subscriber::fmt::Layer` that can be composed with the above `LatencyTrace` layer.
42    // Spans with level `TRACE` or higher priority (lower level) are displayed.
43    let tfmt = tracing_subscriber::fmt::layer()
44        .with_span_events(FmtSpan::FULL)
45        .with_filter(LevelFilter::TRACE);
46
47    // Instantiate a layered subscriber and set it as the global default.
48    let layered = Registry::default().with(ltl).with(tfmt);
49    layered.init();
50
51    // Measure latencies.
52    let latencies = lt.measure_latencies(f);
53
54    println!("\nLatency stats below are in microseconds");
55    for (span_group, stats) in latencies.map_values(summary_stats) {
56        println!("  * {:?}, {:?}", span_group, stats);
57    }
58
59    // A shorter way to print the summary stats, with uglier formatting.
60    println!("\nDebug print of `latencies.map_values(summary_stats)`:");
61    println!("{:?}", latencies.map_values(summary_stats));
62}

Trait Implementations§

Source§

impl<T> AsRef<T> for Wrapper<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Borrow<T> for Wrapper<Arc<T>>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> Borrow<T> for Wrapper<Box<T>>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> Borrow<T> for Wrapper<Rc<T>>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> Borrow<T> for Wrapper<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: Clone> Clone for Wrapper<T>

Source§

fn clone(&self) -> Wrapper<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Wrapper<T>
where T: Debug,

Source§

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

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

impl<T> Deref for Wrapper<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Wrapper<T>

Source§

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

Mutably dereferences the value.
Source§

impl<T> From<T> for Wrapper<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Wrapper<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T> IntoIterator for &'a Wrapper<T>

Source§

type Item = <&'a T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <&'a T as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Wrapper<T>

Source§

type Item = <&'a mut T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <&'a mut T as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Wrapper<T>
where T: IntoIterator,

Source§

type Item = <T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <T as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Ord> Ord for Wrapper<T>

Source§

fn cmp(&self, other: &Wrapper<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Wrapper<T>

Source§

fn eq(&self, other: &Wrapper<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Wrapper<T>

Source§

fn partial_cmp(&self, other: &Wrapper<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq> Eq for Wrapper<T>

Source§

impl<T> StructuralPartialEq for Wrapper<T>

Auto Trait Implementations§

§

impl<T> Freeze for Wrapper<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Wrapper<T>
where T: RefUnwindSafe,

§

impl<T> Send for Wrapper<T>
where T: Send,

§

impl<T> Sync for Wrapper<T>
where T: Sync,

§

impl<T> Unpin for Wrapper<T>
where T: Unpin,

§

impl<T> UnwindSafe for Wrapper<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more