summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/js-self-profiling/resources/profiling-script.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/js-self-profiling/resources/profiling-script.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/js-self-profiling/resources/profiling-script.js')
-rw-r--r--testing/web-platform/tests/js-self-profiling/resources/profiling-script.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/testing/web-platform/tests/js-self-profiling/resources/profiling-script.js b/testing/web-platform/tests/js-self-profiling/resources/profiling-script.js
new file mode 100644
index 0000000000..9f09e05b34
--- /dev/null
+++ b/testing/web-platform/tests/js-self-profiling/resources/profiling-script.js
@@ -0,0 +1,26 @@
+(function(global) {
+ let counter = 0;
+
+ // Spins up a new profiler and performs some work in a new top-level task,
+ // calling some builtins. Returns a promise for the resulting trace.
+ const profileBuiltinsInNewTask = () => {
+ // Run profiling logic in a new task to eliminate the caller stack.
+ return new Promise(resolve => {
+ setTimeout(async () => {
+ const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });
+ for (const deadline = performance.now() + 500; performance.now() < deadline;) {
+ // Run a range of builtins to ensure they get included in the trace.
+ // Store this computation in a variable to prevent getting optimized out.
+ counter += Math.random();
+ counter += performance.now();
+ }
+ const trace = await profiler.stop();
+ resolve(trace);
+ });
+ });
+ }
+
+ global.ProfilingScript = {
+ profileBuiltinsInNewTask,
+ }
+})(window);