Skip to main content

Crate blad_mem

Crate blad_mem 

Source
Expand description

Memory instrumentation.

Two numbers, deliberately, because they answer different questions and their difference is itself informative:

  • Heap — bytes we allocated, counted exactly by wrapping the global allocator. Resettable, so it can be attributed per phase.
  • RSS — what the OS considers resident, a monotonic high-water mark. Includes things the heap counter cannot see: mapped libraries, allocator overhead, and any memory allocated inside vendored C++ rather than through Rust’s global allocator.

The gap between them is the cost of everything that is not our data structures. For blad that is dominated by libjxl’s own working set, which the heap counter cannot see at all — exactly the kind of thing that stays invisible if you only measure one.

Both numbers are for this process only. /usr/bin/time -l includes children and will attribute a subprocess’s peak to us; that mistake was made once here already.

§Usage

The binary installs the allocator:

#[global_allocator]
static ALLOC: blad_mem::Tracking<std::alloc::System> =
    blad_mem::Tracking(std::alloc::System);

Without that, heap_peak reports zero and everything still works — instrumentation must never be load-bearing.

Structs§

Phase
Time, heap, and RSS for one phase of work.
Tracking
Global allocator wrapper that tracks live bytes and a resettable high-water mark.

Functions§

heap_current
Bytes currently allocated through the tracking allocator.
heap_peak
Highest heap_current seen since the last reset_heap_peak.
measure
Run f, timing it and measuring its heap peak in isolation.
reset_heap_peak
Drop the high-water mark to the current level, so the next phase is measured on its own rather than inheriting the previous one’s peak.
rss_highwater
Process peak resident set size, in bytes.