Bug 1298113 - Convert devtools xpcshell memory assertion into a mochitest posting data to perfherder. r=jryans
MozReview-Commit-ID: HORYWm03HNc
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -56,16 +56,17 @@ skip-if = e10s # Bug 1183605 - devtools/
[browser_markers-docloading-01.js]
[browser_markers-docloading-02.js]
[browser_markers-docloading-03.js]
[browser_markers-gc.js]
[browser_markers-minor-gc.js]
[browser_markers-parse-html.js]
[browser_markers-styles.js]
[browser_markers-timestamp.js]
+[browser_memory-footprint.js]
[browser_navigateEvents.js]
skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
[browser_perf-allocation-data.js]
skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
[browser_perf-profiler-01.js]
[browser_perf-profiler-02.js]
skip-if = true # Needs to be updated for async actor destruction
[browser_perf-profiler-03.js]
new file mode 100644
--- /dev/null
+++ b/devtools/server/tests/browser/browser_memory-footprint.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Probe memory usage of devtools debugger server
+ */
+
+const { DevToolsLoader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
+
+let gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(Ci.nsIMemoryReporterManager);
+
+SimpleTest.requestCompleteLog(); // so that "PERFHERDER_DATA" can be scraped from the log
+
+// Attempt to do the most complete garbage collection
+function* gc() {
+ Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
+ Cu.forceGC();
+ Cu.forceCC();
+ yield new Promise(done => {
+ Cu.schedulePreciseShrinkingGC(done);
+ });
+ info("gc-ed");
+}
+
+// Process all concurrent events
+function processPendingEvents() {
+ let start = new Date().getTime();
+ while(Services.tm.currentThread.hasPendingEvents()) {
+ Services.tm.currentThread.processNextEvent(true);
+ }
+ let duration = new Date().getTime() - start;
+ info("Processed events during " + duration + "ms");
+ return duration;
+}
+
+add_task(function* () {
+ // Force freeing memory until firefox is done doing things.
+ // processPendingEvents should return immediately once there is no other
+ // event being processed.
+ while(processPendingEvents() > 50) {
+ yield gc();
+ }
+
+ let refMemory = gMgr.residentUnique;
+ let subtests = [];
+
+ let loader = new DevToolsLoader();
+ let { DebuggerServer } = loader.require("devtools/server/main");
+ check_footprint("DevToolsServer module");
+
+ DebuggerServer.init();
+ DebuggerServer.addBrowserActors();
+ check_footprint("DebuggerServer.addBrowserActors()");
+
+ let client = new DebuggerClient(DebuggerServer.connectPipe());
+ yield client.connect();
+ check_footprint("DebuggerClient.connect()");
+
+ yield client.listTabs();
+ check_footprint("DebuggerClient.listTabs()");
+
+ logToPerfHerder();
+ ok(true, "Sent data to perfherder");
+ yield client.close();
+
+ function check_footprint(name) {
+ let footprint = (gMgr.residentUnique - refMemory) / 1024;
+ subtests.push({ name, value: footprint });
+ }
+
+ function logToPerfHerder() {
+ let footprint = (gMgr.residentUnique - refMemory) / 1024;
+ let PERFHERDER_DATA = {
+ framework: { name: "awsy" },
+ suites: [{
+ subtests,
+ name: "Devtools memory usage", value: footprint
+ }]
+ };
+ info("PERFHERDER_DATA: " + JSON.stringify(PERFHERDER_DATA));
+ }
+});
deleted file mode 100644
--- a/devtools/server/tests/unit/test_memory_footprint.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-var gClient;
-var gMgr;
-var gRefMemory;
-
-function run_test() {
- gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(Ci.nsIMemoryReporterManager);
- Cu.forceGC();
- gRefMemory = gMgr.residentUnique;
-
- add_test(init_server);
- add_test(add_browser_actors);
- add_test(connect_client);
- add_test(list_tabs);
- add_test(close_client);
- run_next_test();
-}
-
-function check_footprint(step, max) {
- var footprint = (gMgr.residentUnique - gRefMemory) / 1024;
- let msg = "Footprint after " + step + " is " + footprint + " kB (should be less than " + max + " kB).\n" +
- "!!! The devtools server's memory usage increased either significantly, or slowly over time.\n" +
- "!!! If your patch doesn't cause a big increase, feel free to raise the thresholds for this test as needed.";
- ok(footprint < max, msg);
- run_next_test();
-}
-
-function init_server() {
- DebuggerServer.init();
- check_footprint("DebuggerServer.init()", 150);
-}
-
-function add_browser_actors() {
- DebuggerServer.addBrowserActors();
- check_footprint("DebuggerServer.addBrowserActors()", 2600);
-}
-
-function connect_client() {
- gClient = new DebuggerClient(DebuggerServer.connectPipe());
- gClient.connect().then(function onConnect() {
- check_footprint("DebuggerClient.connect()", 3200);
- });
-}
-
-function list_tabs() {
- gClient.listTabs(function onListTabs(aResponse) {
- check_footprint("DebuggerClient.listTabs()", 3800);
- });
-}
-
-function close_client() {
- gClient.close().then(run_next_test);
-}
--- a/devtools/server/tests/unit/xpcshell.ini
+++ b/devtools/server/tests/unit/xpcshell.ini
@@ -252,20 +252,16 @@ reason = bug 937197
[test_client_request.js]
[test_monitor_actor.js]
[test_symbols-01.js]
[test_symbols-02.js]
[test_get-executable-lines.js]
[test_get-executable-lines-source-map.js]
[test_xpcshell_debugging.js]
support-files = xpcshell_debugging_script.js
-[test_memory_footprint.js]
-run-sequentially = measure memory, has to be run solo
-skip-if = os != 'linux' || debug || asan
-reason = bug 1014071
[test_setBreakpoint-on-column.js]
[test_setBreakpoint-on-column-in-gcd-script.js]
[test_setBreakpoint-on-column-with-no-offsets-at-end-of-line.js]
[test_setBreakpoint-on-line.js]
[test_setBreakpoint-on-line-in-gcd-script.js]
[test_setBreakpoint-on-line-with-multiple-offsets.js]
[test_setBreakpoint-on-line-with-multiple-statements.js]
[test_setBreakpoint-on-line-with-no-offsets.js]