MCPcopy
hub / github.com/codeaashu/claude-code / evictOldestEvents

Function evictOldestEvents

src/utils/telemetry/perfettoTracing.ts:232–247  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

230 * is inserted so the gap is visible in ui.perfetto.dev.
231 */
232function 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

Callers 2

Calls 2

logForDebuggingFunction · 0.85
spliceMethod · 0.80

Tested by

no test coverage detected