Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
export class InitPerformanceTracer {
|
|
results: {name: string, dur: number}[] = [];
|
|
recordCall(name: string, func: () => void) {
|
|
const start = performance.now();
|
|
func();
|
|
this.results.push({name, dur: performance.now() - start});
|
|
}
|
|
printResults() {
|
|
this.results = this.results.sort((a, b) => b.dur - a.dur);
|
|
for (let i = 0; i < 20 && i < this.results.length; i++) {
|
|
console.info(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function callInitFunctions(functions: (() => any)[]): InitPerformanceTracer | null {
|
|
// Start performance trace by accessing a URL by "https://localhost/?_ui_performance_trace=1" or "https://localhost/?key=value&_ui_performance_trace=1"
|
|
// It is a quick check, no side effect so no need to do slow URL parsing.
|
|
const perfTracer = !window.location.search.includes('_ui_performance_trace=1') ? null : new InitPerformanceTracer();
|
|
if (perfTracer) {
|
|
for (const func of functions) perfTracer.recordCall(func.name, func);
|
|
} else {
|
|
for (const func of functions) func();
|
|
}
|
|
return perfTracer;
|
|
}
|