Bug 1313326 - Part 4: Flush the event IPC buffer when hitting a limit. r=chutten
☠☠ backed out by 6a3af7c02138 ☠ ☠
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 15 Feb 2017 17:00:41 +0100
changeset 345334 bc61502be42e77e1dac46183c7a9075768f8292d
parent 345333 fe98d700bb64c12285d49e4a7cc77473fa72326e
child 345335 49a7a91b73ccf43451e9da4c5d78792d5ef30837
push id31436
push userkwierso@gmail.com
push dateThu, 02 Mar 2017 01:18:52 +0000
treeherdermozilla-central@e91de6fb2b3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1313326
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1313326 - Part 4: Flush the event IPC buffer when hitting a limit. r=chutten
toolkit/components/telemetry/ipc/TelemetryIPCAccumulator.cpp
--- a/toolkit/components/telemetry/ipc/TelemetryIPCAccumulator.cpp
+++ b/toolkit/components/telemetry/ipc/TelemetryIPCAccumulator.cpp
@@ -33,19 +33,22 @@ namespace TelemetryIPCAccumulator = mozi
 
 // Sending each remote accumulation immediately places undue strain on the
 // IPC subsystem. Batch the remote accumulations for a period of time before
 // 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 g*Accumulations arrays, request an immediate flush if the arrays
-// manage to reach this high water mark of elements.
+// 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;
+// 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);
 
 // This batches child process accumulations that should be sent to the parent.
 StaticAutoPtr<nsTArray<Accumulation>> gHistogramAccumulations;
@@ -179,20 +182,28 @@ void
 TelemetryIPCAccumulator::RecordChildEvent(double timestamp,
                                           const nsACString& category,
                                           const nsACString& method,
                                           const nsACString& object,
                                           const mozilla::Maybe<nsCString>& value,
                                           const nsTArray<mozilla::Telemetry::EventExtraEntry>& extra)
 {
   StaticMutexAutoLock locker(gTelemetryIPCAccumulatorMutex);
+
   if (!gChildEvents) {
     gChildEvents = new nsTArray<ChildEventData>();
   }
-  // Store the action.
+
+  if (gChildEvents->Length() == kEventsArrayHighWaterMark) {
+    TelemetryIPCAccumulator::DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
+      TelemetryIPCAccumulator::IPCTimerFired(nullptr, nullptr);
+    }));
+  }
+
+  // Store the event.
   gChildEvents->AppendElement(ChildEventData{timestamp, nsCString(category),
                                              nsCString(method), nsCString(object),
                                              value,
                                              nsTArray<mozilla::Telemetry::EventExtraEntry>(extra)});
   ArmIPCTimer(locker);
 }
 
 // This method takes the lock only to double-buffer the batched telemetry.