pub struct SyncHistogram<C: Counter> { /* private fields */ }
Expand description

A Histogram that can be written to by multiple threads concurrently.

Each writer thread should have a Recorder, which allows it to record new samples without synchronization. New recorded samples are made available through this histogram by calling SyncHistogram::refresh, which blocks until it has synchronized with every recorder.

Implementations

Block until writes from all Recorder instances for this histogram have been incorporated.

Block until writes from all Recorder instances for this histogram have been incorporated, or until the given amount of time has passed.

Obtain another multi-threaded writer for this histogram.

Note that writes made to the Recorder will not be visible until the next call to SyncHistogram::refresh.

Methods from Deref<Target = Histogram<C>>

Get the current number of distinct values that can be represented in the histogram.

Get the lowest discernible value for the histogram in its current configuration.

Get the highest trackable value for the histogram in its current configuration.

Get the number of significant value digits kept by this histogram.

👎 Deprecated since 6.0.0:

use len instead

Get the total number of samples recorded.

Get the total number of samples recorded.

Returns true if this histogram has no recorded values.

Get the number of buckets used by the histogram to cover the highest trackable value.

This method differs from .len() in that it does not count the sub buckets within each bucket.

This method is probably only useful for testing purposes.

Returns true if this histogram is currently able to auto-resize as new samples are recorded.

Get a copy of this histogram, corrected for coordinated omission.

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, the new histogram will include an auto-generated additional series of decreasingly-smaller (down to the interval) value records for each count found in the current histogram that is larger than the interval.

Note: This is a post-correction method, as opposed to the at-recording correction method provided by record_correct. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.

See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

If interval is larger than 0, add auto-generated value records as appropriate if value is larger than interval.

Overwrite this histogram with the given histogram. All data and statistics in this histogram will be overwritten.

Overwrite this histogram with the given histogram while correcting for coordinated omission. All data and statistics in this histogram will be overwritten. See clone_correct for more detailed explanation about how correction is applied

Add the contents of another histogram to this one.

Returns an error if values in the other histogram cannot be stored; see AdditionError.

Add the contents of another histogram to this one, while correcting for coordinated omission.

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, the values added will include an auto-generated additional series of decreasingly-smaller (down to the given interval) value records for each count found in the current histogram that is larger than interval.

Note: This is a post-recording correction method, as opposed to the at-recording correction method provided by record_correct. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.

See notes in the description of the Histogram calls for an illustration of why this corrective behavior is important.

See RecordError for error conditions.

Subtract the contents of another histogram from this one.

See SubtractionError for error conditions.

Clear the contents of this histogram while preserving its statistics and configuration.

Reset the contents and statistics of this histogram, preserving only its configuration.

Control whether or not the histogram can auto-resize and auto-adjust it’s highest trackable value as high-valued samples are recorded.

Record value in the histogram.

Returns an error if value exceeds the highest trackable value and auto-resize is disabled.

Record value in the histogram, clamped to the range of the histogram.

This method cannot fail, as any values that are too small or too large to be tracked will automatically be clamed to be in range. Be aware that this will hide extreme outliers from the resulting histogram without warning. Since the values are clamped, the histogram will also not be resized to accomodate the value, even if auto-resize is enabled.

Record multiple samples for a value in the histogram, adding to the value’s current count.

count is the number of occurrences of this value to record.

Returns an error if value cannot be recorded; see RecordError.

Record multiple samples for a value in the histogram, each one clamped to the histogram’s range.

count is the number of occurrences of this value to record.

This method cannot fail, as values that are too small or too large to be recorded will automatically be clamed to be in range. Be aware that this will hide extreme outliers from the resulting histogram without warning. Since the values are clamped, the histogram will also not be resized to accomodate the value, even if auto-resize is enabled.

Record a value in the histogram while correcting for coordinated omission.

See record_n_correct for further documentation.

Record multiple values in the histogram while correcting for coordinated omission.

To compensate for the loss of sampled values when a recorded value is larger than the expected interval between value samples, this method will auto-generate and record an additional series of decreasingly-smaller (down to interval) value records.

Note: This is a at-recording correction method, as opposed to the post-recording correction method provided by correct_clone. The two methods are mutually exclusive, and only one of the two should be be used on a given data set to correct for the same coordinated omission issue.

Returns an error if value exceeds the highest trackable value and auto-resize is disabled.

Iterate through histogram values by quantile levels.

The iteration mechanic for this iterator may appear somewhat confusing, but it yields fairly pleasing output. The iterator starts with a quantile step size of 1/halving_period. For every iteration, it yields a value whose quantile is that much greater than the previously emitted quantile (i.e., initially 0, 0.1, 0.2, etc.). Once halving_period values have been emitted, the quantile step size is halved, and the iteration continues.

