Bug 1013652 - Add a "DMD" button to about:memory when DMD is enabled. r=mccr8.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 20 May 2014 19:29:37 -0700
changeset 184052 cf53e366410feb1c5baa58182c62cb82a3aa6592
parent 184051 656d74108b62afce59b84d674805396115352502
child 184053 9f960ed46a1d4d9496a2a326f5831933aa6f1b1c
push id26810
push usercbook@mozilla.com
push dateWed, 21 May 2014 11:46:36 +0000
treeherdermozilla-central@50fb8c4db2fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1013652
milestone32.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 1013652 - Add a "DMD" button to about:memory when DMD is enabled. r=mccr8.
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -43,20 +43,22 @@ XPCOMUtils.defineLazyGetter(this, "nsFil
                                      "nsIFile", "initWithPath"));
 XPCOMUtils.defineLazyGetter(this, "nsGzipConverter",
                             () => CC("@mozilla.org/streamconv;1?from=gzip&to=uncompressed",
                                      "nsIStreamConverter"));
 
 let gMgr = Cc["@mozilla.org/memory-reporter-manager;1"]
              .getService(Ci.nsIMemoryReporterManager);
 
-let gUnnamedProcessStr = "Main Process";
+const gUnnamedProcessStr = "Main Process";
 
 let gIsDiff = false;
 
+const DMDFile = "out.dmd";
+
 //---------------------------------------------------------------------------
 
 // Forward slashes in URLs in paths are represented with backslashes to avoid
 // being mistaken for path separators.  Paths/names where this hasn't been
 // undone are prefixed with "unsafe"; the rest are prefixed with "safe".
 function flipBackslashes(aUnsafeStr)
 {
   // Save memory by only doing the replacement if it's necessary.
@@ -287,16 +289,20 @@ function onLoad()
 
   const GCAndCCLogDesc = "Save garbage collection log and concise cycle " +
                          "collection log.\n" +
                          "WARNING: These logs may be large (>1GB).";
   const GCAndCCAllLogDesc = "Save garbage collection log and verbose cycle " +
                             "collection log.\n" +
                             "WARNING: These logs may be large (>1GB).";
 
+  const DMDEnabledDesc = "Run DMD analysis and save it to '" + DMDFile + "'.\n";
+  const DMDDisabledDesc = "DMD is not enabled. Please re-run with $DMD set " +
+                          "appropriately\n";
+
   let ops = appendElement(header, "div", "");
 
   let row1 = appendElement(ops, "div", "opsRow");
 
   let labelDiv =
    appendElementWithText(row1, "div", "opsRowLabel", "Show memory reports");
   let label = appendElementWithText(labelDiv, "label", "");
   gVerbose = appendElement(label, "input", "");
@@ -330,16 +336,34 @@ function onLoad()
   let row4 = appendElement(ops, "div", "opsRow");
 
   appendElementWithText(row4, "div", "opsRowLabel", "Save GC & CC logs");
   appendButton(row4, GCAndCCLogDesc,
                saveGCLogAndConciseCCLog, "Save concise", 'saveLogsConcise');
   appendButton(row4, GCAndCCAllLogDesc,
                saveGCLogAndVerboseCCLog, "Save verbose", 'saveLogsVerbose');
 
+  // This only succeeds in --enable-dmd builds.
+  if (typeof DMDReportAndDump == 'function') {
+    let env = Components.classes["@mozilla.org/process/environment;1"]
+                        .getService(Components.interfaces.nsIEnvironment);
+
+    // Gray the button out if DMD isn't enabled at start-up.
+    let dmd = env.get('DMD');
+    let disabled = dmd === '' || dmd === '0';
+
+    let row5 = appendElement(ops, "div", "opsRow");
+
+    appendElementWithText(row5, "div", "opsRowLabel", "Save DMD output");
+    let dmdButton =
+      appendButton(row5, disabled ? DMDDisabledDesc : DMDEnabledDesc, doDMD,
+                   "Save", "dmdButton");
+    dmdButton.disabled = disabled;
+  }
+
   // Generate the main div, where content ("section" divs) will go.  It's
   // hidden at first.
 
   gMain = appendElement(document.body, 'div', '');
   gMain.id = 'mainDiv';
 
   // Generate the footer.  It's hidden at first.
 
@@ -408,16 +432,23 @@ function saveGCLogAndConciseCCLog()
   dumpGCLogAndCCLog(false);
 }
 
 function saveGCLogAndVerboseCCLog()
 {
   dumpGCLogAndCCLog(true);
 }
 
+function doDMD()
+{
+  updateMainAndFooter('Saving DMD output...', HIDE_FOOTER);
+  DMDReportAndDump('out.dmd');
+  updateMainAndFooter('Saved DMD output to ' + DMDFile, HIDE_FOOTER);
+}
+
 function dumpGCLogAndCCLog(aVerbose)
 {
   let dumper = Cc["@mozilla.org/memory-info-dumper;1"]
                 .getService(Ci.nsIMemoryInfoDumper);
 
   let inProgress = updateMainAndFooter("Saving logs...", HIDE_FOOTER);
   let section = appendElement(gMain, 'div', "section");