Create metric for long javascript tasks

This is a revert and fix on
https://gerrit-review.googlesource.com/c/gerrit/+/244773

Change-Id: I16a5c303ec8f1b0310a5a86391a8ae90760ef750
This commit is contained in:
Tao Zhou
2019-11-13 20:01:09 +00:00
parent 02109bdb4e
commit d59cb8b7ae

View File

@@ -142,6 +142,25 @@
};
catchErrors();
// PerformanceObserver interface is a browser API.
if (window.PerformanceObserver) {
const supportedEntryTypes = PerformanceObserver.supportedEntryTypes || [];
// Safari doesn't support longtask yet
if (supportedEntryTypes.includes('longtask')) {
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({