ticks_per_half_distance must be at least 1.

The iterator yields an iterators::IterationValue struct.

One subtlety of this iterator is that you can reach a value whose cumulative count yields a quantile of 1.0 far sooner than the quantile iteration would reach 1.0. Consider a histogram with count 1 at value 1, and count 1000000 at value 1000. At any quantile iteration above 1/1000001 = 0.000000999, iteration will have necessarily proceeded to the index for value 1000, which has all the remaining counts, and therefore quantile (for the value) of 1.0. This is why IterationValue has both quantile() and quantile_iterated_to(). Additionally, to avoid a bunch of unhelpful iterations once iteration has reached the last value with non-zero count, quantile iteration will skip straight to 1.0 as well.

use hdrhistogram::Histogram;
use hdrhistogram::iterators::IterationValue;
let mut hist = Histogram::<u64>::new_with_max(10000, 4).unwrap();
for i in 0..10000 {
    hist += i;
}

let mut perc = hist.iter_quantiles(1);

println!("{:?}", hist.iter_quantiles(1).collect::<Vec<_>>());

assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.0001), 0.0001, 0.0, 1, 1))
);
// step size = 50
assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.5), 0.5, 0.5, 1, 5000 - 1))
);
// step size = 25
assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.75), 0.75, 0.75, 1, 2500))
);
// step size = 12.5
assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.875), 0.875, 0.875, 1, 1250))
);
// step size = 6.25
assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.9375), 0.9375, 0.9375, 1, 625))
);
// step size = 3.125
assert_eq!(
    perc.next(),
    Some(IterationValue::new(hist.value_at_quantile(0.9688), 0.9688, 0.96875, 1, 313))
);
// etc...

Iterates through histogram values using linear value steps. The iteration is performed in steps of size step, each one yielding the count for all values in the preceeding value range of size step. The iterator terminates when all recorded histogram values are exhausted.

The iterator yields an iterators::IterationValue struct.

use hdrhistogram::Histogram;
use hdrhistogram::iterators::IterationValue;
let mut hist = Histogram::<u64>::new_with_max(1000, 3).unwrap();
hist += 100;
hist += 500;
hist += 800;
hist += 850;

