glean_core/traits/
memory_distribution.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use crate::metrics::DistributionData;
6use crate::{ErrorType, TestGetValue};
7
8/// A description for the
9/// [`MemoryDistributionMetric`](crate::metrics::MemoryDistributionMetric) type.
10///
11/// When changing this trait, make sure all the operations are
12/// implemented in the related type in `../metrics/`.
13pub trait MemoryDistribution: TestGetValue<Output = DistributionData> {
14    /// Accumulates the provided sample in the metric.
15    ///
16    /// # Arguments
17    ///
18    /// * `sample` - The sample to be recorded by the metric. The sample is assumed to be in the
19    ///   configured memory unit of the metric.
20    ///
21    /// ## Notes
22    ///
23    /// Values bigger than 1 Terabyte (2<sup>40</sup> bytes) are truncated
24    /// and an `ErrorType::InvalidValue` error is recorded.
25    fn accumulate(&self, sample: u64);
26
27    /// Accumulates the provided signed samples in the metric.
28    ///
29    /// This is required so that the platform-specific code can provide us with
30    /// 64 bit signed integers if no `u64` comparable type is available. This
31    /// will take care of filtering and reporting errors for any provided negative
32    /// sample.
33    ///
34    /// Please note that this assumes that the provided samples are already in
35    /// the "unit" declared by the instance of the metric type (e.g. if the the
36    /// instance this method was called on is using [`crate::MemoryUnit::Kilobyte`], then
37    /// `samples` are assumed to be in that unit).
38    ///
39    /// # Arguments
40    ///
41    /// * `samples` - The vector holding the samples to be recorded by the metric.
42    ///
43    /// ## Notes
44    ///
45    /// Discards any negative value in `samples` and report an [`ErrorType::InvalidValue`]
46    /// for each of them.
47    ///
48    /// Values bigger than 1 Terabyte (2<sup>40</sup> bytes) are truncated
49    /// and an [`ErrorType::InvalidValue`] error is recorded.
50    fn accumulate_samples(&self, samples: Vec<i64>);
51
52    /// **Exported for test purposes.**
53    ///
54    /// Gets the number of recorded errors for the given error type.
55    ///
56    /// # Arguments
57    ///
58    /// * `error` - The type of error
59    ///
60    /// # Returns
61    ///
62    /// The number of errors recorded.
63    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
64}