summaryrefslogtreecommitdiffstats
path: root/third_party/rust/glean-core/src/metrics/custom_distribution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/glean-core/src/metrics/custom_distribution.rs')
-rw-r--r--third_party/rust/glean-core/src/metrics/custom_distribution.rs38
1 files changed, 32 insertions, 6 deletions
diff --git a/third_party/rust/glean-core/src/metrics/custom_distribution.rs b/third_party/rust/glean-core/src/metrics/custom_distribution.rs
index 929e4863ec..c7f3fbc56f 100644
--- a/third_party/rust/glean-core/src/metrics/custom_distribution.rs
+++ b/third_party/rust/glean-core/src/metrics/custom_distribution.rs
@@ -84,14 +84,33 @@ impl CustomDistributionMetric {
/// for each of them.
pub fn accumulate_samples(&self, samples: Vec<i64>) {
let metric = self.clone();
- crate::launch_with_glean(move |glean| metric.accumulate_samples_sync(glean, samples))
+ crate::launch_with_glean(move |glean| metric.accumulate_samples_sync(glean, &samples))
+ }
+
+ /// Accumulates precisely one signed sample and appends it to the metric.
+ ///
+ /// Signed is required so that the platform-specific code can provide us with a
+ /// 64 bit signed integer if no `u64` comparable type is available. This
+ /// will take care of filtering and reporting errors.
+ ///
+ /// # Arguments
+ ///
+ /// - `sample` - The singular sample to be recorded by the metric.
+ ///
+ /// ## Notes
+ ///
+ /// Discards any negative value of `sample` and reports an
+ /// [`ErrorType::InvalidValue`](crate::ErrorType::InvalidValue).
+ pub fn accumulate_single_sample(&self, sample: i64) {
+ let metric = self.clone();
+ crate::launch_with_glean(move |glean| metric.accumulate_samples_sync(glean, &[sample]))
}
/// Accumulates the provided sample in the metric synchronously.
///
/// See [`accumulate_samples`](Self::accumulate_samples) for details.
#[doc(hidden)]
- pub fn accumulate_samples_sync(&self, glean: &Glean, samples: Vec<i64>) {
+ pub fn accumulate_samples_sync(&self, glean: &Glean, samples: &[i64]) {
if !self.should_record(glean) {
return;
}
@@ -132,7 +151,7 @@ impl CustomDistributionMetric {
self.bucket_count as usize,
)
};
- accumulate(&samples, hist, Metric::CustomDistributionLinear)
+ accumulate(samples, hist, Metric::CustomDistributionLinear)
}
HistogramType::Exponential => {
let hist = if let Some(Metric::CustomDistributionExponential(hist)) = old_value
@@ -145,7 +164,7 @@ impl CustomDistributionMetric {
self.bucket_count as usize,
)
};
- accumulate(&samples, hist, Metric::CustomDistributionExponential)
+ accumulate(samples, hist, Metric::CustomDistributionExponential)
}
};
@@ -194,6 +213,15 @@ impl CustomDistributionMetric {
/// Gets the currently stored value as an integer.
///
/// This doesn't clear the stored value.
+ ///
+ /// # Arguments
+ ///
+ /// * `ping_name` - the optional name of the ping to retrieve the metric
+ /// for. Defaults to the first value in `send_in_pings`.
+ ///
+ /// # Returns
+ ///
+ /// The stored value or `None` if nothing stored.
pub fn test_get_value(&self, ping_name: Option<String>) -> Option<DistributionData> {
crate::block_on_dispatcher();
crate::core::with_glean(|glean| self.get_value(glean, ping_name.as_deref()))
@@ -206,8 +234,6 @@ impl CustomDistributionMetric {
/// # Arguments
///
/// * `error` - The type of error
- /// * `ping_name` - represents the optional name of the ping to retrieve the
- /// metric for. inner to the first value in `send_in_pings`.
///
/// # Returns
///