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

Function writeHeapSnapshot

src/utils/heapDumpService.ts:284–303  ·  view source on GitHub ↗

* Write heap snapshot to a file. * Uses pipeline() which handles stream cleanup automatically on errors.

(filepath: string)

Source from the content-addressed store, hash-verified

282 * Uses pipeline() which handles stream cleanup automatically on errors.
283 */
284async function writeHeapSnapshot(filepath: string): Promise<void> {
285 if (typeof Bun !== 'undefined') {
286 // In Bun, heapsnapshots are currently not streaming.
287 // Use synchronous I/O despite potentially large filesize so that we avoid cloning the string for cross-thread usage.
288 //
289 /* eslint-disable custom-rules/no-sync-fs -- intentionally sync to avoid cloning large heap snapshot string for cross-thread usage */
290 // @ts-expect-error 2nd argument is in the next version of Bun
291 writeFileSync(filepath, Bun.generateHeapSnapshot('v8', 'arraybuffer'), {
292 mode: 0o600,
293 })
294 /* eslint-enable custom-rules/no-sync-fs */
295
296 // Force GC to try to free that heap snapshot sooner.
297 Bun.gc(true)
298 return
299 }
300 const writeStream = createWriteStream(filepath, { mode: 0o600 })
301 const heapSnapshotStream = getHeapSnapshot()
302 await pipeline(heapSnapshotStream, writeStream)
303}
304

Callers 1

performHeapDumpFunction · 0.85

Calls 1

createWriteStreamFunction · 0.90

Tested by

no test coverage detected