Skip to main content

Distribution

Struct Distribution 

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

A container for approximating the distribution of a streaming data source.

Distributions aggregate statistics from raw samples that pass through them. They include:

  • total: The total number of observed values.
  • sum: The sum of all observed values.
  • min: The smallest observed value.
  • max: The largest observed value.
  • buckets: An exponential histogram backed by a BucketSet.

Call the Distribution::observe method on each raw value.

Use the Props implementation on Distribution to include it on a metric sample.

Implementations§

Source§

impl Distribution

Source

pub const DEFAULT_MAX_SCALE: i32 = 20

The default initial scale used when converting observed values into bucket midpoints.

Source

pub const DEFAULT_MAX_BUCKETS: usize = 160

The default maximum number of buckets before rescaling will apply.

Source

pub fn new(max_scale: i32, max_buckets: usize) -> Self

Create a new Distribution that can store up to max_buckets sparse buckets, at up to max_scale precision.

The distribution uses a large scale initially. Whenever the number of buckets would overflow max_buckets, the scale is decremented and the buckets are rescaled. This reduces the number of buckets by half while also decreasing precision.

Source

pub fn observe(&mut self, raw_value: f64)

Observe a raw value.

The value will be converted into a bucket midpoint at the current internal scale. The count for the resulting bucket will be incremented by 1.

§Panics

This method will panic if adding count to an existing entry in value would overflow.

Source

pub fn observe_all(&mut self, raw_value: f64, count: u64)

Observe a raw value.

The value will be converted into a bucket midpoint at the current internal scale. The count for the resulting bucket will be incremented by 1.

§Panics

This method will panic if adding count to an existing entry in value would overflow.

Source

pub fn reset(&mut self)

Clear the distribution of any data so it can be re-used.

This method will also reset the internal scale back to its initial value.

Source

pub fn count(&self) -> u64

Get the total count of observed values across all buckets.

This method returns 0 if no values have been seen.

Source

pub fn min(&self) -> Option<f64>

Get the minimum observed value.

This method returns None if no values have been seen.

Source

pub fn max(&self) -> Option<f64>

Get the maximum observed value.

This method returns None if no values have been seen.

Source

pub fn sum(&self) -> Option<f64>

Get the sum of all observed values.

This method returns None if no values have been seen.

Source

pub fn scale(&self) -> i32

Get the current scale used to bucket values.

Source

pub fn buckets(&self) -> &BucketSet

Get the bucket values.

Source

pub fn max_buckets(&self) -> usize

Get the maximum number of buckets the distribution can hold before rescaling.

Source

pub fn max_scale(&self) -> i32

Get the maximum scale the distribution can use.

Trait Implementations§

Source§

impl Default for Distribution

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Props for Distribution

Source§

fn for_each<'kv, F: FnMut(Str<'kv>, Value<'kv>) -> ControlFlow<()>>( &'kv self, for_each: F, ) -> ControlFlow<()>

Enumerate the Str and Value pairs. Read more
Source§

fn get<'v, K>(&'v self, key: K) -> Option<Value<'v>>
where K: ToStr,

Get the value for a given key, if it’s present. Read more
Source§

fn pull<'kv, V, K>(&'kv self, key: K) -> Option<V>
where V: FromValue<'kv>, K: ToStr,

Get the value for a given key, if it’s present as an instance of V. Read more
Source§

fn and_props<U>(self, other: U) -> And<Self, U>
where U: Props, Self: Sized,

Concatenate other to the end of self.
Source§

fn filter<F>(self, filter: F) -> Filter<Self, F>
where F: Fn(Str<'_>, Value<'_>) -> bool, Self: Sized,

Filter the set of properties. Read more
Source§

fn collect<'kv, C>(&'kv self) -> C
where C: FromProps<'kv>,

Collect these properties into another collection type. Read more
Source§

fn as_map(&self) -> &AsMap<Self>
where Self: Sized,

Get an adapter that will serialize properties as a map.
Source§

fn dedup(&self) -> &Dedup<Self>
where Self: Sized,

Lazily de-duplicate properties in the collection. Read more
Source§

fn is_unique(&self) -> bool

Whether the collection is known not to contain any duplicate keys. Read more
Source§

fn size(&self) -> Option<usize>

A hint on the number of properties in the collection. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<P> ErasedProps for P
where P: Props,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, <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.