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