Bug 1067547 - unify ScopedLogging implementations and use in nsEmbedFunctions; r=bsmedberg
authorTom Tromey <tom@tromey.com>
Mon, 26 Sep 2016 11:06:38 -0600
changeset 316201 e8f4dc9c44cc79fcc35913c8d87063dfabbe127e
parent 316200 326e6c945c377e7a55a9de179cffc2ef0c711826
child 316202 4b9239a43a013638d7ad4c063a422b31aab3e1ed
push id32770
push userttromey@mozilla.com
push dateMon, 03 Oct 2016 19:21:33 +0000
treeherderautoland@e8f4dc9c44cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1067547
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1067547 - unify ScopedLogging implementations and use in nsEmbedFunctions; r=bsmedberg MozReview-Commit-ID: 6hDZDaBsNFM
b2g/app/nsBrowserApp.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
xpcom/build/nsXPCOM.h
xpcom/tests/TestHarness.h
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -75,26 +75,16 @@ static bool IsArg(const char* arg, const
 #if defined(XP_WIN)
   if (*arg == '/')
     return !strcasecmp(++arg, s);
 #endif
 
   return false;
 }
 
-/**
- * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
- */
-class ScopedLogging
-{
-public:
-  ScopedLogging() { NS_LogInit(); }
-  ~ScopedLogging() { NS_LogTerm(); }
-};
-
 XRE_GetFileFromPathType XRE_GetFileFromPath;
 XRE_CreateAppDataType XRE_CreateAppData;
 XRE_FreeAppDataType XRE_FreeAppData;
 XRE_TelemetryAccumulateType XRE_TelemetryAccumulate;
 XRE_mainType XRE_main;
 
 static const nsDynamicFunctionLoad kXULFuncs[] = {
     { "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1552,26 +1552,16 @@ ScopedXPCOMStartup::CreateAppSupport(nsI
   if (!gNativeAppSupport)
     return NS_ERROR_NOT_INITIALIZED;
 
   return gNativeAppSupport->QueryInterface(aIID, aResult);
 }
 
 nsINativeAppSupport* ScopedXPCOMStartup::gNativeAppSupport;
 
-/**
- * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
- */
-class ScopedLogging
-{
-public:
-  ScopedLogging() { NS_LogInit(); }
-  ~ScopedLogging() { NS_LogTerm(); }
-};
-
 static void DumpArbitraryHelp()
 {
   nsresult rv;
 
   ScopedLogging log;
 
   {
     ScopedXPCOMStartup xpcom;
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -362,30 +362,30 @@ XRE_InitChildProcess(int aArgc,
 #if defined(MOZ_SANDBOX)
   if (aChildData->sandboxTargetServices) {
     SandboxTarget::Instance()->SetTargetServices(aChildData->sandboxTargetServices);
   }
 #endif
 #endif
 
   // NB: This must be called before profiler_init
-  NS_LogInit();
+  ScopedLogging logger;
 
   // This is needed by Telemetry to initialize histogram collection.
   // NB: This must be called after NS_LogInit().
   // NS_LogInit must be called before Telemetry::CreateStatisticsRecorder
   // so as to avoid many log messages of the form
   //   WARNING: XPCOM objects created/destroyed from static ctor/dtor: [..]
   // See bug 1279614.
   Telemetry::CreateStatisticsRecorder();
 
   mozilla::LogModule::Init();
 
   char aLocal;
-  profiler_init(&aLocal);
+  GeckoProfilerInitRAII profiler(&aLocal);
 
   PROFILER_LABEL("Startup", "XRE_InitChildProcess",
     js::ProfileEntry::Category::OTHER);
 
   // Complete 'task_t' exchange for Mac OS X. This structure has the same size
   // regardless of architecture so we don't have any cross-arch issues here.
 #ifdef XP_MACOSX
   if (aArgc < 1)
@@ -554,18 +554,16 @@ XRE_InitChildProcess(int aArgc,
     }
   }
 #endif
 
   base::AtExitManager exitManager;
 
   nsresult rv = XRE_InitCommandLine(aArgc, aArgv);
   if (NS_FAILED(rv)) {
-    profiler_shutdown();
-    NS_LogTerm();
     return NS_ERROR_FAILURE;
   }
 
   MessageLoop::Type uiLoopType;
   switch (XRE_GetProcessType()) {
   case GeckoProcessType_Content:
   case GeckoProcessType_GPU:
       // Content processes need the XPCOM/chromium frankenventloop
@@ -664,18 +662,16 @@ XRE_InitChildProcess(int aArgc,
         process = new gfx::GPUProcessImpl(parentPID);
         break;
 
       default:
         NS_RUNTIMEABORT("Unknown main thread class");
       }
 
       if (!process->Init()) {
-        profiler_shutdown();
-        NS_LogTerm();
         return NS_ERROR_FAILURE;
       }
 
 #ifdef MOZ_CRASHREPORTER
 #if defined(XP_WIN) || defined(XP_MACOSX)
       CrashReporter::InitChildProcessTmpDir();
 #endif
 #endif
@@ -712,18 +708,16 @@ XRE_InitChildProcess(int aArgc,
 #if defined(XP_MACOSX)
       // Everybody should be done using shared memory by now.
       mozilla::ipc::SharedMemoryBasic::Shutdown();
 #endif
     }
   }
 
   Telemetry::DestroyStatisticsRecorder();
-  profiler_shutdown();
-  NS_LogTerm();
   return XRE_DeinitCommandLine();
 }
 
 MessageLoop*
 XRE_GetIOMessageLoop()
 {
   if (sChildProcessType == GeckoProcessType_Default) {
     return BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
--- a/tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
+++ b/tools/fuzzing/libfuzzer/harness/LibFuzzerTestHarness.h
@@ -70,30 +70,16 @@ void passed(const char* msg, ...)
   vprintf(msg, ap);
   va_end(ap);
 
   putchar('\n');
 }
 
 //-----------------------------------------------------------------------------
 
-class ScopedLogging
-{
-public:
-    ScopedLogging()
-    {
-        NS_LogInit();
-    }
-
-    ~ScopedLogging()
-    {
-        NS_LogTerm();
-    }
-};
-
 static class ScopedXPCOM : public nsIDirectoryServiceProvider2
 {
   public:
     NS_DECL_ISUPPORTS
 
     explicit ScopedXPCOM(const char* testName,
                          nsIDirectoryServiceProvider *dirSvcProvider = nullptr)
     : mDirSvcProvider(dirSvcProvider)
--- a/xpcom/build/nsXPCOM.h
+++ b/xpcom/build/nsXPCOM.h
@@ -263,16 +263,37 @@ XPCOM_API(void) NS_DebugBreak(uint32_t a
  * NS_LogTerm allow applications to enable logging earlier and delay
  * printing of logging statistics. They should always be used as a
  * matched pair.
  */
 XPCOM_API(void) NS_LogInit();
 
 XPCOM_API(void) NS_LogTerm();
 
+#ifdef __cplusplus
+/**
+ * A helper class that calls NS_LogInit in its constructor and
+ * NS_LogTerm in its destructor.
+ */
+
+class ScopedLogging
+{
+public:
+    ScopedLogging()
+    {
+        NS_LogInit();
+    }
+
+    ~ScopedLogging()
+    {
+        NS_LogTerm();
+    }
+};
+#endif
+
 /**
  * Log construction and destruction of objects. Processing tools can use the
  * stacktraces printed by these functions to identify objects that are being
  * leaked.
  *
  * @param aPtr          A pointer to the concrete object.
  * @param aTypeName     The class name of the type
  * @param aInstanceSize The size of the type
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -68,30 +68,16 @@ void passed(const char* msg, ...)
   vprintf(msg, ap);
   va_end(ap);
 
   putchar('\n');
 }
 
 //-----------------------------------------------------------------------------
 
-class ScopedLogging
-{
-public:
-    ScopedLogging()
-    {
-        NS_LogInit();
-    }
-
-    ~ScopedLogging()
-    {
-        NS_LogTerm();
-    }
-};
-
 class ScopedXPCOM : public nsIDirectoryServiceProvider2
 {
   public:
     NS_DECL_ISUPPORTS
 
     explicit ScopedXPCOM(const char* testName,
                          nsIDirectoryServiceProvider *dirSvcProvider = nullptr)
     : mDirSvcProvider(dirSvcProvider)