cal.pub0.org/packages/lib/server/perfObserver.ts

24 lines
609 B
TypeScript

import { PerformanceObserver } from "perf_hooks";
declare global {
// eslint-disable-next-line no-var
var perfObserver: PerformanceObserver | undefined;
}
export const perfObserver =
globalThis.perfObserver ||
new PerformanceObserver((items, observer) => {
items.getEntries().forEach((entry) => {
console.log(entry); // fake call to our custom logging solution
});
observer.observe({ entryTypes: ["measure"] });
});
if (process.env.NODE_ENV !== "production") {
globalThis.perfObserver = perfObserver;
}
export default perfObserver;
export { performance } from "perf_hooks";