* Final synchronous write (fallback for process 'exit' handler where async is forbidden).
()
| 1040 | * Final synchronous write (fallback for process 'exit' handler where async is forbidden). |
| 1041 | */ |
| 1042 | function 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) |
no test coverage detected