Bug 1141614 - Part 5: Add a test for cycle collection markers; r=jsantell
authorNick Fitzgerald <fitzgen@gmail.com>
Wed, 10 Jun 2015 14:05:53 -0700
changeset 248170 56ede9a5462d857baf323c246113ba738f26bee4
parent 248169 0f7be7f07b63c245e3475fbbffd778a060fb35e4
child 248171 49480f1c4071c59c8ae1afced4d38805f1a60479
push id28893
push userkwierso@gmail.com
push dateFri, 12 Jun 2015 00:02:58 +0000
treeherderautoland@8cf9d3e497f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs1141614
milestone41.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 1141614 - Part 5: Add a test for cycle collection markers; r=jsantell
browser/devtools/performance/test/browser.ini
browser/devtools/performance/test/browser_markers-cycle-collection.js
browser/devtools/performance/test/doc_force_cc.html
docshell/test/browser/frame-head.js
--- a/browser/devtools/performance/test/browser.ini
+++ b/browser/devtools/performance/test/browser.ini
@@ -1,23 +1,25 @@
 [DEFAULT]
 tags = devtools
 subsuite = devtools
 support-files =
+  doc_force_cc.html
   doc_force_gc.html
   doc_innerHTML.html
   doc_markers.html
   doc_simple-test.html
   head.js
 
 # Commented out tests are profiler tests
 # that need to be moved over to performance tool
 
 [browser_aaa-run-first-leaktest.js]
 [browser_marker-utils.js]
+[browser_markers-cycle-collection.js]
 [browser_markers-gc.js]
 [browser_markers-parse-html.js]
 [browser_markers-styles.js]
 [browser_markers-timestamp.js]
 [browser_perf-allocations-to-samples.js]
 [browser_perf-categories-js-calltree.js]
 [browser_perf-compatibility-01.js]
 [browser_perf-compatibility-02.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/performance/test/browser_markers-cycle-collection.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that we get "nsCycleCollector::Collect" and
+ * "nsCycleCollector::ForgetSkippable" markers when we force cycle collection.
+ */
+
+const TEST_URL = EXAMPLE_URL + "doc_force_cc.html"
+
+function waitForMarkerType(front, type) {
+  info("Waiting for marker of type = " + type);
+  const { promise, resolve } = Promise.defer();
+
+  const handler = (_, name, markers) => {
+    if (name !== "markers") {
+      return;
+    }
+
+    info("Got markers: " + JSON.stringify(markers, null, 2));
+
+    if (markers.some(m => m.name === type)) {
+      ok(true, "Found marker of type = " + type);
+      front.off("timeline-data", handler);
+      resolve();
+    }
+  };
+  front.on("timeline-data", handler);
+
+  return promise;
+}
+
+function* spawnTest () {
+  // This test runs very slowly on linux32 debug EC2 instances.
+  requestLongerTimeout(2);
+
+  let { target, front } = yield initBackend(TEST_URL);
+
+  yield front.startRecording({ withMarkers: true, withTicks: true });
+
+  yield Promise.all([
+    waitForMarkerType(front, "nsCycleCollector::Collect"),
+    waitForMarkerType(front, "nsCycleCollector::ForgetSkippable")
+  ]);
+  ok(true, "Got expected cycle collection events");
+
+  yield front.stopRecording();
+  yield removeTab(target.tab);
+  finish();
+}
new file mode 100644
--- /dev/null
+++ b/browser/devtools/performance/test/doc_force_cc.html
@@ -0,0 +1,29 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <title>Performance tool + cycle collection test page</title>
+  </head>
+
+  <body>
+    <script type="text/javascript">
+    window.test = function () {
+      document.body.expando1 = { cycle: document.body };
+      SpecialPowers.Cu.forceCC();
+
+      document.body.expando2 = { cycle: document.body };
+      SpecialPowers.Cu.forceCC();
+
+      document.body.expando3 = { cycle: document.body };
+      SpecialPowers.Cu.forceCC();
+
+      setTimeout(window.test, 100);
+    };
+    test();
+    </script>
+  </body>
+
+</html>
--- a/docshell/test/browser/frame-head.js
+++ b/docshell/test/browser/frame-head.js
@@ -66,16 +66,20 @@ this.timelineContentTest = function(test
       docShell.popProfileTimelineMarkers();
 
       info("Running the test setup function");
       let onMarkers = timelineWaitForMarkers(docShell, searchFor);
       setup(docShell);
       info("Waiting for new markers on the docShell");
       let markers = yield onMarkers;
 
+      // Cycle collection markers are non-deterministic, and none of these tests
+      // expect them to show up.
+      markers = markers.filter(m => m.name.indexOf("nsCycleCollector") === -1);
+
       info("Running the test check function");
       check(markers);
     }
 
     info("Stop recording");
     docShell.recordProfileTimelineMarkers = false;
     finish();
   });