@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
47 lines (45 loc) • 999 B
JavaScript
/**
* Shared performance tracking utilities for use in both main thread and worker
*/
export class PerformanceTracker {
logs = [];
constructor() {
this.baseTime = performance.now();
}
mark(name) {
const time = performance.now();
this.logs.push({
type: 'mark',
name,
startTime: time - this.baseTime
});
return time;
}
measure(name, startTime, endTime) {
this.logs.push({
type: 'measure',
name,
startTime: startTime - this.baseTime,
duration: endTime - startTime
});
}
getLogs() {
return this.logs;
}
clear() {
this.logs = [];
}
}
/**
* Reconstruct performance measures in the main thread from worker logs
*/
export function reconstructPerformanceLogs(logs, timeOffset) {
logs.forEach(log => {
if (log.type === 'measure' && log.duration !== undefined) {
performance.measure(log.name, {
start: timeOffset + log.startTime,
duration: log.duration
});
}
});
}