From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../resources/profiling-script.js | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testing/web-platform/tests/js-self-profiling/resources/profiling-script.js (limited to 'testing/web-platform/tests/js-self-profiling/resources/profiling-script.js') 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); -- cgit v1.2.3