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