bug 1218576 - Pre-allocate child keyed histograms in the parent process r=gfritzsche
authorChris H-C <chutten@mozilla.com>
Wed, 29 Jun 2016 15:38:35 -0400
changeset 314438 1b2b8973c8a2debe79803db16ebd514629a8df2c
parent 314437 832793e20c54a1fc6a2c6573e9205e2e783a3676
child 314439 712681439306713ccaf6cab6c7e3098ef995390b
push id20574
push usercbook@mozilla.com
push dateTue, 20 Sep 2016 10:05:16 +0000
treeherderfx-team@14705f779a46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1218576
milestone51.0a1
bug 1218576 - Pre-allocate child keyed histograms in the parent process r=gfritzsche I originally thought we'd be able to avoid the previous implementation's waste of a map full of every kind of keyed histogram. Unfortunately, other code (TelemetrySession at the very least) depends on this (and will throw if a keyed histogram isn't present, even if it is empty) MozReview-Commit-ID: 8MCGVa595UB
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -1843,22 +1843,17 @@ internal_AccumulateChildKeyed(mozilla::T
   if (!gInitDone || !internal_CanRecordBase()) {
     return;
   }
   const HistogramInfo& th = gHistograms[aId];
   nsCString id;
   id.Append(th.id());
   id.AppendLiteral(CHILD_HISTOGRAM_SUFFIX);
   KeyedHistogram* keyed = internal_GetKeyedHistogramById(id);
-  if (!keyed) {
-    const nsDependentCString expiration(th.expiration());
-    keyed = new KeyedHistogram(id, expiration, th.histogramType, th.min, th.max,
-                               th.bucketCount, th.dataset);
-    gKeyedHistograms.Put(id, keyed);
-  }
+  MOZ_ASSERT(keyed);
   keyed->Add(aKey, aSample);
 }
 
 } // namespace
 
 
 ////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////
@@ -1931,16 +1926,26 @@ void TelemetryHistogram::InitializeGloba
     if (!h.keyed) {
       continue;
     }
 
     const nsDependentCString id(h.id());
     const nsDependentCString expiration(h.expiration());
     gKeyedHistograms.Put(id, new KeyedHistogram(id, expiration, h.histogramType,
                                                 h.min, h.max, h.bucketCount, h.dataset));
+    if (XRE_IsParentProcess()) {
+      // We must create registered child keyed histograms as well or else the
+      // same code in TelemetrySession.jsm that fails without parent keyed
+      // histograms will fail without child keyed histograms.
+      nsCString childId(id);
+      childId.AppendLiteral(CHILD_HISTOGRAM_SUFFIX);
+      gKeyedHistograms.Put(childId,
+                           new KeyedHistogram(id, expiration, h.histogramType,
+                                              h.min, h.max, h.bucketCount, h.dataset));
+    }
   }
 
   // Some Telemetry histograms depend on the value of C++ constants and hardcode
   // their values in Histograms.json.
   // We add static asserts here for those values to match so that future changes
   // don't go unnoticed.
   // TODO: Compare explicitly with gHistograms[<histogram id>].bucketCount here
   // once we can make gHistograms constexpr (requires VS2015).