* Drop the oldest half of events[] when over MAX_EVENTS. Called from the * stale-span cleanup interval (60s). The half-batch splice keeps this * amortized O(1) — we don't pay splice cost per-push. A synthetic marker * is inserted so the gap is visible in ui.perfetto.dev.
()
| 230 | * is inserted so the gap is visible in ui.perfetto.dev. |
| 231 | */ |
| 232 | function evictOldestEvents(): void { |
| 233 | if (events.length < MAX_EVENTS) return |
| 234 | const dropped = events.splice(0, MAX_EVENTS / 2) |
| 235 | events.unshift({ |
| 236 | name: 'trace_truncated', |
| 237 | cat: '__metadata', |
| 238 | ph: 'i', |
| 239 | ts: dropped[dropped.length - 1]?.ts ?? 0, |
| 240 | pid: 1, |
| 241 | tid: 0, |
| 242 | args: { dropped_events: dropped.length }, |
| 243 | }) |
| 244 | logForDebugging( |
| 245 | `[Perfetto] Evicted ${dropped.length} oldest events (cap ${MAX_EVENTS})`, |
| 246 | ) |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Initialize Perfetto tracing |
no test coverage detected