diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index 956500d8a36..ef3c38860b4 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -581,14 +581,7 @@ 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 telemetryService = - do_GetService("@mozilla.org/base/telemetry;1"); - if (!telemetryService || !sTelemetry) - return; - } - + MOZ_ASSERT(sTelemetry); if (!sTelemetry->mCanRecord || !sTelemetry->mTrackedDBs.GetEntry(dbName)) return; @@ -678,6 +671,14 @@ RecordSlowSQLStatement(const nsACString &statement, TelemetryImpl::RecordSlowStatement(statement, dbName, delay); } +void Init() +{ + // Make the service manager hold a long-lived reference to the service + nsCOMPtr telemetryService = + do_GetService("@mozilla.org/base/telemetry;1"); + MOZ_ASSERT(telemetryService); +} + } // namespace Telemetry } // namespace mozilla diff --git a/toolkit/components/telemetry/Telemetry.h b/toolkit/components/telemetry/Telemetry.h index 8e46a3f0c63..6f83cc26a12 100644 --- a/toolkit/components/telemetry/Telemetry.h +++ b/toolkit/components/telemetry/Telemetry.h @@ -59,6 +59,11 @@ enum ID { HistogramCount }; +/** + * Initialize the Telemetry service on the main thread at startup. + */ +void Init(); + /** * Adds sample to a histogram defined in TelemetryHistograms.h * diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index aff33f2f0df..14c087b53d5 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -140,6 +140,7 @@ extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **) #include "mozilla/FunctionTimer.h" #include "mozilla/Omnijar.h" #include "mozilla/HangMonitor.h" +#include "mozilla/Telemetry.h" #include "nsChromeRegistry.h" #include "nsChromeProtocolHandler.h" @@ -536,6 +537,8 @@ NS_InitXPCOM2(nsIServiceManager* *result, mozilla::HangMonitor::Startup(); + mozilla::Telemetry::Init(); + return NS_OK; }