summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_perf-samples-02.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/server/tests/browser/browser_perf-samples-02.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/browser/browser_perf-samples-02.js')
-rw-r--r--devtools/server/tests/browser/browser_perf-samples-02.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/devtools/server/tests/browser/browser_perf-samples-02.js b/devtools/server/tests/browser/browser_perf-samples-02.js
new file mode 100644
index 0000000000..a48ccdcece
--- /dev/null
+++ b/devtools/server/tests/browser/browser_perf-samples-02.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests if the retrieved profiler data samples always have a (root) node.
+ * If this ever changes, the |ThreadNode.prototype.insert| function in
+ * devtools/client/performance/modules/logic/tree-model.js will have to be changed.
+ */
+
+"use strict";
+
+// Time in ms
+const WAIT_TIME = 1000;
+
+add_task(async function() {
+ const target = await addTabTarget(MAIN_DOMAIN + "doc_perf.html");
+
+ const front = await target.getFront("performance");
+
+ const rec = await front.startRecording();
+ // allow the profiler module to sample some cpu activity
+ busyWait(WAIT_TIME);
+
+ await front.stopRecording(rec);
+ const profile = rec.getProfile();
+ let sampleCount = 0;
+
+ for (const thread of profile.threads) {
+ info("Checking thread: " + thread.name);
+
+ for (const sample of thread.samples.data) {
+ sampleCount++;
+
+ const stack = getInflatedStackLocations(thread, sample);
+ if (stack[0] != "(root)") {
+ ok(
+ false,
+ "The sample " + stack.toSource() + " doesn't have a root node."
+ );
+ }
+ }
+ }
+
+ ok(
+ sampleCount > 0,
+ "At least some samples have been iterated over, checking for root nodes."
+ );
+
+ await target.getFront("performance");
+ gBrowser.removeCurrentTab();
+});
+
+/**
+ * Inflate a particular sample's stack and return an array of strings.
+ */
+function getInflatedStackLocations(thread, sample) {
+ const stackTable = thread.stackTable;
+ const frameTable = thread.frameTable;
+ const stringTable = thread.stringTable;
+ const SAMPLE_STACK_SLOT = thread.samples.schema.stack;
+ const STACK_PREFIX_SLOT = stackTable.schema.prefix;
+ const STACK_FRAME_SLOT = stackTable.schema.frame;
+ const FRAME_LOCATION_SLOT = frameTable.schema.location;
+
+ // Build the stack from the raw data and accumulate the locations in
+ // an array.
+ let stackIndex = sample[SAMPLE_STACK_SLOT];
+ const locations = [];
+ while (stackIndex !== null) {
+ const stackEntry = stackTable.data[stackIndex];
+ const frame = frameTable.data[stackEntry[STACK_FRAME_SLOT]];
+ locations.push(stringTable[frame[FRAME_LOCATION_SLOT]]);
+ stackIndex = stackEntry[STACK_PREFIX_SLOT];
+ }
+
+ // The profiler tree is inverted, so reverse the array.
+ return locations.reverse();
+}