pub struct HeapStats {
pub total_blocks: u64,
pub total_bytes: u64,
pub curr_blocks: usize,
pub curr_bytes: usize,
pub max_blocks: usize,
pub max_bytes: usize,
}dhat-compat only.Expand description
Heap-mode statistics snapshot. Mirrors the shape of
dhat::HeapStats field-for-field so consumers migrating from
dhat can drop in the type alias without code edits.
Note the total_* fields are u64 while curr_* and max_*
are usize — this matches dhat-rs exactly. On 32-bit targets
the u64 -> usize casts in HeapStats::get are saturating;
in practice mod-alloc targets 64-bit only (the Tier 2 walker
requires x86_64 / aarch64).
§Example
use mod_alloc::dhat_compat::{Alloc, HeapStats};
#[global_allocator]
static ALLOC: Alloc = Alloc;
let _v: Vec<u8> = vec![0; 1024];
let stats = HeapStats::get();
assert!(stats.total_bytes >= 1024);Fields§
§total_blocks: u64Total blocks ever allocated (lifetime count).
total_bytes: u64Total bytes ever allocated (lifetime sum).
curr_blocks: usizeCurrently-alive block count.
curr_bytes: usizeCurrently-resident bytes.
max_blocks: usizePeak live block count.
max_bytes: usizePeak resident bytes.
Implementations§
Source§impl HeapStats
impl HeapStats
Sourcepub fn get() -> Self
pub fn get() -> Self
Snapshot the current heap statistics from the installed allocator.
If no crate::dhat_compat::Alloc (or crate::ModAlloc)
is installed as #[global_allocator] and no allocation has
occurred yet, all fields are zero.
Examples found in repository?
35fn main() {
36 let _profiler = dhat::Profiler::new_heap();
37
38 for _ in 0..500 {
39 alloc_small();
40 }
41 for _ in 0..100 {
42 alloc_medium();
43 }
44
45 let stats = dhat::HeapStats::get();
46 println!(
47 "total_blocks: {}, total_bytes: {}, max_bytes: {}, curr_blocks: {}",
48 stats.total_blocks, stats.total_bytes, stats.max_bytes, stats.curr_blocks,
49 );
50 println!("_profiler drops at end of main → writes dhat-heap.json");
51}