From 05473f821b6368097f1ff5109276de047bb83398 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 15 Nov 2013 12:01:06 -0500 Subject: [PATCH] Bug 939137 - part 2 - display memory statistics following each mochitest; r=ted Landing this on a CLOSED TREE --- .../mochitest/tests/SimpleTest/TestRunner.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/testing/mochitest/tests/SimpleTest/TestRunner.js b/testing/mochitest/tests/SimpleTest/TestRunner.js index 17b63684b0e1..cb2e22d754d0 100644 --- a/testing/mochitest/tests/SimpleTest/TestRunner.js +++ b/testing/mochitest/tests/SimpleTest/TestRunner.js @@ -392,6 +392,22 @@ 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. **/ @@ -409,6 +425,28 @@ TestRunner.testFinished = function(tests) { 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 | " +