Skip to main content

Module memory

Module memory 

Source
Expand description

Resident Set Size (RSS) sampling for memory diagnostics.

Used by the allocator benchmark (vtcode bench-allocator) to measure whether the global allocator returns memory to the OS after bursty/sparse workloads. Unlike performance_profiler::get_memory_usage_mb (Linux /proc only, fake fallback on macOS), this returns a real value on every supported platform.

Functionsยง

resident_set_size_mb
Returns the current process Resident Set Size in megabytes, or None if it cannot be determined on the current platform.
sample_peak_rss_mb
Sample RSS repeatedly, returning the maximum observed value in MB. Useful for capturing peak memory during a burst of activity.
sample_peak_rss_mb_while
Like sample_peak_rss_mb, but stops early once should_continue returns false. The predicate is checked before each sample, so a caller measuring a burst can release the sampler as soon as the burst ends instead of waiting out a worst-case timeout. Intended for blocking threads (e.g. spawn_blocking): each poll is a syscall followed by thread::sleep, which must not run on a Tokio worker.
sample_rss_mb
Sample RSS once and return the value in MB (0.0 if unavailable).