Bug 1260908 - Allow keyed histograms to accumulate early in startup (r=gfritzsche)
authorBill McCloskey <billm@mozilla.com>
Wed, 30 Mar 2016 15:25:18 -0700
changeset 291409 8d4ce12bda44c0d57bd52b1192e138680d1d6ba6
parent 291408 7600e2f05b9709ed88f150def0f4df259fc95e54
child 291410 c8eea76ef144eacdf9889782c80c62950a8db6fd
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1260908
milestone48.0a1
Bug 1260908 - Allow keyed histograms to accumulate early in startup (r=gfritzsche)
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -698,16 +698,17 @@ class TelemetryImpl final
 {
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSITELEMETRY
   NS_DECL_NSIMEMORYREPORTER
 
 public:
   void InitMemoryReporter();
 
+  static bool IsInitialized();
   static bool CanRecordBase();
   static bool CanRecordExtended();
   static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
   static void ShutdownTelemetry();
   static void RecordSlowStatement(const nsACString &sql, const nsACString &dbName,
                                   uint32_t delay);
 #if defined(MOZ_ENABLE_PROFILER_SPS)
   static void RecordChromeHang(uint32_t aDuration,
@@ -3304,16 +3305,22 @@ TelemetryImpl::GetCanRecordBase(bool *re
 }
 
 NS_IMETHODIMP
 TelemetryImpl::SetCanRecordBase(bool canRecord) {
   mCanRecordBase = canRecord;
   return NS_OK;
 }
 
+/* static */ bool
+TelemetryImpl::IsInitialized()
+{
+  return sTelemetry;
+}
+
 /**
  * Indicates if Telemetry can record base data (FHR data). This is true if the
  * FHR data reporting service or self-support are enabled.
  *
  * In the unlikely event that adding a new base probe is needed, please check the data
  * collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
  * Telemetry team.
  */
@@ -3897,17 +3904,17 @@ Accumulate(ID aHistogram, uint32_t aSamp
   if (NS_SUCCEEDED(rv)) {
     HistogramAdd(*h, aSample, gHistograms[aHistogram].dataset);
   }
 }
 
 void
 Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
 {
-  if (!TelemetryImpl::CanRecordBase()) {
+  if (!TelemetryImpl::IsInitialized() || !TelemetryImpl::CanRecordBase()) {
     return;
   }
   const TelemetryHistogram& th = gHistograms[aID];
   KeyedHistogram* keyed = TelemetryImpl::GetKeyedHistogramById(nsDependentCString(th.id()));
   MOZ_ASSERT(keyed);
   keyed->Add(aKey, aSample);
 }