in glean-core/src/metrics/custom_distribution.rs [280:322]
fn commit_histogram(&self, histogram: Histogram<LinearOrExponential>) {
let metric = self.clone();
crate::launch_with_glean(move |glean| {
glean
.storage()
.record_with(glean, &metric.meta, move |old_value| {
match metric.histogram_type {
HistogramType::Linear => {
let mut hist =
if let Some(Metric::CustomDistributionLinear(hist)) = old_value {
hist
} else {
Histogram::linear(
metric.range_min,
metric.range_max,
metric.bucket_count as usize,
)
};
hist._merge(&histogram);
Metric::CustomDistributionLinear(hist)
}
HistogramType::Exponential => {
let mut hist = if let Some(Metric::CustomDistributionExponential(
hist,
)) = old_value
{
hist
} else {
Histogram::exponential(
metric.range_min,
metric.range_max,
metric.bucket_count as usize,
)
};
hist._merge(&histogram);
Metric::CustomDistributionExponential(hist)
}
}
});
});
}