Bug 799476 - Remove MemoryObserver dumping code in favour of using core gecko code. r=mfinkle
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 13 Oct 2012 08:54:50 -0400
changeset 114781 7e369eed5f9f26e3555fdc941a5052143e3b6a4d
parent 114780 7f47eacb16e385d1516171b55c67bd5a8b150a21
child 114782 ab275d939bf2e86e73a76ac30dad5daae85c7e0d
push idunknown
push userunknown
push dateunknown
reviewersmfinkle
bugs799476
milestone19.0a1
Bug 799476 - Remove MemoryObserver dumping code in favour of using core gecko code. r=mfinkle
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -7408,89 +7408,18 @@ var MemoryObserver = {
   },
 
   gc: function() {
     window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
     Cu.forceGC();
   },
 
   dumpMemoryStats: function(aLabel) {
-    // TODO once bug 788021 has landed, replace this code and just invoke that instead
-    // currently this code is hijacked from areweslimyet.com, original code can be found at:
-    // https://github.com/Nephyrin/MozAreWeSlimYet/blob/master/mozmill_endurance_test/performance.js
     let memMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(Ci.nsIMemoryReporterManager);
-
-    let timestamp = new Date();
-    let memory = {};
-
-    // These *should* be identical to the explicit/resident root node
-    // sum, AND the explicit/resident node explicit value (on newer builds),
-    // but we record all three so we can make sure the data is consistent
-    memory['manager_explicit'] = memMgr.explicit;
-    memory['manager_resident'] = memMgr.resident;
-
-    let knownHeap = 0;
-
-    function addReport(path, amount, kind, units) {
-      if (units !== undefined && units != Ci.nsIMemoryReporter.UNITS_BYTES)
-        // Unhandled. (old builds don't specify units, but use only bytes)
-        return;
-
-      if (memory[path])
-        memory[path] += amount;
-      else
-        memory[path] = amount;
-      if (kind !== undefined && kind == Ci.nsIMemoryReporter.KIND_HEAP
-          && path.indexOf('explicit/') == 0)
-        knownHeap += amount;
-    }
-
-    // Normal reporters
-    let reporters = memMgr.enumerateReporters();
-    while (reporters.hasMoreElements()) {
-      let r = reporters.getNext();
-      r instanceof Ci.nsIMemoryReporter;
-      if (r.path.length) {
-        addReport(r.path, r.amount, r.kind, r.units);
-      }
-    }
-
-    // Multireporters
-    if (memMgr.enumerateMultiReporters) {
-      let multireporters = memMgr.enumerateMultiReporters();
-
-      while (multireporters.hasMoreElements()) {
-        let mr = multireporters.getNext();
-        mr instanceof Ci.nsIMemoryMultiReporter;
-        mr.collectReports(function (proc, path, kind, units, amount, description, closure) {
-          addReport(path, amount, kind, units);
-        }, null);
-      }
-    }
-
-    let heapAllocated = memory['heap-allocated'];
-    // Called heap-used in older builds
-    if (!heapAllocated) heapAllocated = memory['heap-used'];
-    // This is how about:memory calculates derived value heap-unclassified, which
-    // is necessary to get a proper explicit value.
-    if (knownHeap && heapAllocated)
-      memory['explicit/heap-unclassified'] = memory['heap-allocated'] - knownHeap;
-
-    // If the build doesn't have a resident/explicit reporter, but does have
-    // the memMgr.explicit/resident field, use that
-    if (!memory['resident'])
-      memory['resident'] = memory['manager_resident']
-    if (!memory['explicit'])
-      memory['explicit'] = memory['manager_explicit']
-
-    let label = "[AboutMemoryDump|" + aLabel + "] ";
-    dump(label + timestamp);
-    for (let type in memory) {
-      dump(label + type + " = " + memory[type]);
-    }
+    memMgr.dumpMemoryReportsToFile(aLabel, false, true);
   },
 };
 
 var Distribution = {
   _file: null,
 
   init: function dc_init() {
     Services.obs.addObserver(this, "Distribution:Set", false);