From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. 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