fix: perflogger mark detail bug (#10818)

This commit is contained in:
Sébastien Lorber 2025-01-06 14:13:14 +01:00 committed by GitHub
parent 0df69844b6
commit 431526ecbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -114,12 +114,24 @@ function createPerfLogger(): PerfLoggerAPI {
},
});
const end: PerfLoggerAPI['end'] = (label) => {
const {
duration,
detail: {memoryUsage},
} = performance.measure(label);
const readMark = (label: string) => {
const startMark = performance.getEntriesByName(
label,
'mark',
)?.[0] as PerformanceMark;
if (!startMark) {
throw new Error(`No performance start mark for label=${label}`);
}
performance.clearMarks(label);
return startMark;
};
const end: PerfLoggerAPI['end'] = (label) => {
const startMark = readMark(label);
const duration = performance.now() - startMark.startTime;
const {
detail: {memoryUsage},
} = startMark;
printPerfLog({
label: applyParentPrefix(label),
duration,