2020-09-16 12:10:15 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
import { getCLS, getFID, getLCP } from 'web-vitals';
|
2020-11-05 21:08:51 +00:00
|
|
|
import { PERFORMANCE_TYPE_MARK, PERFORMANCE_TYPE_MEASURE } from '~/performance/constants';
|
2020-09-16 12:10:15 +00:00
|
|
|
|
|
|
|
const initVitalsLog = () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
const reportVital = (data) => {
|
2020-09-16 12:10:15 +00:00
|
|
|
console.log(`${String.fromCodePoint(0x1f4c8)} ${data.name} : `, data);
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
`${String.fromCodePoint(
|
|
|
|
0x1f4d1,
|
|
|
|
)} To get the final web vital numbers reported you maybe need to switch away and back to the tab`,
|
|
|
|
);
|
|
|
|
getCLS(reportVital);
|
|
|
|
getFID(reportVital);
|
|
|
|
getLCP(reportVital);
|
|
|
|
};
|
|
|
|
|
2020-09-24 18:09:51 +00:00
|
|
|
const logUserTimingMetrics = () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
const metricsProcessor = (list) => {
|
2020-09-24 18:09:51 +00:00
|
|
|
const entries = list.getEntries();
|
2020-12-23 21:10:24 +00:00
|
|
|
entries.forEach((entry) => {
|
2020-09-24 18:09:51 +00:00
|
|
|
const { name, entryType, startTime, duration } = entry;
|
|
|
|
const typeMapper = {
|
2020-09-25 18:09:46 +00:00
|
|
|
[PERFORMANCE_TYPE_MARK]: String.fromCodePoint(0x1f3af),
|
|
|
|
[PERFORMANCE_TYPE_MEASURE]: String.fromCodePoint(0x1f4d0),
|
2020-09-24 18:09:51 +00:00
|
|
|
};
|
|
|
|
console.group(`${typeMapper[entryType]} ${name}`);
|
|
|
|
if (entryType === PERFORMANCE_TYPE_MARK) {
|
|
|
|
console.log(`Start time: ${startTime}`);
|
|
|
|
} else if (entryType === PERFORMANCE_TYPE_MEASURE) {
|
|
|
|
console.log(`Duration: ${duration}`);
|
|
|
|
}
|
|
|
|
console.log(entry);
|
|
|
|
console.groupEnd();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const observer = new PerformanceObserver(metricsProcessor);
|
|
|
|
observer.observe({ entryTypes: [PERFORMANCE_TYPE_MEASURE, PERFORMANCE_TYPE_MARK] });
|
|
|
|
};
|
|
|
|
|
2020-09-16 12:10:15 +00:00
|
|
|
const initPerformanceBarLog = () => {
|
|
|
|
console.log(
|
|
|
|
`%c ${String.fromCodePoint(0x1f98a)} GitLab performance bar`,
|
2021-01-21 12:09:05 +00:00
|
|
|
'width:100%; background-color: #292961; color: #FFFFFF; padding: 10px; display:block;',
|
2020-09-16 12:10:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
initVitalsLog();
|
2020-09-24 18:09:51 +00:00
|
|
|
logUserTimingMetrics();
|
2020-09-16 12:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default initPerformanceBarLog;
|