Skip to main content

heap_dump_json

Function heap_dump_json 

Source
pub fn heap_dump_json(
    include_blocks: bool,
    hash_addresses: bool,
) -> Option<String>
Expand description

Live per-heap -> per-page -> (optional) per-block JSON snapshot of the current subprocess (issue #269, Bun parity P4). Backs Bun’s shipped bun:jsc heapStats({dump:true|"blocks"}).mimallocDump; see src/heap-dump.c for the JSON shape ({"heaps":[{"seq":N,"pages":[{"id","block_size","used","reserved","thread_id"}], "blocks":[[id,size],...]}]}, blocks present only when include_blocks).

Set hash_addresses to mix every reported address through a per-process key so a dump can be shared or diffed without exposing raw ASLR-derived pointers.

Best-effort under concurrent frees on the heaps being walked (mimalloc’s mi_heap_visit_blocks/mi_subproc_visit_heaps contract; see the caveat on src/heap-dump.c and issue #78) – never unsafe to call, but a heap another thread is actively freeing into may be under- or over-reported in the returned JSON.

Returns None only on allocation failure (out of memory building the JSON buffer), not for an empty subprocess.