Skip to main content

HeapStats

Struct HeapStats 

Source
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,
}
Available on crate feature 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: u64

Total blocks ever allocated (lifetime count).

§total_bytes: u64

Total bytes ever allocated (lifetime sum).

§curr_blocks: usize

Currently-alive block count.

§curr_bytes: usize

Currently-resident bytes.

§max_blocks: usize

Peak live block count.

§max_bytes: usize

Peak resident bytes.

Implementations§

Source§

impl HeapStats

Source

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?
examples/dhat_drop_in.rs (line 45)
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}

Trait Implementations§

Source§

impl Clone for HeapStats

Source§

fn clone(&self) -> HeapStats

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeapStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for HeapStats

Source§

impl PartialEq for HeapStats

Source§

fn eq(&self, other: &HeapStats) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HeapStats

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.