Struct LogHistogramBuilder

Source
pub struct LogHistogramBuilder { /* private fields */ }
Available on tokio_unstable and crate feature rt only.
Expand description

Configuration for a LogHistogram

The log-scaled histogram implements an H2 histogram where the first bucket covers the range from 0 to LogHistogramBuilder::min_value and the final bucket covers LogHistogramBuilder::max_value to infinity. The precision is bounded to the specified LogHistogramBuilder::max_error. Specifically, the precision is the next smallest value of 2^-p such that it is smaller than the requested max error. You can also select p directly with LogHistogramBuilder::precision_exact.

Depending on the selected parameters, the number of buckets required is variable. To ensure that the histogram size is acceptable, callers may call LogHistogramBuilder::max_buckets. If the resulting histogram would require more buckets, then the method will return an error.

§Default values

The default configuration provides the following settings:

  1. min_value: 100ns
  2. max_value: 68 seconds. The final bucket covers all values >68 seconds
  3. precision: max error of 25%

This uses 237 64-bit buckets.

Implementations§

Source§

impl LogHistogramBuilder

Source

pub fn max_error(self, max_error: f64) -> Self

Set the precision for this histogram

This function determines the smallest value of p that would satisfy the requested precision such that 2^-p is less than precision. To set p directly, use LogHistogramBuilder::precision_exact.

Precision controls the size of the “bucket groups” (consecutive buckets with identical ranges). When p is 0, each bucket will be twice the size of the previous bucket. To match the behavior of the legacy log histogram implementation, use builder.precision_exact(0).

The default value is 25% (2^-2)

The highest supported precision is 0.0977% (2^-10). Provided values less than this will be truncated.

§Panics
  • max_error < 0
  • max_error > 1
Source

pub fn precision_exact(self, p: u32) -> Self

Sets the precision of this histogram directly.

The precision (meaning: the ratio n/bucket_range(n) for some given n) will be 2^-p.

Precision controls the number consecutive buckets with identically sized ranges. When p is 0, each bucket will be twice the size of the previous bucket (bucket groups are only a single bucket wide).

To match the behavior of the legacy implementation (HistogramScale::Log), use builder.precision_exact(0).

§Panics
  • p > 10
Source

pub fn min_value(self, duration: Duration) -> Self

Sets the minimum duration that can be accurately stored by this histogram.

This sets the resolution. The first bucket will be no larger than the provided duration. Setting this value will reduce the number of required buckets, sometimes quite significantly.

Source

pub fn max_value(self, duration: Duration) -> Self

Sets the maximum value that can by this histogram without truncation

Values greater than this fall in the final bucket that stretches to u64::MAX.

§Panics

The provided value is 0

Source

pub fn max_buckets( &mut self, max_buckets: usize, ) -> Result<LogHistogram, InvalidHistogramConfiguration>

Builds the log histogram, enforcing the max buckets requirement

Source

pub fn build(&self) -> LogHistogram

Builds the log histogram

Trait Implementations§

Source§

impl Clone for LogHistogramBuilder

Source§

fn clone(&self) -> LogHistogramBuilder

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 Debug for LogHistogramBuilder

Source§

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

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

impl Default for LogHistogramBuilder

Source§

fn default() -> LogHistogramBuilder

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

impl From<LogHistogramBuilder> for LogHistogram

Source§

fn from(value: LogHistogramBuilder) -> Self

Converts to this type from the input type.
Source§

impl Copy for LogHistogramBuilder

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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