Bug 1567390 - Add a merged stack test for the profiler; r=canaltinova
authorGreg Tatum <gtatum@mozilla.com>
Fri, 02 Aug 2019 14:18:18 +0000
changeset 485964 9655b89e5f5add7d096b1f28b088c319d31a14c3
parent 485963 9527800a8dcd455510083b6f788b0416a3b8f8b6
child 485965 527dc31598d28bd72bd77a5205a9246dd54c6d94
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 merged stack test for the profiler; r=canaltinova Depends on D40324 Differential Revision: https://phabricator.services.mozilla.com/D40422
tools/profiler/tests/xpcshell/test_merged_stacks.js
tools/profiler/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/xpcshell/test_merged_stacks.js
@@ -0,0 +1,75 @@
+/* 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 we correctly merge the three stack types, JS, native, and frame labels.
+ */
+add_task(async () => {
+  if (!AppConstants.MOZ_GECKO_PROFILER) {
+    return;
+  }
+  const entries = 10000;
+  const interval = 1;
+  const threads = [];
+  const features = ["js", "stackwalk"];
+
+  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]
+  );
+
+  const nativeStack = /^0x[0-9a-f]+$/;
+
+  expectStackToContain(
+    inflatedStackFrames,
+    [
+      "(root)",
+      nativeStack,
+      nativeStack,
+      // There are more native stacks and frame labels here, but we know some execute
+      // and then the "js::RunScript" frame label runs.
+      "js::RunScript",
+      nativeStack,
+      nativeStack,
+      // The following regexes match a string similar to:
+      //
+      // "functionA (/gecko/obj/_tests/xpcshell/tools/profiler/tests/xpcshell/test_merged_stacks.js:47:0)"
+      //
+      //          this matches the script location
+      //          |                          match the line number
+      //          |                          |   match the column number
+      //          v                          v   v
+      /^functionA \(.+test_merged_stacks\.js:\d+:\d+\)$/,
+      /^functionB \(.+test_merged_stacks\.js:\d+:\d+\)$/,
+      /^functionC \(.+test_merged_stacks\.js:\d+:\d+\)$/,
+      // After the JS frames, then there are a bunch of arbitrary native stack frames
+      // that run.
+      nativeStack,
+      nativeStack,
+    ],
+    "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
@@ -15,8 +15,9 @@ skip-if = (os == "win" && processor == "
 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]
+[test_merged_stacks.js]