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;
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 {
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 currently stored value as a DistributionData of the serialized value.
30 ///
31 /// This doesn't clear the stored value.
32 ///
33 /// # Arguments
34 ///
35 /// * `ping_name` - represents the optional name of the ping to retrieve the
36 /// metric for. Defaults to the first value in `send_in_pings`.
37 fn test_get_value<'a, S: Into<Option<&'a str>>>(
38 &self,
39 ping_name: S,
40 ) -> Option<DistributionData>;
41
42 /// **Exported for test purposes.**
43 ///
44 /// Gets the number of recorded errors for the given error type.
45 ///
46 /// # Arguments
47 ///
48 /// * `error` - The type of error
49 ///
50 /// # Returns
51 ///
52 /// The number of errors recorded.
53 fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
54}