Skip to main content

Profiler

Struct Profiler 

Source
pub struct Profiler { /* private fields */ }
Available on crate feature dhat-compat only.
Expand description

RAII handle that writes a DHAT-format JSON report on drop.

Drop-in-shaped replacement for dhat::Profiler. Hold the returned value in main (or wherever you want the file to land) and let scope exit trigger the write.

§Example

use mod_alloc::dhat_compat::{Alloc, Profiler};

#[global_allocator]
static ALLOC: Alloc = Alloc;

fn main() {
    let _profiler = Profiler::new_heap();
    let _v: Vec<u8> = vec![0; 1024];
    // _profiler drops here → writes dhat-heap.json
}

Implementations§

Source§

impl Profiler

Source

pub fn new_heap() -> Self

Construct a heap-mode profiler. Writes dhat-heap.json on drop unless builder().file_name(...) was used.

Examples found in repository?
examples/dhat_drop_in.rs (line 36)
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}
Source

pub fn new_ad_hoc() -> Self

Construct an ad-hoc-mode profiler. Writes dhat-ad-hoc.json on drop.

Source

pub fn builder() -> ProfilerBuilder

Start a builder for fine-grained configuration.

Trait Implementations§

Source§

impl Drop for Profiler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> 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, 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.