let mut perc = hist.iter_linear(100);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(99, hist.quantile_below(99), hist.quantile_below(99), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(199, hist.quantile_below(199), hist.quantile_below(199), 0, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(299, hist.quantile_below(299), hist.quantile_below(299), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(399, hist.quantile_below(399), hist.quantile_below(399), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(499, hist.quantile_below(499), hist.quantile_below(499), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(599, hist.quantile_below(599), hist.quantile_below(599), 0, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(699, hist.quantile_below(699), hist.quantile_below(699), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(799, hist.quantile_below(799), hist.quantile_below(799), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(899, hist.quantile_below(899), hist.quantile_below(899), 0, 2))
);
assert_eq!(perc.next(), None);

Iterates through histogram values at logarithmically increasing levels. The iteration is performed in steps that start at start and increase exponentially according to exp. The iterator terminates when all recorded histogram values are exhausted.

The iterator yields an iterators::IterationValue struct.

use hdrhistogram::Histogram;
use hdrhistogram::iterators::IterationValue;
let mut hist = Histogram::<u64>::new_with_max(1000, 3).unwrap();
hist += 100;
hist += 500;
hist += 800;
hist += 850;

let mut perc = hist.iter_log(1, 10.0);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(0, hist.quantile_below(0), hist.quantile_below(0), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(9, hist.quantile_below(9), hist.quantile_below(9), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(99, hist.quantile_below(99), hist.quantile_below(99), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(999, hist.quantile_below(999), hist.quantile_below(999), 0, 4))
);
assert_eq!(perc.next(), None);

Iterates through all recorded histogram values using the finest granularity steps supported by the underlying representation. The iteration steps through all non-zero recorded value counts, and terminates when all recorded histogram values are exhausted.

The iterator yields an iterators::IterationValue struct.

use hdrhistogram::Histogram;
use hdrhistogram::iterators::IterationValue;
let mut hist = Histogram::<u64>::new_with_max(1000, 3).unwrap();
hist += 100;
hist += 500;
hist += 800;
hist += 850;

let mut perc = hist.iter_recorded();
assert_eq!(
    perc.next(),
    Some(IterationValue::new(100, hist.quantile_below(100), hist.quantile_below(100), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(500, hist.quantile_below(500), hist.quantile_below(500), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(800, hist.quantile_below(800), hist.quantile_below(800), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(850, hist.quantile_below(850), hist.quantile_below(850), 1, 1))
);
assert_eq!(perc.next(), None);

Iterates through all histogram values using the finest granularity steps supported by the underlying representation. The iteration steps through all possible unit value levels, regardless of whether or not there were recorded values for that value level, and terminates when all recorded histogram values are exhausted.

The iterator yields an iterators::IterationValue struct.

use hdrhistogram::Histogram;
use hdrhistogram::iterators::IterationValue;
let mut hist = Histogram::<u64>::new_with_max(10, 1).unwrap();
hist += 1;
hist += 5;
hist += 8;

let mut perc = hist.iter_all();
assert_eq!(perc.next(), Some(IterationValue::new(0, 0.0, 0.0, 0, 0)));
assert_eq!(
    perc.next(),
    Some(IterationValue::new(1, hist.quantile_below(1), hist.quantile_below(1), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(2, hist.quantile_below(2), hist.quantile_below(2), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(3, hist.quantile_below(3), hist.quantile_below(3), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(4, hist.quantile_below(4), hist.quantile_below(4), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(5, hist.quantile_below(5), hist.quantile_below(5), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(6, hist.quantile_below(6), hist.quantile_below(6), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(7, hist.quantile_below(7), hist.quantile_below(7), 0, 0))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(8, hist.quantile_below(8), hist.quantile_below(8), 1, 1))
);
assert_eq!(
    perc.next(),
    Some(IterationValue::new(9, hist.quantile_below(9), hist.quantile_below(9), 0, 0))
);
assert_eq!(perc.next(), Some(IterationValue::new(10, 1.0, 1.0, 0, 0)));

Get the lowest recorded value level in the histogram. If the histogram has no recorded values, the value returned will be 0.

Get the highest recorded value level in the histogram. If the histogram has no recorded values, the value returned is undefined.

Get the lowest recorded non-zero value level in the histogram. If the histogram has no recorded values, the value returned is u64::max_value().

Determine if two values are equivalent with the histogram’s resolution. Equivalent here means that value samples recorded for any two equivalent values are counted in a common total count.

Get the computed mean value of all recorded values in the histogram.

Get the computed standard deviation of all recorded values in the histogram

Get the value at a given percentile.

This is simply value_at_quantile multiplied by 100.0. For best floating-point precision, use value_at_quantile directly.

Get the value at a given quantile.

When the given quantile is > 0.0, the value returned is the value that the given percentage of the overall recorded value entries in the histogram are either smaller than or equivalent to. When the given quantile is 0.0, the value returned is the value that all value entries in the histogram are either larger than or equivalent to.

Two values are considered “equivalent” if self.equivalent would return true.

If the total count of the histogram has exceeded u64::max_value(), this will return inaccurate results.

Get the percentile of samples at and below a given value.

This is simply quantile_below* multiplied by 100.0. For best floating-point precision, use quantile_below` directly.

Get the quantile of samples at or below a given value.

The value returned is the quantile of values recorded in the histogram that are smaller than or equivalent to the given value.

Two values are considered “equivalent” if self.equivalent would return true.

If the value is larger than the maximum representable value, it will be clamped to the max representable value.

If the total count of the histogram has reached u64::max_value(), this will return inaccurate results.

Get the count of recorded values within a range of value levels (inclusive to within the histogram’s resolution).

low gives the lower value bound on the range for which to provide the recorded count. Will be rounded down with lowest_equivalent. Similarly, high gives the higher value bound on the range, and will be rounded up with highest_equivalent. The function returns the total count of values recorded in the histogram within the value range that is >= lowest_equivalent(low) and <= highest_equivalent(high).

If either value is larger than the maximum representable value, it will be clamped to the max representable value.

The count will saturate at u64::max_value().

Get the count of recorded values at a specific value (to within the histogram resolution at the value level).

The count is computed across values recorded in the histogram that are within the value range that is >= lowest_equivalent(value) and <= highest_equivalent(value).

If the value is larger than the maximum representable value, it will be clamped to the max representable value.

Get the lowest value that is equivalent to the given value within the histogram’s resolution. Equivalent here means that value samples recorded for any two equivalent values are counted in a common total count.

Get the highest value that is equivalent to the given value within the histogram’s resolution. Equivalent here means that value samples recorded for any two equivalent values are counted in a common total count.

Note that the return value is capped at u64::max_value().

Get a value that lies in the middle (rounded up) of the range of values equivalent the given value. Equivalent here means that value samples recorded for any two equivalent values are counted in a common total count.

Note that the return value is capped at u64::max_value().

Get the next value that is not equivalent to the given value within the histogram’s resolution. Equivalent means that value samples recorded for any two equivalent values are counted in a common total count.

Note that the return value is capped at u64::max_value().

Get the size (in value units) of the range of values that are equivalent to the given value within the histogram’s resolution. Equivalent here means that value samples recorded for any two equivalent values are counted in a common total count.

Trait Implementations

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.