Commit 4ca4e079 authored by Denys Mishunov's avatar Denys Mishunov

Log user timing metrics

We output User Timing API based metrics into the console when
the performance bar is enabled
parent 62bb3e68
...@@ -16,6 +16,29 @@ const initVitalsLog = () => { ...@@ -16,6 +16,29 @@ const initVitalsLog = () => {
getLCP(reportVital); getLCP(reportVital);
}; };
const logUserTimingMetrics = () => {
const metricsProcessor = list => {
const entries = list.getEntries();
entries.forEach(entry => {
const { name, entryType, startTime, duration } = entry;
const typeMapper = {
mark: String.fromCodePoint(0x1f3af),
measure: String.fromCodePoint(0x1f4d0),
};
console.group(`${typeMapper[entryType]} ${name}`);
if (entryType === 'mark') {
console.log(`Start time: ${startTime}`);
} else if (entryType === 'measure') {
console.log(`Duration: ${duration}`);
}
console.log(entry);
console.groupEnd();
});
};
const observer = new PerformanceObserver(metricsProcessor);
observer.observe({ entryTypes: ['mark', 'measure'] });
};
const initPerformanceBarLog = () => { const initPerformanceBarLog = () => {
console.log( console.log(
`%c ${String.fromCodePoint(0x1f98a)} GitLab performance bar`, `%c ${String.fromCodePoint(0x1f98a)} GitLab performance bar`,
...@@ -23,6 +46,7 @@ const initPerformanceBarLog = () => { ...@@ -23,6 +46,7 @@ const initPerformanceBarLog = () => {
); );
initVitalsLog(); initVitalsLog();
logUserTimingMetrics();
}; };
export default initPerformanceBarLog; export default initPerformanceBarLog;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment