Bug 1298113 - Convert devtools xpcshell memory assertion into a mochitest posting data to perfherder. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 01 Sep 2016 02:14:12 -0700
changeset 408647 167d7435f1aab8bca719805c639a29e65932a890
parent 408554 cd644f22ff59bd09800b6607072405fbe589a332
child 530157 36b721b6eb1166bc479f0d40e64b4ad380103883
push id28264
push userbmo:poirot.alex@gmail.com
push dateThu, 01 Sep 2016 13:03:14 +0000
reviewersjryans
bugs1298113
milestone51.0a1
Bug 1298113 - Convert devtools xpcshell memory assertion into a mochitest posting data to perfherder. r=jryans MozReview-Commit-ID: HORYWm03HNc
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_memory-footprint.js
devtools/server/tests/unit/test_memory_footprint.js
devtools/server/tests/unit/xpcshell.ini
--- 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,78 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Probe memory usage of devtools debugger server
+ */
+
+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 = [];
+
+  DebuggerServer.init();
+  check_footprint("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]