Skip to main content

Module alloc

Module alloc 

Source
Available on crate feature alloc-tracking only.
Expand description

Allocation tracking. Available with the alloc-tracking feature.

Wraps mod-alloc’s dhat_compat surface (a drop-in replacement for dhat-rs) to capture total bytes, total allocation count, and peak resident bytes during a benchmark. Reports a CheckResult with regression-style verdict.

As of v0.9.7 the backend is mod-alloc instead of dhat; the public API surface here (AllocationStats, the install_global_allocator! macro) is unchanged. JSON output from mod-alloc::dhat_compat::Profiler loads in the same upstream dh_view.html viewer.

§Cost

Enabling alloc-tracking installs a tracking global allocator. It is heavier than the default allocator and changes timing characteristics. Do not combine allocation thresholds with timing thresholds in the same invocation. Run timing benchmarks with the feature off and allocation benchmarks with it on.

§Setup

Use the install_global_allocator! macro at module scope in your binary or test target:

dev_bench::install_global_allocator!();

Then start a profiler before the benchmark and snapshot stats after:

use mod_alloc::dhat_compat as dhat;

let _profiler = dhat::Profiler::new_heap();
// ... run benchmarked code ...
let stats = dev_bench::alloc::AllocationStats::snapshot();

The macro expands to a #[global_allocator] static of mod_alloc::dhat_compat::Alloc.

Structs§

AllocationStats
Snapshot of allocation activity, captured from mod_alloc::dhat_compat::HeapStats (drop-in for dhat::HeapStats).