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