Source code
Revision control
Copy as Markdown
Other Tools
<script>
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
/* global Quitter */
var defaultTimeout = 2 * 1000;
var extendedTimeout = 2 * 60 * 1000;
var superExtendedTimeout = 5 * 60 * 1000;
var hasExtendedCorpus =
new URLSearchParams(location.search).get("extendedCorpus") == "true";
// How long to keep an item open after it signals that it is done, so that
// trailing work such as painting still gets profiled.
var loadGracePeriod = 500;
var reportGracePeriod = 250;
var benchmarkGracePeriod = 2 * 1000;
function waitTimeout(time, win = window) {
return new Promise(resolve => {
win.setTimeout(() => {
resolve();
}, time);
});
}
// This page is in a background tab while items run, so its own timers are
// clamped. Prefer the item's window for short waits when it is same-origin.
function timerWindow(subWindow) {
try {
if (typeof subWindow.setTimeout == "function") {
return subWindow;
}
} catch (e) {}
return window;
}
/**
* An item in the PGO training corpus
*/
class Item {
url;
timeout;
waitFor;
/**
* @param {string} url URL to open.
* @param {number} timeout Maximum time to keep the item open.
* @param {string} waitFor What signals that the item is done: "load" for the load
* event, "report" for a perf-reftest-singleton calling tpRecordTime,
* "benchmark" for a completion message posted by the benchmark, or
* "timeout" to always wait for the full timeout.
*/
constructor(url, timeout = defaultTimeout, waitFor = "load") {
this.url = url;
this.timeout = timeout;
this.waitFor = waitFor;
}
async run() {
let finished;
let completed = new Promise(resolve => {
finished = resolve;
});
var subWindow = window.open(this.url);
let onMessage = e => {
if (e.source === subWindow && e.data && e.data.pgoBenchmarkDone) {
finished(benchmarkGracePeriod);
}
};
// Prevent the perf-reftest-singletons from calling alert()
subWindow.tpRecordTime = () => {
if (this.waitFor == "report") {
finished(reportGracePeriod);
}
};
if (this.waitFor == "load") {
watchLoad(subWindow, () => finished(loadGracePeriod));
} else if (this.waitFor == "benchmark") {
window.addEventListener("message", onMessage);
}
let gracePeriod = await Promise.race([
completed,
waitTimeout(this.timeout),
]);
window.removeEventListener("message", onMessage);
if (gracePeriod !== undefined) {
await waitTimeout(gracePeriod, timerWindow(subWindow));
}
subWindow.close();
}
}
function watchLoad(subWindow, callback) {
let loaded = () => {
try {
return (
subWindow.location.href != "about:blank" &&
subWindow.document.readyState == "complete"
);
} catch (e) {
return false;
}
};
subWindow.addEventListener("load", () => {
if (loaded()) {
callback();
}
});
let poll = window.setInterval(() => {
if (subWindow.closed || loaded()) {
window.clearInterval(poll);
if (!subWindow.closed) {
callback();
}
}
}, 100);
}
var defaultItemUrls = [
"blueprint/elements.html",
"blueprint/forms.html",
"blueprint/grid.html",
"blueprint/sample.html",
"js-input/3d-thingy.html",
"js-input/crypto-otp.html",
"js-input/collator_bench.html",
"js-input/normalizer_bench.html",
"js-input/sunspider/3d-cube.html",
"js-input/sunspider/3d-morph.html",
"js-input/sunspider/3d-raytrace.html",
"js-input/sunspider/access-binary-trees.html",
"js-input/sunspider/access-fannkuch.html",
"js-input/sunspider/access-nbody.html",
"js-input/sunspider/access-nsieve.html",
"js-input/sunspider/bitops-3bit-bits-in-byte.html",
"js-input/sunspider/bitops-bits-in-byte.html",
"js-input/sunspider/bitops-bitwise-and.html",
"js-input/sunspider/bitops-nsieve-bits.html",
"js-input/sunspider/controlflow-recursive.html",
"js-input/sunspider/crypto-aes.html",
"js-input/sunspider/crypto-md5.html",
"js-input/sunspider/crypto-sha1.html",
"js-input/sunspider/date-format-tofte.html",
"js-input/sunspider/date-format-xparb.html",
"js-input/sunspider/math-cordic.html",
"js-input/sunspider/math-partial-sums.html",
"js-input/sunspider/math-spectral-norm.html",
"js-input/sunspider/regexp-dna.html",
"js-input/sunspider/string-base64.html",
"js-input/sunspider/string-fasta.html",
"js-input/sunspider/string-tagcloud.html",
"js-input/sunspider/string-unpack-code.html",
"js-input/sunspider/string-validate-input.html",
"talos/tests/perf-reftest-singletons/abspos-reflow-1.html",
"talos/tests/perf-reftest-singletons/attr-selector-1.html",
"talos/tests/perf-reftest-singletons/bidi-resolution-1.html",
"talos/tests/perf-reftest-singletons/bloom-basic-2.html",
"talos/tests/perf-reftest-singletons/bloom-basic.html",
"talos/tests/perf-reftest-singletons/coalesce-1.html",
"talos/tests/perf-reftest-singletons/coalesce-2.html",
"talos/tests/perf-reftest-singletons/display-none-1.html",
"talos/tests/perf-reftest-singletons/external-string-pass.html",
"talos/tests/perf-reftest-singletons/getElementById-1.html",
"talos/tests/perf-reftest-singletons/id-getter-1.html",
"talos/tests/perf-reftest-singletons/id-getter-2.html",
"talos/tests/perf-reftest-singletons/id-getter-3.html",
"talos/tests/perf-reftest-singletons/id-getter-4.html",
"talos/tests/perf-reftest-singletons/id-getter-5.html",
"talos/tests/perf-reftest-singletons/id-getter-6.html",
"talos/tests/perf-reftest-singletons/id-getter-7.html",
"talos/tests/perf-reftest-singletons/inline-style-cache-1.html",
"talos/tests/perf-reftest-singletons/line-iterator.html",
"talos/tests/perf-reftest-singletons/link-style-cache-1.html",
"talos/tests/perf-reftest-singletons/nth-index-1.html",
"talos/tests/perf-reftest-singletons/nth-index-2.html",
"talos/tests/perf-reftest-singletons/only-children-1.html",
"talos/tests/perf-reftest-singletons/parent-basic-singleton.html",
"talos/tests/perf-reftest-singletons/resize-lengthy-textarea.html",
"talos/tests/perf-reftest-singletons/scrollbar-styles-1.html",
"talos/tests/perf-reftest-singletons/slow-selector-1.html",
"talos/tests/perf-reftest-singletons/slow-selector-2.html",
"talos/tests/perf-reftest-singletons/style-attr-1.html",
"talos/tests/perf-reftest-singletons/style-sharing-style-attr.html",
"talos/tests/perf-reftest-singletons/style-sharing.html",
"talos/tests/perf-reftest-singletons/svg-text-textLength-1.html",
"talos/tests/perf-reftest-singletons/svg-text-getExtentOfChar-1.html",
"talos/tests/perf-reftest-singletons/tiny-traversal-singleton.html",
"talos/tests/perf-reftest-singletons/window-named-property-get.html",
];
// Start with items with the default timeout
var items = defaultItemUrls.map(x => {
if (x.includes("perf-reftest-singletons")) {
return new Item(x, defaultTimeout, "report");
}
// This page animates continuously, so it never finishes on its own.
if (x.endsWith("3d-thingy.html")) {
return new Item(x, defaultTimeout, "timeout");
}
return new Item(x);
});
// Add items that needs longer timeouts
items.push(
new Item(
"webkit/PerformanceTests/Speedometer/index.html",
extendedTimeout,
"benchmark"
),
new Item(
extendedTimeout,
"benchmark"
),
new Item(
"webkit/PerformanceTests/webaudio/index.html?raptor&rendering-buffer-length=30",
extendedTimeout,
"benchmark"
)
);
// Add optional items if there is a 'pgo-extended-corpus' provided
if (hasExtendedCorpus) {
items.push(
new Item(
superExtendedTimeout,
"benchmark"
)
);
}
window.onload = async function () {
for (let item of items) {
await item.run();
}
Quitter.quit();
};
for (let item of items) {
// eslint-disable-next-line no-unsanitized/method
document.write(item.url);
document.write("<br>");
}
</script>