Bug 1340928 (part 10) - Remove nested calls to profiler_{init,shutdown}(). r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 15 Feb 2017 17:08:38 +1100
changeset 373482 aa7e56055a3ec7b7b4bec6a5a1bc9265e0cb4a4d
parent 373481 b6b681adb0173c3d41faec2e7ff1cea163b6fdb6
child 373483 c6afc9b586b6f81b7f7bce2cff2e0cc1e8623282
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1340928
milestone54.0a1
Bug 1340928 (part 10) - Remove nested calls to profiler_{init,shutdown}(). r=mstange. The profiler can currently handle nested calls to profiler_{init,shutdown}() -- only the first call to profiler_init() and the last call to profiler_shutdown() do anything. And sure enough, we have the following. - Outer init/shutdown pairs in XRE_main()/XRE_InitChildProcess() (via GeckoProfilerInitRAII). - Inner init/shutdown pairs in NS_InitXPCOM2()/NS_InitMinimalXPCOM() (both shut down in ShutdownXPCOM()). This is a bit silly, so the patch removes the inner pairs, and adds a now-needed pair in XRE_XPCShellMain. This will allow gInitCount -- which tracks the nesting depth -- to be removed in a future patch.
js/xpconnect/src/XPCShellImpl.cpp
xpcom/build/XPCOMInit.cpp
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -29,16 +29,17 @@
 #include "xpcpublic.h"
 #include "xpcprivate.h"
 #include "BackstagePass.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsJSUtils.h"
 #include "gfxPrefs.h"
 #include "nsIXULRuntime.h"
+#include "GeckoProfiler.h"
 
 #include "base/histogram.h"
 
 #ifdef ANDROID
 #include <android/log.h>
 #endif
 
 #ifdef XP_WIN
@@ -1300,16 +1301,19 @@ XRE_XPCShellMain(int argc, char** argv, 
 
     mozilla::LogModule::Init();
 
     // A initializer to initialize histogram collection
     // used by telemetry.
     UniquePtr<base::StatisticsRecorder> telStats =
        MakeUnique<base::StatisticsRecorder>();
 
+    char aLocal;
+    profiler_init(&aLocal);
+
     if (PR_GetEnv("MOZ_CHAOSMODE")) {
         ChaosFeature feature = ChaosFeature::Any;
         long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16);
         if (featureInt) {
             // NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
             feature = static_cast<ChaosFeature>(featureInt);
         }
         ChaosMode::SetChaosFeature(feature);
@@ -1647,16 +1651,20 @@ XRE_XPCShellMain(int argc, char** argv, 
     dirprovider.ClearAppFile();
 
 #ifdef MOZ_CRASHREPORTER
     // Shut down the crashreporter service to prevent leaking some strings it holds.
     if (CrashReporter::GetEnabled())
         CrashReporter::UnsetExceptionHandler();
 #endif
 
+    // This must precede NS_LogTerm(), otherwise xpcshell return non-zero
+    // during some tests, which causes failures.
+    profiler_shutdown();
+
     NS_LogTerm();
 
     return result;
 }
 
 void
 XPCShellDirProvider::SetGREDirs(nsIFile* greDir)
 {
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -489,18 +489,16 @@ NS_InitXPCOM2(nsIServiceManager** aResul
   mozPoisonValueInit();
 
   NS_LogInit();
 
   NS_InitAtomTable();
 
   mozilla::LogModule::Init();
 
-  char aLocal;
-  profiler_init(&aLocal);
   nsresult rv = NS_OK;
 
   // We are not shutting down
   gXPCOMShuttingDown = false;
 
   // Initialize the available memory tracker before other threads have had a
   // chance to start up, because the initialization is not thread-safe.
   mozilla::AvailableMemoryTracker::Init();
@@ -777,19 +775,16 @@ NS_InitMinimalXPCOM()
 {
   mozPoisonValueInit();
   NS_SetMainThread();
   mozilla::TimeStamp::Startup();
   NS_LogInit();
   NS_InitAtomTable();
   mozilla::LogModule::Init();
 
-  char aLocal;
-  profiler_init(&aLocal);
-
   nsresult rv = nsThreadManager::get().Init();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Init the SystemGroup for dispatching main thread runnables.
   SystemGroup::InitStatic();
 
@@ -1097,18 +1092,16 @@ ShutdownXPCOM(nsIServiceManager* aServMg
 
   HangMonitor::Shutdown();
 
   delete sMainHangMonitor;
   sMainHangMonitor = nullptr;
 
   BackgroundHangMonitor::Shutdown();
 
-  profiler_shutdown();
-
   NS_LogTerm();
 
 #if defined(MOZ_WIDGET_GONK)
   // This _exit(0) call is intended to be temporary, to get shutdown leak
   // checking working on non-B2G platforms.
   // On debug B2G, the child process crashes very late.  Instead, just
   // give up so at least we exit cleanly. See bug 1071866.
   if (XRE_IsContentProcess()) {