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<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    /// **Exported for test purposes.**
28    ///
29    /// Gets the number of recorded errors for the given error type.
30    ///
31    /// # Arguments
32    ///
33    /// * `error` - The type of error
34    ///
35    /// # Returns
36    ///
37    /// The number of errors recorded.
38    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
39}