Bug 1780621 test size limits of updated Memory Distribution Accumulate r=Dexter

Also adds a small guardrail consistent with the implementation in Timing Distribution

Differential Revision: https://phabricator.services.mozilla.com/D153384
This commit is contained in:
pmcmanis 2022-08-02 12:14:16 +00:00
Родитель 66a89641e4
Коммит e744c1f7a6
2 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -72,7 +72,12 @@ impl MemoryDistribution for MemoryDistributionMetric {
// If the value doesn't fit into `i64` it's definitely to large
// and cause an error.
// glean-core handles that.
let sample = sample.try_into().unwrap_or(i64::MAX);
let sample = sample.try_into().unwrap_or_else(|_| {
log::warn!(
"Memory size too large to fit into into 64-bytes. Saturating at i64::MAX."
);
i64::MAX
});
inner.accumulate(sample);
}
MemoryDistributionMetric::Child(c) => {

Просмотреть файл

@ -92,6 +92,31 @@ add_task(function test_gifft_memory_dist() {
Telemetry.getHistogramById("TELEMETRY_TEST_LINEAR").clear();
Assert.equal(24, data.sum, "Histogram's in `memory_unit` units");
Assert.equal(2, data.values["1"], "Both samples in a low bucket");
// MemoryDistribution's Accumulate method to takes
// a platform specific type (size_t).
// Glean's, however, is i64, and, glean_memory_dist is uint64_t
// What happens when we give accumulate dubious values?
// This may occur on some uncommon platforms.
Glean.testOnlyIpc.aMemoryDist.accumulate(Math.pow(2, 65));
let dubiousValue = Object.entries(
Glean.testOnlyIpc.aMemoryDist.testGetValue().values
)[0][1];
Assert.equal(
dubiousValue,
1,
"Greater than 64-Byte number did not accumulate correctly"
);
// Values lower than the out-of-range value are not clamped
// resulting in an exception being thrown from the glean side
// when the value exceeds the glean maximum allowed value
Glean.testOnlyIpc.aMemoryDist.accumulate(Math.pow(2, 35));
Assert.throws(
() => Glean.testOnlyIpc.aMemoryDist.testGetValue(),
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
"Did not accumulate correctly"
);
});
add_task(function test_gifft_custom_dist() {