* Get a formatted report of all checkpoints * Only available when DETAILED_PROFILING is enabled
()
| 80 | * Only available when DETAILED_PROFILING is enabled |
| 81 | */ |
| 82 | function getReport(): string { |
| 83 | if (!DETAILED_PROFILING) { |
| 84 | return 'Startup profiling not enabled' |
| 85 | } |
| 86 | |
| 87 | const perf = getPerformance() |
| 88 | const marks = perf.getEntriesByType('mark') |
| 89 | if (marks.length === 0) { |
| 90 | return 'No profiling checkpoints recorded' |
| 91 | } |
| 92 | |
| 93 | const lines: string[] = [] |
| 94 | lines.push('='.repeat(80)) |
| 95 | lines.push('STARTUP PROFILING REPORT') |
| 96 | lines.push('='.repeat(80)) |
| 97 | lines.push('') |
| 98 | |
| 99 | let prevTime = 0 |
| 100 | for (const [i, mark] of marks.entries()) { |
| 101 | lines.push( |
| 102 | formatTimelineLine( |
| 103 | mark.startTime, |
| 104 | mark.startTime - prevTime, |
| 105 | mark.name, |
| 106 | memorySnapshots[i], |
| 107 | 8, |
| 108 | 7, |
| 109 | ), |
| 110 | ) |
| 111 | prevTime = mark.startTime |
| 112 | } |
| 113 | |
| 114 | const lastMark = marks[marks.length - 1] |
| 115 | lines.push('') |
| 116 | lines.push(`Total startup time: ${formatMs(lastMark?.startTime ?? 0)}ms`) |
| 117 | lines.push('='.repeat(80)) |
| 118 | |
| 119 | return lines.join('\n') |
| 120 | } |
| 121 | |
| 122 | let reported = false |
| 123 |
no test coverage detected