Bug 1000755 - [about:service] Refine the format of output reports. r=dhylands
authorAlphan Chen <alchen@mozilla.com>
Mon, 28 Apr 2014 14:20:41 +0800
changeset 181178 ba3c6ac9dfdab0eae6d84a8cfc8e7a56c0927609
parent 181177 5e58a8f23067b403f4a625561d9b9fa13082059b
child 181179 7620a58abe97f9246781802a13b990635d87660c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersdhylands
bugs1000755
milestone32.0a1
Bug 1000755 - [about:service] Refine the format of output reports. r=dhylands
xpcom/base/nsStatusReporterManager.cpp
--- a/xpcom/base/nsStatusReporterManager.cpp
+++ b/xpcom/base/nsStatusReporterManager.cpp
@@ -59,17 +59,17 @@ void doStatusReport(const nsCString& inp
 static bool gStatusReportProgress = 0;
 static int gNumReporters = 0;
 
 nsresult getStatus(nsACString& desc)
 {
   if(!gStatusReportProgress)
     desc.AssignLiteral("Init");
   else {
-    desc.AssignLiteral("Running:\nThere are ");
+    desc.AssignLiteral("Running: There are ");
     desc.AppendInt(gNumReporters);
     desc.AppendLiteral(" reporters");
   }
   return NS_OK;
 }
 
 NS_STATUS_REPORTER_IMPLEMENT(StatusReporter, "StatusReporter State", getStatus)
 
@@ -85,29 +85,32 @@ NS_STATUS_REPORTER_IMPLEMENT(StatusRepor
 static nsresult
 DumpReport(nsIFileOutputStream* aOStream, const nsCString& aProcess,
            const nsCString& aName, const nsCString& aDescription)
 {
   int pid;
   if (aProcess.IsEmpty()) {
     pid = getpid();
     nsPrintfCString pidStr("PID %u", pid);
-    DUMP(aOStream, "\n    {\"Process\": \"");
+    DUMP(aOStream, "\n  {\n  \"Process\": \"");
     DUMP(aOStream, pidStr.get());
   } else {
     pid = 0;
-    DUMP(aOStream, "\n    {\"Unknown Process\": \"");
+    DUMP(aOStream, "\n  {  \"Unknown Process\": \"");
   }
 
-  DUMP(aOStream, "\", \"Reporter name\": \"");
+  DUMP(aOStream, "\",\n  \"Reporter name\": \"");
   DUMP(aOStream, aName.get());
 
-  DUMP(aOStream, "\", \"Status Description\": \"");
-  DUMP(aOStream, aDescription.get());
-  DUMP(aOStream, "\"}");
+  DUMP(aOStream, "\",\n  \"Status Description\": [\"");
+  nsCString desc = aDescription;
+  desc.ReplaceSubstring("|", "\",\"");
+  DUMP(aOStream, desc.get());
+
+  DUMP(aOStream, "\"]\n  }");
 
   return NS_OK;
 }
 
 /**
  ** nsStatusReporterManager implementation
  **/
 
@@ -163,20 +166,21 @@ nsStatusReporterManager::DumpReports()
   nsCOMPtr<nsIFileOutputStream> ostream =
     do_CreateInstance("@mozilla.org/network/file-output-stream;1");
   rv = ostream->Init(tmpFile, -1, -1, 0);
   if (NS_WARN_IF(NS_FAILED(rv)))
     return rv;
 
   //Write the reports to the file
 
-  DUMP(ostream, "  [Sysdump Report Start]: ");
+  DUMP(ostream, "{\n\"subject\":\"about:service reports\",\n");
+  DUMP(ostream, "\"reporters\": [ ");
 
   nsCOMPtr<nsISimpleEnumerator> e;
-  bool more;
+  bool more, first = true;
   EnumerateReporters(getter_AddRefs(e));
   while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
     nsCOMPtr<nsISupports> supports;
     e->GetNext(getter_AddRefs(supports));
     nsCOMPtr<nsIStatusReporter> r = do_QueryInterface(supports);
 
     nsCString process;
     rv = r->GetProcess(process);
@@ -188,22 +192,27 @@ nsStatusReporterManager::DumpReports()
     if (NS_WARN_IF(NS_FAILED(rv)))
       return rv;
 
     nsCString description;
     rv = r->GetDescription(description);
     if (NS_WARN_IF(NS_FAILED(rv)))
       return rv;
 
+    if (first) {
+      first = false;
+    } else {
+      DUMP(ostream, ",");
+    }
+
     rv = DumpReport(ostream, process, name, description);
     if (NS_WARN_IF(NS_FAILED(rv)))
       return rv;
   }
-
-  DUMP(ostream, "\n  [Sysdump Report End] ");
+  DUMP(ostream, "\n]\n}\n");
 
   rv = ostream->Close();
   if (NS_WARN_IF(NS_FAILED(rv)))
     return rv;
 
   // Rename the status reports file
   nsCOMPtr<nsIFile> srFinalFile;
   rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(srFinalFile));