bug 1312778 - Ensure histogram recording is enabled before remote accumulation r?gfritzsche draft
authorChris H-C <chutten@mozilla.com>
Wed, 26 Oct 2016 11:17:50 -0400
changeset 431732 fc714584c0b94f41875476c8e47eee220bc0fae1
parent 423604 7ae377917236b7e6111146aa9fb4c073c0efc7f4
child 535455 2d8365e92f99f6b97839dcfba0eee2f2dd5366c3
push id34097
push userbmo:chutten@mozilla.com
push dateMon, 31 Oct 2016 13:38:46 +0000
reviewersgfritzsche
bugs1312778
milestone52.0a1
bug 1312778 - Ensure histogram recording is enabled before remote accumulation r?gfritzsche There is a mechanism to selectively turn hgram recording off and on. This is presently only used to throttle an otherwise-devastatingly-chatty hgram to only contain accumulations from specific times (sync scroll). This was only checked on the parent. This checks it on the child as well. MozReview-Commit-ID: 4f0VXMHLaPW
toolkit/components/telemetry/TelemetryHistogram.cpp
toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -1336,16 +1336,21 @@ void internal_armIPCTimer()
 }
 
 bool
 internal_RemoteAccumulate(mozilla::Telemetry::ID aId, uint32_t aSample)
 {
   if (XRE_IsParentProcess()) {
     return false;
   }
+  Histogram *h;
+  nsresult rv = internal_GetHistogramByEnumId(aId, &h);
+  if (NS_SUCCEEDED(rv) && !h->IsRecordingEnabled()) {
+    return true;
+  }
   if (!gAccumulations) {
     gAccumulations = new nsTArray<Accumulation>();
   }
   if (gAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
     NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
       TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
     }));
   }
@@ -1356,16 +1361,23 @@ internal_RemoteAccumulate(mozilla::Telem
 
 bool
 internal_RemoteAccumulate(mozilla::Telemetry::ID aId,
                     const nsCString& aKey, uint32_t aSample)
 {
   if (XRE_IsParentProcess()) {
     return false;
   }
+  const HistogramInfo& th = gHistograms[aId];
+  KeyedHistogram* keyed
+     = internal_GetKeyedHistogramById(nsDependentCString(th.id()));
+  MOZ_ASSERT(keyed);
+  if (!keyed->IsRecordingEnabled()) {
+    return false;
+  }
   if (!gKeyedAccumulations) {
     gKeyedAccumulations = new nsTArray<KeyedAccumulation>();
   }
   if (gKeyedAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
     NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
       TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
     }));
   }
--- a/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
@@ -13,26 +13,33 @@ const APP_VERSION = "1";
 const APP_ID = "xpcshell@tests.mozilla.org";
 const APP_NAME = "XPCShell";
 
 function run_child_test() {
   // Setup histograms with some fixed values.
   let flagHist = Telemetry.getHistogramById("TELEMETRY_TEST_FLAG");
   flagHist.add(1);
   let countHist = Telemetry.getHistogramById("TELEMETRY_TEST_COUNT");
+  Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_COUNT", false);
+  countHist.add();
+  Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_COUNT", true);
   countHist.add();
   countHist.add();
   let categHist = Telemetry.getHistogramById("TELEMETRY_TEST_CATEGORICAL");
   categHist.add("Label2");
   categHist.add("Label3");
 
   let flagKeyed = Telemetry.getKeyedHistogramById("TELEMETRY_TEST_KEYED_FLAG");
   flagKeyed.add("a", 1);
   flagKeyed.add("b", 1);
   let countKeyed = Telemetry.getKeyedHistogramById("TELEMETRY_TEST_KEYED_COUNT");
+  Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_KEYED_COUNT", false);
+  countKeyed.add("a");
+  countKeyed.add("b");
+  Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_KEYED_COUNT", true);
   countKeyed.add("a");
   countKeyed.add("b");
   countKeyed.add("b");
 }
 
 function check_histogram_values(payload) {
   const hs = payload.histograms;
   Assert.ok("TELEMETRY_TEST_COUNT" in hs, "Should have count test histogram.");