Struct heatmap::Heatmap

source ·
pub struct Heatmap { /* private fields */ }
Expand description

A Heatmap stores counts for timestamped values over a configured span of time.

Internally, it is represented as a ring buffer of histograms with one additional histogram to track all counts within the span of time. Old histograms age-out as time moves forward and they are subtracted from the summary histogram at that point.

This acts as a moving histogram, such that requesting a percentile returns a percentile from across the configured span of time.

Implementations§

source§

impl Heatmap

source

pub fn new( m: u32, r: u32, n: u32, span: Duration, resolution: Duration ) -> Result<Self, Error>

Create a new Heatmap which stores counts for timestamped values over a configured span of time.

  • m - sets the minimum resolution M = 2^m. This is the smallest unit of quantification, which is also the smallest bucket width. If the input values are always integers, choosing m=0 would ensure precise recording for the smallest values.

  • r - sets the minimum resolution range R = 2^r - 1. The selected value must be greater than the minimum resolution m. This sets the maximum value that the minimum resolution should extend to.

  • n - sets the maximum value N = 2^n - 1. The selected value must be greater than or equal to the minimum resolution range r.

  • span - sets the total duration that the heatmap covers

  • resolution - sets the resolution in the time domain. Counts from similar instants in time will be grouped together.

source

pub fn builder() -> Builder

Creates a Builder with the default values m = 0, r = 10, n = 30, span = 60s, resolution = 1s.

This would create a Heatmap with 61 total Histograms, each with 11264 buckets which can store values from 1 to 1_073_741_823 with values 1 to 1023 being stored in buckets with a width of 1. Such a Heatmap would be appropriate for latencies measured in nanoseconds where the max expected latency is one second and reporting covers the past minute.

source

pub fn windows(&self) -> usize

Returns the number of windows stored in the Heatmap

source

pub fn buckets(&self) -> usize

Returns the number of buckets stored within each Histogram in the Heatmap

source

pub fn increment(&self, time: Instant, value: u64, count: u32)

Increment a time-value pair by a specified count

source

pub fn percentile(&self, percentile: f64) -> Result<Bucket, Error>

Return the nearest value for the requested percentile (0.0 - 100.0) across the total range of samples retained in the Heatmap.

Note: since the heatmap stores a distribution across a configured time span, sequential calls to fetch the percentile might result in different results even without concurrent writers. For instance, you may see a 90th percentile that is higher than the 100th percentile depending on the timing of calls to this function and the distribution of your data.

Note: concurrent writes may also effect the value returned by this function. Users needing better consistency should ensure that other threads are not writing into the heatmap while this function is in-progress.

source

pub fn iter(&self) -> Iter<'_>

Creates an iterator to iterate over the component histograms of this heatmap.

source

pub fn summary(&self) -> &Histogram

Access the summary histogram of this heatmap.

Note that concurrent modifications to the heatmap will continue to show up in the summary histogram while it is being read so sequential queries may not return consistent results.

Trait Implementations§

source§

impl Clone for Heatmap

source§

fn clone(&self) -> Self

Returns a copy 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<'a> IntoIterator for &'a Heatmap

§

type Item = Window<'a>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.