Bug 1065258 (part 6) - Factor out code shared by DumpMemoryReportsToNamedFile() and DumpMemoryInfoToTempDir(). r=jld.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 10 Sep 2014 00:40:10 -0700
changeset 227992 68ea49d3131636ddb547e3e09c5d89db326b1920
parent 227991 f43ce1b77bee82035b24d449626bba60b94cabbe
child 227993 468af76c47a758cb76a70f7095c6183f69819f03
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjld
bugs1065258
milestone35.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 1065258 (part 6) - Factor out code shared by DumpMemoryReportsToNamedFile() and DumpMemoryInfoToTempDir(). r=jld.
xpcom/base/nsMemoryInfoDumper.cpp
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -699,16 +699,53 @@ private:
   ~TempDirMemoryFinishCallback() {}
 
   nsCOMPtr<nsIFile> mReportsTmpFile;
   nsCString mReportsFilename;
 };
 
 NS_IMPL_ISUPPORTS(TempDirMemoryFinishCallback, nsIFinishDumpingCallback)
 
+static nsresult
+DumpMemoryInfoToFile(
+  nsIFile* aReportsFile,
+  nsIFinishDumpingCallback* aFinishDumping,
+  nsISupports* aFinishDumpingData,
+  bool aAnonymize,
+  bool aMinimizeMemoryUsage,
+  nsAString& aDMDIdentifier)
+{
+  nsRefPtr<nsGZFileWriter> reportsWriter = new nsGZFileWriter();
+  nsresult rv = reportsWriter->Init(aReportsFile);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  // Dump the memory reports to the file.
+  rv = DumpHeader(reportsWriter);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  // Process reporters.
+  nsCOMPtr<nsIMemoryReporterManager> mgr =
+    do_GetService("@mozilla.org/memory-reporter-manager;1");
+  nsRefPtr<DumpReportCallback> dumpReport =
+    new DumpReportCallback(reportsWriter);
+  nsRefPtr<FinishReportingCallback> finishReporting =
+    new FinishReportingCallback(reportsWriter, aFinishDumping,
+                                aFinishDumpingData);
+  rv = mgr->GetReportsExtended(dumpReport, nullptr,
+                               finishReporting, nullptr,
+                               aAnonymize,
+                               aMinimizeMemoryUsage,
+                               aDMDIdentifier);
+  return rv;
+}
+
 NS_IMETHODIMP
 nsMemoryInfoDumper::DumpMemoryInfoToTempDir(const nsAString& aIdentifier,
                                             bool aAnonymize,
                                             bool aMinimizeMemoryUsage)
 {
   nsString identifier(aIdentifier);
   EnsureNonEmptyIdentifier(identifier);
 
@@ -743,41 +780,18 @@ nsMemoryInfoDumper::DumpMemoryInfoToTemp
                                  NS_LITERAL_CSTRING("memory-reports"));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsRefPtr<TempDirMemoryFinishCallback> finishDumping =
     new TempDirMemoryFinishCallback(reportsTmpFile, reportsFinalFilename);
 
-  nsRefPtr<nsGZFileWriter> reportsWriter = new nsGZFileWriter();
-  rv = reportsWriter->Init(reportsTmpFile);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  // Dump the memory reports to the file.
-  rv = DumpHeader(reportsWriter);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  // Process reporters.
-  nsCOMPtr<nsIMemoryReporterManager> mgr =
-    do_GetService("@mozilla.org/memory-reporter-manager;1");
-  nsRefPtr<DumpReportCallback> dumpReport =
-    new DumpReportCallback(reportsWriter);
-  nsRefPtr<FinishReportingCallback> finishReporting =
-    new FinishReportingCallback(reportsWriter, finishDumping, nullptr);
-  rv = mgr->GetReportsExtended(dumpReport, nullptr,
-                               finishReporting, nullptr,
-                               aAnonymize,
-                               aMinimizeMemoryUsage,
-                               /* DMDident = */ identifier);
-  return rv;
+  return DumpMemoryInfoToFile(reportsTmpFile, finishDumping, nullptr,
+                              aAnonymize, aMinimizeMemoryUsage, identifier);
 }
 
 #ifdef MOZ_DMD
 nsresult
 nsMemoryInfoDumper::OpenDMDFile(const nsAString& aIdentifier, int aPid,
                                 FILE** aOutFile)
 {
   if (!dmd::IsRunning()) {
@@ -867,38 +881,15 @@ nsMemoryInfoDumper::DumpMemoryReportsToN
 
   if (!exists) {
     rv = reportsFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  // Write the memory reports to the file.
-
-  nsRefPtr<nsGZFileWriter> reportsWriter = new nsGZFileWriter();
-  rv = reportsWriter->Init(reportsFile);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = DumpHeader(reportsWriter);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  // Process reports and finish up.
-  nsCOMPtr<nsIMemoryReporterManager> mgr =
-    do_GetService("@mozilla.org/memory-reporter-manager;1");
-  nsRefPtr<DumpReportCallback> dumpReport =
-    new DumpReportCallback(reportsWriter);
-  nsRefPtr<FinishReportingCallback> finishReporting =
-    new FinishReportingCallback(reportsWriter, aFinishDumping,
-                                aFinishDumpingData);
-  rv = mgr->GetReportsExtended(dumpReport, nullptr,
-                               finishReporting, nullptr,
-                               aAnonymize,
-                               /* minimizeMemoryUsage = */ false,
-                               /* DMDident = */ EmptyString());
-  return rv;
+  nsString dmdIdent = EmptyString();
+  return DumpMemoryInfoToFile(reportsFile, aFinishDumping, aFinishDumpingData,
+                              aAnonymize, /* minimizeMemoryUsage = */ false,
+                              dmdIdent);
 }
 
 #undef DUMP