Bug 929791 - Fix invalid JSON generation when dumping memory reports to file after viewing about:memory in the presence of child processes. r=mccr8.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 22 Oct 2013 16:58:33 -0700
changeset 165568 9d86e7b4520804b84224a9b862a0a1a388beb1a7
parent 165567 ac4f0cba097a38a663760983f47b2b1eea810272
child 165569 9a2fa71f26572444800d10741bc5fe528b5a35de
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs929791
milestone27.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 929791 - Fix invalid JSON generation when dumping memory reports to file after viewing about:memory in the presence of child processes. r=mccr8.
xpcom/base/nsMemoryInfoDumper.cpp
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -605,29 +605,30 @@ namespace mozilla {
 
 #define DUMP(o, s) \
   do { \
     nsresult rv = (o)->Write(s); \
     NS_ENSURE_SUCCESS(rv, rv); \
   } while (0)
 
 static nsresult
-DumpReport(nsIGZFileWriter *aWriter, bool aIsFirst,
+DumpReport(nsIGZFileWriter *aWriter, bool *aIsFirstPtr,
   const nsACString &aProcess, const nsACString &aPath, int32_t aKind,
   int32_t aUnits, int64_t aAmount, const nsACString &aDescription)
 {
-  DUMP(aWriter, aIsFirst ? "[" : ",");
-
   // We only want to dump reports for this process.  If |aProcess| is
   // non-nullptr that means we've received it from another process in response
   // to a "child-memory-reporter-request" event;  ignore such reports.
   if (!aProcess.IsEmpty()) {
     return NS_OK;
   }
 
+  DUMP(aWriter, *aIsFirstPtr ? "[" : ",");
+  *aIsFirstPtr = false;
+
   // Generate the process identifier, which is of the form "$PROCESS_NAME
   // (pid $PID)", or just "(pid $PID)" if we don't have a process name.  If
   // we're the main process, we let $PROCESS_NAME be "Main Process".
   nsAutoCString processId;
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     // We're the main process.
     processId.AssignLiteral("Main Process ");
   } else if (ContentChild *cc = ContentChild::GetSingleton()) {
@@ -673,37 +674,32 @@ DumpReport(nsIGZFileWriter *aWriter, boo
   return NS_OK;
 }
 
 class DumpReporterCallback MOZ_FINAL : public nsIMemoryReporterCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
-  DumpReporterCallback(bool* aIsFirstPtr) : mIsFirstPtr(aIsFirstPtr) {}
+  DumpReporterCallback() : mIsFirst(true) {}
 
   NS_IMETHOD Callback(const nsACString &aProcess, const nsACString &aPath,
       int32_t aKind, int32_t aUnits, int64_t aAmount,
       const nsACString &aDescription,
       nsISupports *aData)
   {
     nsCOMPtr<nsIGZFileWriter> writer = do_QueryInterface(aData);
     NS_ENSURE_TRUE(writer, NS_ERROR_FAILURE);
 
-    // The |isFirst = false| assumes that at least one single reporter is
-    // present and so will have been processed in
-    // DumpProcessMemoryReportsToGZFileWriter() below.
-    bool isFirst = *mIsFirstPtr;
-    *mIsFirstPtr = false;
-    return DumpReport(writer, isFirst, aProcess, aPath, aKind, aUnits, aAmount,
-                      aDescription);
+    return DumpReport(writer, &mIsFirst, aProcess, aPath, aKind, aUnits,
+                      aAmount, aDescription);
   }
 
 private:
-  bool* mIsFirstPtr;
+  bool mIsFirst;
 };
 
 NS_IMPL_ISUPPORTS1(DumpReporterCallback, nsIMemoryReporterCallback)
 
 } // namespace mozilla
 
 static void
 MakeFilename(const char *aPrefix, const nsAString &aIdentifier,
@@ -812,21 +808,20 @@ DumpProcessMemoryReportsToGZFileWriter(n
     do_GetService("@mozilla.org/memory-reporter-manager;1");
   NS_ENSURE_STATE(mgr);
 
   DUMP(aWriter, mgr->GetHasMozMallocUsableSize() ? "true" : "false");
   DUMP(aWriter, ",\n");
   DUMP(aWriter, "  \"reports\": ");
 
   // Process reporters.
-  bool isFirst = true;
   bool more;
   nsCOMPtr<nsISimpleEnumerator> e;
   mgr->EnumerateReporters(getter_AddRefs(e));
-  nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback(&isFirst);
+  nsRefPtr<DumpReporterCallback> cb = new DumpReporterCallback();
   while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
     nsCOMPtr<nsIMemoryReporter> r;
     e->GetNext(getter_AddRefs(r));
     r->CollectReports(cb, aWriter);
   }
 
   DUMP(aWriter, "\n  ]\n}\n");