Skip to content

Commit

Permalink
fix: perflogger mark detail bug (#10818)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Jan 6, 2025
1 parent 0df6984 commit 431526e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/docusaurus-logger/src/perfLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,24 @@ function createPerfLogger(): PerfLoggerAPI {
},
});

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 {
duration,
detail: {memoryUsage},
} = performance.measure(label);
performance.clearMarks(label);
} = startMark;
printPerfLog({
label: applyParentPrefix(label),
duration,
Expand Down

0 comments on commit 431526e

Please sign in to comment.