Bug 939137 - part 2 - display memory statistics following each mochitest; r=ted
authorNathan Froyd <froydnj@mozilla.com>
Fri, 15 Nov 2013 12:01:06 -0500
changeset 154913 86cf2e690f904815b9e842d4ebdc8b2f766934ea
parent 154912 b3995a14d96884e29e63d7bfee70b0c83e3eedfb
child 154914 a7a6ff24a7b8cbb21e6207220d5f0bf0ddc6c46d
push id25656
push userryanvm@gmail.com
push dateSat, 16 Nov 2013 02:44:05 +0000
treeherdermozilla-central@a475f94bb1b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs939137
milestone28.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 939137 - part 2 - display memory statistics following each mochitest; r=ted Landing this on a CLOSED TREE
testing/mochitest/tests/SimpleTest/TestRunner.js
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -388,32 +388,70 @@ TestRunner.runNextTest = function() {
     }
 };
 
 TestRunner.expectChildProcessCrash = function() {
     TestRunner._expectingProcessCrash = true;
 };
 
 /**
+ * Statistics that we want to retrieve and display after every test is
+ * done.  The keys of this table are intended to be identical to the
+ * relevant attributes of nsIMemoryReporterManager.  However, since
+ * nsIMemoryReporterManager doesn't necessarily support all these
+ * statistics in all build configurations, we also use this table to
+ * tell us whether statistics are supported or not.
+ */
+var MEM_STAT_UNKNOWN = 0;
+var MEM_STAT_UNSUPPORTED = 1;
+var MEM_STAT_SUPPORTED = 2;
+TestRunner._hasMemoryStatistics = {}
+TestRunner._hasMemoryStatistics.vsize = MEM_STAT_UNKNOWN;
+TestRunner._hasMemoryStatistics.heapAllocated = MEM_STAT_UNKNOWN;
+TestRunner._hasMemoryStatistics.largestContiguousVMBlock = MEM_STAT_UNKNOWN;
+
+/**
  * This stub is called by SimpleTest when a test is finished.
 **/
 TestRunner.testFinished = function(tests) {
     // Prevent a test from calling finish() multiple times before we
     // have a chance to unload it.
     if (TestRunner._currentTest == TestRunner._lastTestFinished &&
         !TestRunner._loopIsRestarting) {
         TestRunner.error("TEST-UNEXPECTED-FAIL | " +
                          TestRunner.currentTestURL +
                          " | called finish() multiple times");
         TestRunner.updateUI([{ result: false }]);
         return;
     }
     TestRunner._lastTestFinished = TestRunner._currentTest;
     TestRunner._loopIsRestarting = false;
 
+    var mrm = SpecialPowers.Cc["@mozilla.org/memory-reporter-manager;1"]
+                           .getService(SpecialPowers.Ci.nsIMemoryReporterManager);
+    for (stat in TestRunner._hasMemoryStatistics) {
+        var supported = TestRunner._hasMemoryStatistics[stat];
+        var firstAccess = false;
+        if (supported == MEM_STAT_UNKNOWN) {
+            firstAccess = true;
+            try {
+                var value = mrm[stat];
+                supported = MEM_STAT_SUPPORTED;
+            } catch (e) {
+                supported = MEM_STAT_UNSUPPORTED;
+            }
+            TestRunner._hasMemoryStatistics[stat] = supported;
+        }
+        if (supported == MEM_STAT_SUPPORTED) {
+            TestRunner.log("TEST-INFO | MEMORY STAT " + stat + " after test: " + mrm[stat]);
+        } else if (firstAccess) {
+            TestRunner.log("TEST-INFO | MEMORY STAT " + stat + " not supported in this build configuration.");
+        }
+    }
+
     function cleanUpCrashDumpFiles() {
         if (!SpecialPowers.removeExpectedCrashDumpFiles(TestRunner._expectingProcessCrash)) {
             TestRunner.error("TEST-UNEXPECTED-FAIL | " +
                              TestRunner.currentTestURL +
                              " | This test did not leave any crash dumps behind, but we were expecting some!");
             tests.push({ result: false });
         }
         var unexpectedCrashDumpFiles =