Bug 800486 - Part 3: Minor fixups to MemoryInfoDumper.cpp. r=njn
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 15 Oct 2012 22:12:14 -0400
changeset 110498 bdb3e55bdddae77e5c982070b0973c1101a61792
parent 110497 295110f8c8922817f9e0e001a6b47d7cc9beb9a3
child 110499 6f970ea66426bacf74f4eec4357358423b0ce4ea
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersnjn
bugs800486
milestone19.0a1
Bug 800486 - Part 3: Minor fixups to MemoryInfoDumper.cpp. r=njn
xpcom/base/MemoryInfoDumper.cpp
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/MemoryInfoDumper.cpp
+++ b/xpcom/base/MemoryInfoDumper.cpp
@@ -14,16 +14,23 @@
 #include "mozilla/dom/ContentChild.h"
 #include "nsIConsoleService.h"
 #include "nsICycleCollectorListener.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsGZFileWriter.h"
 #include "nsJSEnvironment.h"
 #include "nsPrintfCString.h"
 
+#ifdef XP_WIN
+#include <process.h>
+#define getpid _getpid
+#else
+#include <unistd.h>
+#endif
+
 #ifdef XP_LINUX
 #include <fcntl.h>
 #endif
 
 #ifdef ANDROID
 #include <sys/types.h>
 #include <sys/stat.h>
 #endif
@@ -209,20 +216,21 @@ public:
       NS_WARNING("Error reading from buffer in "
                  "SignalPipeWatcher::OnFileCanReadWithoutBlocking.");
       return;
     }
 
     if (signum == sDumpAboutMemorySignum ||
         signum == sDumpAboutMemoryAfterMMUSignum) {
       // Dump our memory reports (but run this on the main thread!).
+      bool doMMUFirst = signum == sDumpAboutMemoryAfterMMUSignum;
       nsRefPtr<DumpMemoryReportsRunnable> runnable =
         new DumpMemoryReportsRunnable(
             /* identifier = */ EmptyString(),
-            signum == sDumpAboutMemoryAfterMMUSignum,
+            doMMUFirst,
             /* dumpChildProcesses = */ true);
       NS_DispatchToMainThread(runnable);
     }
     else if (signum == sGCAndCCDumpSignum) {
       // Dump GC and CC logs (from the main thread).
       nsRefPtr<GCAndCCLogDumpRunnable> runnable =
         new GCAndCCLogDumpRunnable(
             /* identifier = */ EmptyString(),
@@ -265,30 +273,38 @@ InitializeSignalWatcher()
 /* static */ void
 MemoryInfoDumper::Initialize()
 {
 #ifdef XP_LINUX
   InitializeSignalWatcher();
 #endif
 }
 
-  /* static */ void
+static void
+EnsureNonEmptyIdentifier(nsAString& aIdentifier)
+{
+  if (!aIdentifier.IsEmpty()) {
+    return;
+  }
+
+  // If the identifier is empty, set it to the number of whole seconds since the
+  // epoch.  This identifier will appear in the files that this process
+  // generates and also the files generated by this process's children, allowing
+  // us to identify which files are from the same memory report request.
+  aIdentifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
+}
+
+/* static */ void
 MemoryInfoDumper::DumpMemoryReportsToFile(
     const nsAString& aIdentifier,
     bool aMinimizeMemoryUsage,
     bool aDumpChildProcesses)
 {
-  // If the identifier is empty, set it to the number of whole seconds since
-  // the epoch.  This identifier will appear in our memory report as well as
-  // our children's, allowing us to identify which files are from the same
-  // memory report request.
   nsString identifier(aIdentifier);
-  if (identifier.IsEmpty()) {
-    identifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
-  }
+  EnsureNonEmptyIdentifier(identifier);
 
   // Kick off memory report dumps in our child processes, if applicable.  We
   // do this before doing our own report because writing a report may be I/O
   // bound, in which case we want to busy the CPU with other reports while we
   // work on our own.
   if (aDumpChildProcesses) {
     nsTArray<ContentParent*> children;
     ContentParent::GetAll(children);
@@ -313,24 +329,18 @@ MemoryInfoDumper::DumpMemoryReportsToFil
   DumpMemoryReportsToFileImpl(identifier);
 }
 
 /* static */ void
 MemoryInfoDumper::DumpGCAndCCLogsToFile(
   const nsAString& aIdentifier,
   bool aDumpChildProcesses)
 {
-  // If the identifier is empty, set it to the number of whole seconds since
-  // the epoch.  This identifier will appear in our logs as well as our
-  // children's, allowing us to identify which files are from the same
-  // request.
   nsString identifier(aIdentifier);
-  if (identifier.IsEmpty()) {
-    identifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
-  }
+  EnsureNonEmptyIdentifier(identifier);
 
   if (aDumpChildProcesses) {
     nsTArray<ContentParent*> children;
     ContentParent::GetAll(children);
     for (uint32_t i = 0; i < children.Length(); i++) {
       unused << children[i]->SendDumpGCAndCCLogsToFile(
           identifier, aDumpChildProcesses);
     }
@@ -577,23 +587,23 @@ MemoryInfoDumper::DumpMemoryReportsToFil
   nsAutoString dstFileName;
   rv = dstFile->GetLeafName(dstFileName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = tmpFile->MoveTo(/* directory */ nullptr, dstFileName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIConsoleService> cs =
-      do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
+    do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsString path;
   tmpFile->GetPath(path);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsString msg = NS_LITERAL_STRING("nsIMemoryReporterManager::dumpReports() "
-                                   "dumped reports to ");
+  nsString msg = NS_LITERAL_STRING(
+    "nsIMemoryReporterManager::dumpReports() dumped reports to ");
   msg.Append(path);
   return cs->LogStringMessage(msg.get());
 }
 
 #undef DUMP
 } // namespace mozilla
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -17,20 +17,17 @@
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "nsThread.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Services.h"
 #include "mozilla/MemoryInfoDumper.h"
 
-#ifdef XP_WIN
-#include <process.h>
-#define getpid _getpid
-#else
+#ifndef XP_WIN
 #include <unistd.h>
 #endif
 
 using namespace mozilla;
 
 #if defined(MOZ_MEMORY)
 #  define HAVE_JEMALLOC_STATS 1
 #  include "jemalloc.h"