Bug 708962 - Start Telemetry service at application start to avoid deadlock from GetService spinning event loop. r=benjamin
authorVladan Djeric <vdjeric@mozilla.com>
Tue, 10 Jan 2012 15:29:58 -0500
changeset 85373 a537453b1d667a66d5272915e43499eedb3554b5
parent 85372 8eb5fd52246138ddf748a6c44e7fdbd44f5608fb
child 85374 b18d407e2321e01fcb286ed45080546d71db0c88
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenjamin
bugs708962
milestone12.0a1
Bug 708962 - Start Telemetry service at application start to avoid deadlock from GetService spinning event loop. r=benjamin
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/Telemetry.h
xpcom/build/nsXPComInit.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -576,24 +576,17 @@ TelemetryImpl::ShutdownTelemetry()
   NS_IF_RELEASE(sTelemetry);
 }
 
 void
 TelemetryImpl::RecordSlowStatement(const nsACString &statement,
                                    const nsACString &dbName,
                                    PRUint32 delay)
 {
-  if (!sTelemetry) {
-    // Make the service manager hold a long-lived reference to the service
-    nsCOMPtr<nsITelemetry> telemetryService =
-      do_GetService("@mozilla.org/base/telemetry;1");
-    if (!telemetryService || !sTelemetry)
-      return;
-  }
-
+  MOZ_ASSERT(sTelemetry);
   if (!sTelemetry->mCanRecord || !sTelemetry->mTrackedDBs.GetEntry(dbName))
     return;
 
   nsTHashtable<SlowSQLEntryType> *slowSQLMap = NULL;
   if (NS_IsMainThread())
     slowSQLMap = &(sTelemetry->mSlowSQLOnMainThread);
   else
     slowSQLMap = &(sTelemetry->mSlowSQLOnOtherThread);
@@ -673,16 +666,24 @@ GetHistogramById(ID id)
 void
 RecordSlowSQLStatement(const nsACString &statement,
                        const nsACString &dbName,
                        PRUint32 delay)
 {
   TelemetryImpl::RecordSlowStatement(statement, dbName, delay);
 }
 
+void Init()
+{
+  // Make the service manager hold a long-lived reference to the service
+  nsCOMPtr<nsITelemetry> telemetryService =
+    do_GetService("@mozilla.org/base/telemetry;1");
+  MOZ_ASSERT(telemetryService);
+}
+
 } // namespace Telemetry
 } // namespace mozilla
 
 NSMODULE_DEFN(nsTelemetryModule) = &kTelemetryModule;
 
 /**
  * The XRE_TelemetryAdd function is to be used by embedding applications
  * that can't use mozilla::Telemetry::Accumulate() directly.
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -55,16 +55,21 @@ enum ID {
 
 #include "TelemetryHistograms.h"
 
 #undef HISTOGRAM
 HistogramCount
 };
 
 /**
+ * Initialize the Telemetry service on the main thread at startup.
+ */
+void Init();
+
+/**
  * Adds sample to a histogram defined in TelemetryHistograms.h
  *
  * @param id - histogram id
  * @param sample - value to record.
  */
 void Accumulate(ID id, PRUint32 sample);
 
 /**
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -135,16 +135,17 @@ extern nsresult nsStringInputStreamConst
 #include "nsSystemInfo.h"
 #include "nsMemoryReporterManager.h"
 
 #include <locale.h>
 #include "mozilla/Services.h"
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/Omnijar.h"
 #include "mozilla/HangMonitor.h"
+#include "mozilla/Telemetry.h"
 
 #include "nsChromeRegistry.h"
 #include "nsChromeProtocolHandler.h"
 
 #include "mozilla/scache/StartupCache.h"
 
 #include "base/at_exit.h"
 #include "base/command_line.h"
@@ -531,16 +532,18 @@ NS_InitXPCOM2(nsIServiceManager* *result
 #ifdef XP_WIN
     ScheduleMediaCacheRemover();
 #endif
 
     mozilla::MapsMemoryReporter::Init();
 
     mozilla::HangMonitor::Startup();
 
+    mozilla::Telemetry::Init();
+
     return NS_OK;
 }
 
 
 //
 // NS_ShutdownXPCOM()
 //
 // The shutdown sequence for xpcom would be