FgenerateHeapSnapshot
Bun

function

generateHeapSnapshot

format?: 'jsc'

Show precise statistics about memory usage of your application

Generate a heap snapshot in JavaScriptCore's format that can be viewed with bun --inspect or Safari's Web Inspector

format: 'v8'
): string;

Show precise statistics about memory usage of your application

Generate a V8 Heap Snapshot that can be used with Chrome DevTools & Visual Studio Code

This is a JSON string that can be saved to a file.

const snapshot = Bun.generateHeapSnapshot("v8");
await Bun.write("heap.heapsnapshot", snapshot);
format: 'v8',
encoding: 'arraybuffer'

Show precise statistics about memory usage of your application

Generate a V8 Heap Snapshot as an ArrayBuffer.

This avoids the overhead of creating a JavaScript string for large heap snapshots. The ArrayBuffer contains the UTF-8 encoded JSON.

const snapshot = Bun.generateHeapSnapshot("v8", "arraybuffer");
await Bun.write("heap.heapsnapshot", snapshot);

Referenced types

interface HeapSnapshot

JavaScriptCore engine's internal heap snapshot

I don't know how to make this something Chrome or Safari can read.

If you have any ideas, please file an issue https://github.com/oven-sh/bun

class ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

  • readonly [Symbol.toStringTag]: string
  • readonly byteLength: number

    Read-only. The length of the ArrayBuffer (in bytes).

  • newByteLength?: number
    ): void;

    Resizes the ArrayBuffer to the specified size (in bytes).

    MDN

    byteLength: number

    Resize an ArrayBuffer in-place.

  • begin: number,
    end?: number

    Returns a section of an ArrayBuffer.

  • newByteLength?: number

    Creates a new ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN

  • newByteLength?: number

    Creates a new non-resizable ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN