# HG changeset patch # User Joel Maher # Date 1320853263 18000 # Node ID beca399c3a16ef1831f7f887c608a5ef2224b564 # Parent eaef28f55f92d25c470fef8bb3747a006b0c671d Bug 685632 - Please collect RSS (memory) data during Talos testing on Android. r=jlebar,njn diff -r eaef28f55f92 -r beca399c3a16 chrome/memory.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/memory.js Wed Nov 09 10:41:03 2011 -0500 @@ -0,0 +1,95 @@ + +var gChildProcess = true; +var gMemCallback = null; + + +/* + * Initialize memory collector. Determine if we have a child process. + */ +function initializeMemoryCollector(callback, args) { + gMemCallback = function() { return callback(args); }; + + var os = Components.classes["@mozilla.org/observer-service;1"]. + getService(Components.interfaces.nsIObserverService); + + os.addObserver(function () { + var os = Components.classes["@mozilla.org/observer-service;1"]. + getService(Components.interfaces.nsIObserverService); + + memTimer.cancel(); + memTimer = null; + + os.removeObserver(arguments.callee, "child-memory-reporter-update", false); + os.addObserver(collectAndReport, "child-memory-reporter-update", false); + gMemCallback(); + }, "child-memory-reporter-update", false); + + /* + * Assume we have a child process, but if timer fires before we call the observer + * we will assume there is no child process. + */ + var event = { + notify: function(timer) { + memTimer = null; + gChildProcess = false; + gMemCallback(); + } + } + + memTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); + memTimer.initWithCallback(event, 10000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); + + os.notifyObservers(null, "child-memory-reporter-request", null); +} + +/* + * Collect memory from all processes and callback when done collecting. + */ +function collectMemory(callback, args) { + gMemCallback = function() { return callback(args); }; + + if (gChildProcess) { + var os = Components.classes["@mozilla.org/observer-service;1"]. + getService(Components.interfaces.nsIObserverService); + + os.notifyObservers(null, "child-memory-reporter-request", null); + } else { + collectAndReport(null, null, null); + } +} + +function collectAndReport(aSubject, aTopic, aData) { + dumpLine(collectRSS()); + gMemCallback(); +} + +function collectRSS() { + var mgr = Components.classes["@mozilla.org/memory-reporter-manager;1"]. + getService(Components.interfaces.nsIMemoryReporterManager); + var e = mgr.enumerateReporters(); + text = ""; + while (e.hasMoreElements()) { + var reporter = e.getNext().QueryInterface(Components.interfaces.nsIMemoryReporter); + if (reporter.path == 'resident') { + procName = reporter.process; + if (procName == '') + procName = "Main"; + + //For content process it is in the format "Content ()", we just want Content + procName = procName.split(' ')[0]; + text += "RSS: " + procName + ": " + reporter.amount + "\n"; + } + } + return text; +} + +/* + * Cleanup and stop memory collector. + */ +function stopMemCollector() { + if (gChildProcess) { + var os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + os.removeObserver(collectAndReport, "child-memory-reporter-update"); + } +} diff -r eaef28f55f92 -r beca399c3a16 chrome/pageloader.js --- a/chrome/pageloader.js Mon Oct 10 14:41:18 2011 -0700 +++ b/chrome/pageloader.js Wed Nov 09 10:41:03 2011 -0500 @@ -66,6 +66,7 @@ var timeoutEvent = -1; var running = false; var forceCC = true; +var reportRSS = false; var useMozAfterPaint = false; var gPaintWindow = window; @@ -109,6 +110,7 @@ if (args.timeout) timeout = parseInt(args.timeout); if (args.delay) delay = parseInt(args.delay); if (args.mozafterpaint) useMozAfterPaint = true; + if (args.rss) reportRSS = true; forceCC = !args.noForceCC; doRenderTest = args.doRender; @@ -210,8 +212,11 @@ "addEventListener('load', _contentLoadHandler, true); "; content.messageManager.loadFrameScript(contentScript, false); } - - setTimeout(plLoadPage, 100); + if (reportRSS) { + initializeMemoryCollector(plLoadPage, 100); + } else { + setTimeout(plLoadPage, 100); + } }, 500); }; @@ -222,7 +227,11 @@ content = document.getElementById('contentPageloader'); - setTimeout(plLoadPage, delay); + if (reportRSS) { + initializeMemoryCollector(plLoadPage, delay); + } else { + setTimeout(plLoadPage, delay); + } } } catch(e) { dumpLine(e); @@ -290,7 +299,15 @@ if (timeout > 0) { timeoutEvent = setTimeout('loadFail()', timeout); - } + } + if (reportRSS) { + collectMemory(startAndLoadURI, pageName); + } else { + startAndLoadURI(pageName); + } +} + +function startAndLoadURI(pageName) { start_time = Date.now(); content.loadURI(pageName); } @@ -548,6 +565,14 @@ } function plStop(force) { + if (reportRSS) { + collectMemory(plStopAll, force); + } else { + plStopAll(force); + } +} + +function plStopAll(force) { try { if (force == false) { pageIndex = 0; @@ -573,6 +598,10 @@ dumpLine(e); } + if (reportRSS) { + stopMemCollector(); + } + if (content) { content.removeEventListener('load', plLoadHandlerCapturing, true); content.removeEventListener('load', plLoadHandler, true); diff -r eaef28f55f92 -r beca399c3a16 chrome/pageloader.xul --- a/chrome/pageloader.xul Mon Oct 10 14:41:18 2011 -0700 +++ b/chrome/pageloader.xul Wed Nov 09 10:41:03 2011 -0500 @@ -50,6 +50,7 @@ + diff -r eaef28f55f92 -r beca399c3a16 components/tp-cmdline.js --- a/components/tp-cmdline.js Mon Oct 10 14:41:18 2011 -0700 +++ b/components/tp-cmdline.js Wed Nov 09 10:41:03 2011 -0500 @@ -94,6 +94,7 @@ args.delay = cmdLine.handleFlagWithParam("tpdelay", false); args.noForceCC = cmdLine.handleFlag("tpnoforcecc", false); args.mozafterpaint = cmdLine.handleFlag("tpmozafterpaint", false); + args.rss = cmdLine.handleFlag("rss", false); } catch (e) { return; @@ -125,7 +126,8 @@ " -tptimeout Max amount of time given for a page to load, quit if exceeded\n" + " -tpdelay Amount of time to wait between each pageload\n" + " -tpnoforcecc Don't force cycle collection between each pageload\n" + - " -tpmozafterpaint Measure Time after recieving MozAfterPaint event instead of load event\n" + " -tpmozafterpaint Measure Time after recieving MozAfterPaint event instead of load event\n" + + " -rss Dump RSS after each page is loaded\n" };