Bug 1567390 - Add a JS stack collection test; r=canaltinova
authorGreg Tatum <gtatum@mozilla.com>
Fri, 02 Aug 2019 14:15:15 +0000
changeset 485963 9527800a8dcd455510083b6f788b0416a3b8f8b6
parent 485962 6ab1565e59002751c4bd5b64be99a14f69ce8eee
child 485964 9655b89e5f5add7d096b1f28b088c319d31a14c3
push id91562
push usergtatum@mozilla.com
push dateFri, 02 Aug 2019 15:11:46 +0000
treeherderautoland@9655b89e5f5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscanaltinova
bugs1567390
milestone70.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 1567390 - Add a JS stack collection test; r=canaltinova Differential Revision: https://phabricator.services.mozilla.com/D40324
tools/profiler/tests/xpcshell/test_feature_js.js
tools/profiler/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/xpcshell/test_feature_js.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Test that JS capturing works as expected.
+ */
+add_task(async () => {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  const entries = 10000;
+  const interval = 1;
+  const threads = [];
+  const features = ["js"];
+
+  Services.profiler.StartProfiler(entries, interval, features, threads);
+
+  // Call the following to get a nice stack in the profiler:
+  // functionA -> functionB -> functionC -> doAtLeastOnePeriodicSample
+  const sampleIndex = await functionA();
+
+  const profile = await Services.profiler.getProfileDataAsync();
+  const [thread] = profile.threads;
+  const { samples } = thread;
+
+  const inflatedStackFrames = getInflatedStackLocations(
+    thread,
+    samples.data[sampleIndex]
+  );
+
+  expectStackToContain(
+    inflatedStackFrames,
+    [
+      "(root)",
+      "js::RunScript",
+      // The following regexes match a string similar to:
+      //
+      // "functionA (/gecko/obj/_tests/xpcshell/tools/profiler/tests/xpcshell/test_feature_js.js:47:0)"
+      //
+      //          this matches the script location
+      //          |                       match the line number
+      //          |                       |   match the column number
+      //          v                       v   v
+      /^functionA \(.+test_feature_js\.js:\d+:\d+\)$/,
+      /^functionB \(.+test_feature_js\.js:\d+:\d+\)$/,
+      /^functionC \(.+test_feature_js\.js:\d+:\d+\)$/,
+    ],
+    "The stack contains a few frame labels, as well as the JS functions that we called."
+  );
+});
+
+function functionA() {
+  return functionB();
+}
+
+function functionB() {
+  return functionC();
+}
+
+async function functionC() {
+  return doAtLeastOnePeriodicSample();
+}
--- a/tools/profiler/tests/xpcshell/xpcshell.ini
+++ b/tools/profiler/tests/xpcshell/xpcshell.ini
@@ -14,8 +14,9 @@ skip-if = (os == "win" && processor == "
 [test_enterjit_osr_disabling.js]
 skip-if = !debug
 [test_enterjit_osr_enabling.js]
 skip-if = !debug
 [test_asm.js]
 [test_feature_mainthreadio.js]
 skip-if = release_or_beta || (os == "win" && processor == "aarch64") # The IOInterposer is in an ifdef, aarch64 due to 1536657
 [test_feature_stackwalking.js]
+[test_feature_js.js]