* Log startup performance phases to Statsig. * Only logs if this session was sampled at startup.
()
| 164 | * Only logs if this session was sampled at startup. |
| 165 | */ |
| 166 | function logStartupPerf(): void { |
| 167 | // Only log if we were sampled (decision made at module load) |
| 168 | if (!STATSIG_LOGGING_SAMPLED) return |
| 169 | |
| 170 | const perf = getPerformance() |
| 171 | const marks = perf.getEntriesByType('mark') |
| 172 | if (marks.length === 0) return |
| 173 | |
| 174 | // Build checkpoint lookup |
| 175 | const checkpointTimes = new Map<string, number>() |
| 176 | for (const mark of marks) { |
| 177 | checkpointTimes.set(mark.name, mark.startTime) |
| 178 | } |
| 179 | |
| 180 | // Compute phase durations |
| 181 | const metadata: Record<string, number | undefined> = {} |
| 182 | |
| 183 | for (const [phaseName, [startCheckpoint, endCheckpoint]] of Object.entries( |
| 184 | PHASE_DEFINITIONS, |
| 185 | )) { |
| 186 | const startTime = checkpointTimes.get(startCheckpoint) |
| 187 | const endTime = checkpointTimes.get(endCheckpoint) |
| 188 | |
| 189 | if (startTime !== undefined && endTime !== undefined) { |
| 190 | metadata[`${phaseName}_ms`] = Math.round(endTime - startTime) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // Add checkpoint count for debugging |
| 195 | metadata.checkpoint_count = marks.length |
| 196 | |
| 197 | logEvent( |
| 198 | 'tengu_startup_perf', |
| 199 | metadata as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 200 | ) |
| 201 | } |
no test coverage detected