Struct Metrics

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

The metrics struct is used to initialize the metrics communications channels and access the Histogram data for each named metric.

Implementations§

Source§

impl Metrics

Source

pub fn for_each_histogram<F>(&self, f: F)
where F: FnMut(&'static str, &Histogram<u64>),

Iterate the histograms created. This function accepts a closure of FnMut(&'static str, &Histogram<u64>) taking the span name and the histogram as arguments.

Examples found in repository?
examples/nothread.rs (lines 37-39)
24fn main() {
25    let metrics = Metrics::new(1);
26
27    (0..2).for_each(|_| long_scoped());
28    (0..2).for_each(|_| long());
29    (0..2).for_each(|_| short_scoped());
30    (0..2).for_each(|_| short());
31
32    (0..2).for_each(|_| long_scoped());
33    (0..2).for_each(|_| long());
34    (0..2).for_each(|_| short_scoped());
35    (0..2).for_each(|_| short());
36
37    metrics.for_each_histogram(|span_name, h| {
38        println!("{} -> {:.2}ms", span_name, h.mean() / 1_000_000.0);
39    });
40}
More examples
Hide additional examples
examples/simple.rs (lines 46-48)
26fn main() {
27    let metrics = Metrics::new(1);
28
29    let t1 =  std::thread::spawn(|| {
30        (0..10).for_each(|_| long_scoped());
31        (0..10).for_each(|_| long());
32        (0..10).for_each(|_| short_scoped());
33        (0..10).for_each(|_| short());
34    });
35
36    let t2 =  std::thread::spawn(|| {
37        (0..10).for_each(|_| long_scoped());
38        (0..10).for_each(|_| long());
39        (0..10).for_each(|_| short_scoped());
40        (0..10).for_each(|_| short());
41    });
42
43    t1.join().unwrap();
44    t2.join().unwrap();
45
46    metrics.for_each_histogram(|span_name, h| {
47        println!("{} -> {:.2}ms", span_name, h.mean() / 1_000_000.0);
48    });
49}
Source

pub fn flush(&self)

Blocks the current thread until the worker thread has completed flushing the receiver.

§Warning

In high contention situations, this may block indefinitely. This method is meant to be used in the context of a game engine, where execution can be guaranteed to be blocked for metric collection.

Source

pub fn new(sigfig: u8) -> Metrics

Creates a new metrcs instance, initializing metrics and spawning a worker to collect the data.

§Warning

Any given instance of Metrics will globally collect a duplicate of the Histgram data. Only one instance should be active at a time.

Examples found in repository?
examples/nothread.rs (line 25)
24fn main() {
25    let metrics = Metrics::new(1);
26
27    (0..2).for_each(|_| long_scoped());
28    (0..2).for_each(|_| long());
29    (0..2).for_each(|_| short_scoped());
30    (0..2).for_each(|_| short());
31
32    (0..2).for_each(|_| long_scoped());
33    (0..2).for_each(|_| long());
34    (0..2).for_each(|_| short_scoped());
35    (0..2).for_each(|_| short());
36
37    metrics.for_each_histogram(|span_name, h| {
38        println!("{} -> {:.2}ms", span_name, h.mean() / 1_000_000.0);
39    });
40}
More examples
Hide additional examples
examples/simple.rs (line 27)
26fn main() {
27    let metrics = Metrics::new(1);
28
29    let t1 =  std::thread::spawn(|| {
30        (0..10).for_each(|_| long_scoped());
31        (0..10).for_each(|_| long());
32        (0..10).for_each(|_| short_scoped());
33        (0..10).for_each(|_| short());
34    });
35
36    let t2 =  std::thread::spawn(|| {
37        (0..10).for_each(|_| long_scoped());
38        (0..10).for_each(|_| long());
39        (0..10).for_each(|_| short_scoped());
40        (0..10).for_each(|_| short());
41    });
42
43    t1.join().unwrap();
44    t2.join().unwrap();
45
46    metrics.for_each_histogram(|span_name, h| {
47        println!("{} -> {:.2}ms", span_name, h.mean() / 1_000_000.0);
48    });
49}

Trait Implementations§

Source§

impl Drop for Metrics

Source§

fn drop(&mut self)

Executes the destructor for this type. 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, 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.