forked from mirrors/gecko-dev
Automatic update from web-platform-tests [profiler] Attribute builtins to the nearest parent script To ensure that builtins executed by cross-origin no-CORS script do not get included in traces, attribute them to the next valid caller script. This captures the notion of 'invoker' loosely defined in the spec. Bug: 956688 Change-Id: I7ff33be35b0162c7df25871ebc15323f2c2499ae Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3073352 Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Commit-Queue: Andrew Comminos <acomminos@fb.com> Cr-Commit-Position: refs/heads/master@{#909056} -- wpt-commits: f8cd2a47833e58c9f0d7ca17db8494a38669d046 wpt-pr: 29908
26 lines
959 B
JavaScript
26 lines
959 B
JavaScript
(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);
|