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
impl Profiler
Sourcepub fn new_heap() -> Self
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}Sourcepub fn new_ad_hoc() -> Self
pub fn new_ad_hoc() -> Self
Construct an ad-hoc-mode profiler. Writes
dhat-ad-hoc.json on drop.
Sourcepub fn builder() -> ProfilerBuilder
pub fn builder() -> ProfilerBuilder
Start a builder for fine-grained configuration.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Profiler
impl RefUnwindSafe for Profiler
impl Send for Profiler
impl Sync for Profiler
impl Unpin for Profiler
impl UnsafeUnpin for Profiler
impl UnwindSafe for Profiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more