Crates.io | peakmem-alloc |
lib.rs | peakmem-alloc |
version | 0.3.0 |
source | src |
created_at | 2023-04-05 05:19:00.743255 |
updated_at | 2024-03-18 10:14:51.05976 |
description | An allocator wrapper that allows measuring peak memory consumption |
homepage | |
repository | https://github.com/PSeitz/peakmem-alloc |
max_upload_size | |
id | 830687 |
size | 9,183 |
An instrumenting middleware for global allocators in Rust, useful to find the peak memory consumed by a function.
use peakmem_alloc::*;
use std::alloc::System;
#[global_allocator]
static GLOBAL: &PeakMemAlloc<System> = &INSTRUMENTED_SYSTEM;
#[test]
fn example_using_region() {
GLOBAL.reset_peak_memory(); // Note that other threads may impact the peak memory computation.
let _x: Vec<u8> = Vec::with_capacity(1_024);
println!(
"Peak Memory used by function : {:#?}",
GLOBAL.get_peak_memory()
);
}
You can wrap your existing allocator as follows:
use jemallocator::Jemalloc;
use peakmem_alloc::*;
#[global_allocator]
static GLOBAL: PeakMemAlloc<Jemalloc> = PeakMemAlloc::new(Jemalloc);