MCPcopy Index your code
hub / github.com/codeaashu/claude-code / writePerfettoTrace

Function writePerfettoTrace

src/utils/telemetry/perfettoTracing.ts:1011–1037  ·  view source on GitHub ↗

* Final async write: close open spans and write the complete trace. * Idempotent — sets `traceWritten` on success so subsequent calls are no-ops.

()

Source from the content-addressed store, hash-verified

1009 * Idempotent — sets `traceWritten` on success so subsequent calls are no-ops.
1010 */
1011async function writePerfettoTrace(): Promise<void> {
1012 if (!isEnabled || !tracePath || traceWritten) {
1013 logForDebugging(
1014 `[Perfetto] Skipping final write: isEnabled=${isEnabled}, tracePath=${tracePath}, traceWritten=${traceWritten}`,
1015 )
1016 return
1017 }
1018
1019 stopWriteInterval()
1020 closeOpenSpans()
1021
1022 logForDebugging(
1023 `[Perfetto] writePerfettoTrace called: events=${events.length}`,
1024 )
1025
1026 try {
1027 await mkdir(dirname(tracePath), { recursive: true })
1028 await writeFile(tracePath, buildTraceDocument())
1029 traceWritten = true
1030 logForDebugging(`[Perfetto] Trace finalized at: ${tracePath}`)
1031 } catch (error) {
1032 logForDebugging(
1033 `[Perfetto] Failed to write final trace: ${errorMessage(error)}`,
1034 { level: 'error' },
1035 )
1036 }
1037}
1038
1039/**
1040 * Final synchronous write (fallback for process 'exit' handler where async is forbidden).

Callers 1

Calls 6

logForDebuggingFunction · 0.85
stopWriteIntervalFunction · 0.85
closeOpenSpansFunction · 0.85
mkdirFunction · 0.85
buildTraceDocumentFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected