Bug 1380676 - Replace usages of Date.now() with performance.now() in testing/talos. r=sparky,perftest-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D81575
This commit is contained in:
kanishk509 2020-07-07 11:55:04 +00:00
parent ee86c32c2e
commit 4652478d3d
15 changed files with 62 additions and 46 deletions

View File

@ -9,7 +9,7 @@ function _contentHeroHandler(isload) {
function callback(entries, observer) {
entries.forEach(entry => {
sendAsyncMessage("PageLoader:LoadEvent", {
time: Date.now(), // eslint-disable-line
time: content.window.performance.now(),
name: "tphero",
});
obs.disconnect();

View File

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from report.js */
/* eslint mozilla/avoid-Date-timing: "off" */
var { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
@ -409,7 +408,7 @@ function startAndLoadURI(pageName) {
TalosParentProfiler.resume("Starting to load URI " + pageName);
}
start_time = Date.now();
start_time = window.performance.now();
if (loadNoCache) {
content.loadURI(pageName, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
@ -532,9 +531,9 @@ var plNextPage = async function() {
if (doNextPage) {
if (forceCC) {
var tccstart = new Date();
var tccstart = window.performance.now();
window.windowUtils.garbageCollect();
var tccend = new Date();
var tccend = window.performance.now();
report.recordCCTime(tccend - tccstart);
// Now asynchronously trigger GC / CC in the content process
@ -733,7 +732,10 @@ function _loadHandlerCapturing() {
if (useMozAfterPaint) {
if (gStartTime != null && gStartTime >= 0) {
gTime = new Date() - gStartTime;
gTime =
window.performance.timing.navigationStart +
window.performance.now() -
gStartTime;
gStartTime = -1;
}
}
@ -786,9 +788,18 @@ function _loadHandler(paint_time = 0) {
if (paint_time !== 0) {
// window.performance.timing.timeToNonBlankPaint is a timestamp
// this may have a value for hero element (also a timestamp)
end_time = paint_time;
let minDate = new Date("2001");
if (paint_time < minDate) {
//paint_time is a performance.now() value
end_time = paint_time;
} else {
//paint_time is a UNIX timestamp
end_time = paint_time - window.performance.timing.navigationStart;
}
} else {
end_time = Date.now();
end_time = window.performance.now();
}
var duration;
@ -843,7 +854,7 @@ function plLoadHandlerMessage(message) {
}
if (gTime !== -1) {
if (useMozAfterPaint && gStartTime >= 0) {
time = Date.now() - gStartTime;
time = window.performance.now() - gStartTime;
gStartTime = -1;
} else if (!useMozAfterPaint) {
time = gTime;

View File

@ -90,7 +90,7 @@ Report.prototype.getReport = function() {
report += "_x_x_mozilla_cycle_collect," + this.totalCCTime + "\n";
report += "__end_cc_report\n";
}
var now = new Date().getTime(); // eslint-disable-line mozilla/avoid-Date-timing
var now = window.performance.now();
report += "__startTimestamp" + now + "__endTimestamp\n"; // timestamp for determning shutdown time, used by talos
return report;

View File

@ -91,8 +91,8 @@ function testScroll(target, stepSize, opt_reportFunc, opt_numSteps) {
resolve();
});
// eslint-disable-next-line mozilla/avoid-Date-timing
imported.src = "../../scripts/talos-debug.js?dummy=" + Date.now(); // For some browsers to re-read
imported.src =
"../../scripts/talos-debug.js?dummy=" + win.performance.now(); // For some browsers to re-read
document.head.appendChild(imported);
return;
}
@ -125,12 +125,6 @@ function testScroll(target, stepSize, opt_reportFunc, opt_numSteps) {
});
}
function myNow() {
return win.performance && win.performance.now
? win.performance.now()
: Date.now(); // eslint-disable-line mozilla/avoid-Date-timing
}
var isWindow = target.self === target;
var getPos = isWindow
@ -191,13 +185,13 @@ function testScroll(target, stepSize, opt_reportFunc, opt_numSteps) {
function P_syncScrollTest() {
return new Promise(function(resolve) {
// We should be at the top of the page now.
var start = myNow();
var start = win.performance.now();
var lastScrollPos = getPos();
var lastScrollTime = start;
var durations = [];
function tick() {
var now = myNow();
var now = win.performance.now();
var duration = now - lastScrollTime;
lastScrollTime = now;

View File

@ -363,7 +363,7 @@ class BrowserLogResults(object):
self.error("Could not find %s in browser output: (tokens: %s)"
% (attr, tokens))
try:
value = int(value)
value = int(float(value))
except ValueError:
self.error("Could not cast %s to an integer: %s"
% (attr, value))

View File

@ -122,13 +122,13 @@ this.sessionrestore = class extends ExtensionAPI {
? StartupPerformance.latestRestoredTimeStamp
: startup_info.sessionRestored;
let duration = restoreTime - startup_info.process;
let win = BrowserWindowTracker.getTopWindow();
// Report data to Talos, if possible.
dump("__start_report" + duration + "__end_report\n\n");
// Next one is required by the test harness but not used.
// eslint-disable-next-line mozilla/avoid-Date-timing
dump("__startTimestamp" + Date.now() + "__endTimestamp\n\n");
dump("__startTimestamp" + win.performance.now() + "__endTimestamp\n\n");
} catch (ex) {
dump(`SessionRestoreTalosTest: error ${ex}\n`);
dump(ex.stack);

View File

@ -41,6 +41,7 @@ this.startup_about_home_paint = class extends ExtensionAPI {
async checkForTelemetry() {
let snapshot = Services.telemetry.getSnapshotForScalars("main");
let measurement = snapshot.parent[SCALAR_KEY];
let win = BrowserWindowTracker.getTopWindow();
if (!measurement) {
if (gAttempts == MAX_ATTEMPTS) {
dump(`Failed to get ${SCALAR_KEY} scalar probe in time.\n`);
@ -56,8 +57,7 @@ this.startup_about_home_paint = class extends ExtensionAPI {
} else {
// Got our measurement.
dump("__start_report" + measurement + "__end_report\n\n");
// eslint-disable-next-line mozilla/avoid-Date-timing
dump("__startTimestamp" + Date.now() + "__endTimestamp\n");
dump("__startTimestamp" + win.performance.now() + "__endTimestamp\n");
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment

View File

@ -48,8 +48,7 @@ function dumpConsoleAndQuit() {
// Close window asynchronously, there might still be startup operations that still need to run
window.setTimeout(function() {
if (window.dump) {
// eslint-disable-next-line mozilla/avoid-Date-timing
dump("__startTimestamp" + Date.now() + "__endTimestamp\n");
dump("__startTimestamp" + window.performance.now() + "__endTimestamp\n");
}
TalosPowersContent.goQuitApplication();
}, 0);

View File

@ -166,8 +166,7 @@ addEventListener(
let uniqueMessageId =
"TalosPowers:ParentExec:" +
content.document.documentURI +
// eslint-disable-next-line mozilla/avoid-Date-timing
Date.now() +
content.window.performance.now() +
Math.random();
// Listener for the reply from the parent process

View File

@ -18,7 +18,7 @@
TalosContentProfiler.resume("dhtml test start", true).then(() => {
var container = document.getElementById("container");
var lastchild = document.getElementById("lastchild");
var start = new Date(); // eslint-disable-line mozilla/avoid-Date-timing
var start = window.performance.now();
var i, div;
for (i = 0; i < 2000; i++) {
div = document.createElement("div");
@ -44,10 +44,10 @@
}
function postProcessingRecord(s) {
// alert(new Date() - s);
let delta = new Date() - s; // eslint-disable-line mozilla/avoid-Date-timing
// alert(window.performance.now() - s);
let delta = window.performance.now() - s;
TalosContentProfiler.pause("dhtml test finish", true).then(() => {
tpRecordTime(delta, s);
tpRecordTime(delta, window.performance.timing.navigationStart + s);
});
}
</script>

View File

@ -118,7 +118,7 @@ function mutateTable() {
ensureAccessibleTreeForId("start");
TalosContentProfiler.resume("tablemutation start", true).then(() => {
var start = new Date(); // eslint-disable-line mozilla/avoid-Date-timing
var start = window.performance.now();
// Cause all kinds of crazy events
Range.deleteContents();
@ -131,10 +131,10 @@ function mutateTable() {
}
function postProcessingRecord(s) {
// alert(new Date() - s);
let delta = new Date() - s; // eslint-disable-line mozilla/avoid-Date-timing
// alert(window.performance.now() - s);
let delta = window.performance.now() - s;
TalosContentProfiler.pause("tablemutation finish", true).then(() => {
tpRecordTime(delta, s);
tpRecordTime(delta, window.performance.timing.navigationStart + s);
});
}
</script>

View File

@ -30,6 +30,11 @@ ChromeUtils.defineModuleGetter(
"TalosParentProfiler",
"resource://talos-powers/TalosParentProfiler.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"BrowserWindowTracker",
"resource:///modules/BrowserWindowTracker.jsm"
);
const REDUCE_MOTION_PREF = "ui.prefersReducedMotion";
const MULTI_OPT_OUT_PREF = "dom.ipc.multiOptOut";
@ -128,12 +133,17 @@ this.tabpaint = class extends ExtensionAPI {
* with the time (in ms) it took to open the tab from the parent.
*/
async openTabFromParent(gBrowser, target) {
let win = BrowserWindowTracker.getTopWindow();
TalosParentProfiler.resume("tabpaint parent start");
// eslint-disable-next-line mozilla/avoid-Date-timing
gBrowser.selectedTab = gBrowser.addTab(`${target}?${Date.now()}`, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
gBrowser.selectedTab = gBrowser.addTab(
//win.performance.now() + win.performance.timing.navigationStart gives the UNIX timestamp.
`${target}?${win.performance.now() +
win.performance.timing.navigationStart}`,
{
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
}
);
let { tab, delta } = await this.whenTabShown();
TalosParentProfiler.pause("tabpaint parent end");

View File

@ -15,7 +15,9 @@ function init() {
window.addEventListener("TabPaint:OpenFromContent", (event) => {
let target = document.getElementById("target");
let now = Date.now(); // eslint-disable-line mozilla/avoid-Date-timing
//win.performance.now() + win.performance.timing.navigationStart gives the UNIX timestamp.
let now = window.performance.now() + window.performance.timing.navigationStart;
target.href = `${targetURL.href}?${now}`;
target.click();

View File

@ -30,8 +30,10 @@
}
var uniqueMessageId =
// eslint-disable-next-line mozilla/avoid-Date-timing
TART_PREFIX + content.document.documentURI + Date.now() + Math.random();
TART_PREFIX +
content.document.documentURI +
content.window.performance.now() +
Math.random();
addMessageListener(TART_PREFIX + "chrome-exec-reply", function done(
reply

View File

@ -7,8 +7,7 @@
var uniqueMessageId =
TRESIZE_PREFIX +
content.document.documentURI +
// eslint-disable-next-line mozilla/avoid-Date-timing
Date.now() +
content.window.performance.now() +
Math.random();
addMessageListener(TRESIZE_PREFIX + "chrome-run-reply", function done(