Create metric for long javascript tasks

LongTasks API is well supported by most browsers. We can use it to
capture javascript tasks longer than 200 ms, so we can better
understand what is impact of javascript execution on page load.

Change-Id: I8fe0ec20e35ed3aa8dd97db43b345d6db72e4a85
This commit is contained in:
Milutin Kristofic
2019-10-18 14:08:41 +02:00
parent 2f91ec4923
commit 180b3da91d

View File

@@ -142,6 +142,22 @@
};
catchErrors();
// PerformanceObserver interface is a browser API.
if (PerformanceObserver) {
const catchLongJsTasks = new PerformanceObserver(list => {
for (const task of list.getEntries()) {
// We are interested in longtask longer than 200 ms (default is 50 ms)
if (task.duration > 200) {
GrReporting.prototype.reporter(TIMING.TYPE,
TIMING.CATEGORY_UI_LATENCY, `Task ${task.name}`,
Math.round(task.duration), false);
}
}
});
catchLongJsTasks.observe({entryTypes: ['longtask']});
}
// The Polymer pass of JSCompiler requires this to be reassignable
// eslint-disable-next-line prefer-const
let GrReporting = Polymer({