bug 1440673 - Set the max number of event summary keys by pref r?Dexter draft
authorChris H-C <chutten@mozilla.com>
Wed, 28 Mar 2018 13:58:33 -0400
changeset 778101 078a5167589c2a5979a2d2d42b68d546ff01414d
parent 778100 713661f72164b7b7cb2b03672fab33ebd1adeb40
child 778102 65524bb81db80c2adc91e58ff3a6ce5fe4d2b073
push id105384
push userbmo:chutten@mozilla.com
push dateThu, 05 Apr 2018 20:33:48 +0000
reviewersDexter
bugs1440673
milestone61.0a1
bug 1440673 - Set the max number of event summary keys by pref r?Dexter Introducing the pref toolkit.telemetry.maxEventSummaryKeys which we should hopefully never have to think about because (and yes, I risk being quoted in future for this): 500 unique event names per process ought to be enough. We check the preference just once but have to set it each time as the KeyedScalar object may have been recreated while we weren't looking. MozReview-Commit-ID: 8IE9dcfuynh
toolkit/components/telemetry/TelemetryScalar.cpp
--- a/toolkit/components/telemetry/TelemetryScalar.cpp
+++ b/toolkit/components/telemetry/TelemetryScalar.cpp
@@ -13,26 +13,28 @@
 #include "nsDataHashtable.h"
 #include "nsIXPConnect.h"
 #include "nsContentUtils.h"
 #include "nsThreadUtils.h"
 #include "nsJSUtils.h"
 #include "nsPrintfCString.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/PContent.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Unused.h"
 
 #include "TelemetryCommon.h"
 #include "TelemetryScalar.h"
 #include "TelemetryScalarData.h"
 #include "ipc/TelemetryComms.h"
 #include "ipc/TelemetryIPCAccumulator.h"
 
+using mozilla::Preferences;
 using mozilla::StaticAutoPtr;
 using mozilla::StaticMutex;
 using mozilla::StaticMutexAutoLock;
 using mozilla::Telemetry::Common::AutoHashtable;
 using mozilla::Telemetry::Common::IsExpiredVersion;
 using mozilla::Telemetry::Common::CanRecordDataset;
 using mozilla::Telemetry::Common::IsInDataset;
 using mozilla::Telemetry::Common::LogToBrowserConsole;
@@ -2548,16 +2550,22 @@ TelemetryScalar::SummarizeEvent(const ns
   KeyedScalar* scalar = nullptr;
   nsresult rv = internal_GetKeyedScalarByEnum(lock, scalarKey, aProcessType, &scalar);
 
   if (NS_FAILED(rv)) {
     NS_WARNING("NS_FAILED getting keyed scalar telemetry.event_counts. Wut.");
     return;
   }
 
+  static uint32_t sMaxEventSummaryKeys =
+    Preferences::GetUint("toolkit.telemetry.maxEventSummaryKeys", 500);
+
+  // Set this each time as it may have been cleared and recreated between calls
+  scalar->SetMaximumNumberOfKeys(sMaxEventSummaryKeys);
+
   scalar->AddValue(NS_ConvertASCIItoUTF16(aUniqueEventName), 1);
 }
 
 /**
  * Resets all the stored scalars. This is intended to be only used in tests.
  */
 void
 TelemetryScalar::ClearScalars()