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

Function writePerfettoTraceSync

src/utils/telemetry/perfettoTracing.ts:1042–1071  ·  view source on GitHub ↗

* Final synchronous write (fallback for process 'exit' handler where async is forbidden).

()

Source from the content-addressed store, hash-verified

1040 * Final synchronous write (fallback for process 'exit' handler where async is forbidden).
1041 */
1042function writePerfettoTraceSync(): void {
1043 if (!isEnabled || !tracePath || traceWritten) {
1044 logForDebugging(
1045 `[Perfetto] Skipping final sync write: isEnabled=${isEnabled}, tracePath=${tracePath}, traceWritten=${traceWritten}`,
1046 )
1047 return
1048 }
1049
1050 stopWriteInterval()
1051 closeOpenSpans()
1052
1053 logForDebugging(
1054 `[Perfetto] writePerfettoTraceSync called: events=${events.length}`,
1055 )
1056
1057 try {
1058 const dir = dirname(tracePath)
1059 // eslint-disable-next-line custom-rules/no-sync-fs -- Only called from process.on('exit') handler
1060 mkdirSync(dir, { recursive: true })
1061 // eslint-disable-next-line custom-rules/no-sync-fs, eslint-plugin-n/no-sync -- Required for process 'exit' handler which doesn't support async
1062 writeFileSync(tracePath, buildTraceDocument())
1063 traceWritten = true
1064 logForDebugging(`[Perfetto] Trace finalized synchronously at: ${tracePath}`)
1065 } catch (error) {
1066 logForDebugging(
1067 `[Perfetto] Failed to write final trace synchronously: ${errorMessage(error)}`,
1068 { level: 'error' },
1069 )
1070 }
1071}
1072
1073/**
1074 * Get all recorded events (for testing)

Callers 1

Calls 6

mkdirSyncFunction · 0.90
logForDebuggingFunction · 0.85
stopWriteIntervalFunction · 0.85
closeOpenSpansFunction · 0.85
buildTraceDocumentFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected