Bug 1338555 - Add an accumulation limit to Scalars IPC messages; r?chutten
This patch adds an accumulation limit to Scalars IPC messages,
in a similar way as this limit was already implemented for Histograms.
After a discussion in the bug entry, 10000 was chosen as limit.
MozReview-Commit-ID: ARBUOFnfDBr
--- a/toolkit/components/telemetry/ipc/TelemetryIPCAccumulator.cpp
+++ b/toolkit/components/telemetry/ipc/TelemetryIPCAccumulator.cpp
@@ -36,16 +36,17 @@ namespace TelemetryIPCAccumulator = mozi
// sending them all at once. This value was chosen as a balance between data
// timeliness and performance (see bug 1218576)
const uint32_t kBatchTimeoutMs = 2000;
// To stop growing unbounded in memory while waiting for kBatchTimeoutMs to
// drain the probe accumulation arrays, we request an immediate flush if the
// arrays manage to reach certain high water mark of elements.
const size_t kHistogramAccumulationsArrayHighWaterMark = 5 * 1024;
+const size_t kScalarActionsArrayHighWaterMark = 10000;
// With the current limits, events cost us about 1100 bytes each.
// This limits memory use to about 10MB.
const size_t kEventsArrayHighWaterMark = 10000;
// This timer is used for batching and sending child process accumulations to the parent.
nsITimer* gIPCTimer = nullptr;
mozilla::Atomic<bool, mozilla::Relaxed> gIPCTimerArmed(false);
mozilla::Atomic<bool, mozilla::Relaxed> gIPCTimerArming(false);
@@ -151,32 +152,42 @@ void
TelemetryIPCAccumulator::RecordChildScalarAction(mozilla::Telemetry::ScalarID aId,
ScalarActionType aAction, const ScalarVariant& aValue)
{
StaticMutexAutoLock locker(gTelemetryIPCAccumulatorMutex);
// Make sure to have the storage.
if (!gChildScalarsActions) {
gChildScalarsActions = new nsTArray<ScalarAction>();
}
+ if (gChildScalarsActions->Length() == kScalarActionsArrayHighWaterMark) {
+ TelemetryIPCAccumulator::DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
+ TelemetryIPCAccumulator::IPCTimerFired(nullptr, nullptr);
+ }));
+ }
// Store the action.
gChildScalarsActions->AppendElement(ScalarAction{aId, aAction, Some(aValue)});
ArmIPCTimer(locker);
}
void
TelemetryIPCAccumulator::RecordChildKeyedScalarAction(mozilla::Telemetry::ScalarID aId,
const nsAString& aKey,
ScalarActionType aAction,
const ScalarVariant& aValue)
{
StaticMutexAutoLock locker(gTelemetryIPCAccumulatorMutex);
// Make sure to have the storage.
if (!gChildKeyedScalarsActions) {
gChildKeyedScalarsActions = new nsTArray<KeyedScalarAction>();
}
+ if (gChildKeyedScalarsActions->Length() == kScalarActionsArrayHighWaterMark) {
+ TelemetryIPCAccumulator::DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
+ TelemetryIPCAccumulator::IPCTimerFired(nullptr, nullptr);
+ }));
+ }
// Store the action.
gChildKeyedScalarsActions->AppendElement(
KeyedScalarAction{aId, aAction, NS_ConvertUTF16toUTF8(aKey), Some(aValue)});
ArmIPCTimer(locker);
}
void
TelemetryIPCAccumulator::RecordChildEvent(const mozilla::TimeStamp& timestamp,