Bug 1800492 - Fix division by zero when calculating GC_TENURED_SURVIVAL_RATE telemetry r=sfink

Differential Revision: https://phabricator.services.mozilla.com/D162016
This commit is contained in:
Jon Coppeard 2022-11-15 09:55:17 +00:00
parent 4bcd987494
commit a69165bcbb
2 changed files with 5 additions and 5 deletions

View File

@ -1071,7 +1071,7 @@ void Statistics::sendGCTelemetry() {
}
}
if (!lastSlice.wasReset()) {
if (!lastSlice.wasReset() && preCollectedHeapBytes != 0) {
size_t bytesSurvived = 0;
for (ZonesIter zone(runtime, WithAtoms); !zone.done(); zone.next()) {
if (zone->wasCollected()) {
@ -1080,9 +1080,9 @@ void Statistics::sendGCTelemetry() {
}
MOZ_ASSERT(preCollectedHeapBytes >= bytesSurvived);
double survialRate =
double survivalRate =
100.0 * double(bytesSurvived) / double(preCollectedHeapBytes);
runtime->metrics().GC_TENURED_SURVIVAL_RATE(uint32_t(survialRate));
runtime->metrics().GC_TENURED_SURVIVAL_RATE(uint32_t(survivalRate));
// Calculate 'effectiveness' in MB / second, on main thread only for now.
if (!runtime->parentRuntime) {

View File

@ -263,7 +263,7 @@ class Metrics {
struct Enumeration {
using SourceType = int;
static uint32_t convert(SourceType sample) {
MOZ_ASSERT(sample <= 100);
MOZ_ASSERT(sample >= 0 && sample <= 100);
return static_cast<uint32_t>(sample);
}
};
@ -274,7 +274,7 @@ class Metrics {
struct Percentage {
using SourceType = int;
static uint32_t convert(SourceType sample) {
MOZ_ASSERT(sample <= 100);
MOZ_ASSERT(sample >= 0 && sample <= 100);
return static_cast<uint32_t>(sample);
}
};