Crates.io | peak_alloc |
lib.rs | peak_alloc |
version | 0.2.1 |
source | src |
created_at | 2021-01-08 13:53:57.621414 |
updated_at | 2024-02-26 12:30:52.893208 |
description | An allocator to keep track of (the max) allocated memory |
homepage | |
repository | https://github.com/xgillard/peak_alloc |
max_upload_size | |
id | 334317 |
size | 10,136 |
Peak Alloc is a dead simple and willingly low overhead allocator for rust which allows you to track (and consult) the amount of memory that is being allocated to your process as well as the maximum amount of memory that has been allocatd to your process over the course of its life.
When I mean that peak alloc is low overhead, I mean that all it ever maintains, is a pair of two atomic usize. So the overhead is low...but there is and overhead because of the atomic number manipulations.
The peak allocator is really just a shim around the system allocator. The
bulk of its work is delegated to the system allocator and all PeakAlloc
does is to maintain the atomic counters.
In your Cargo.toml
, you should add the following line to your dependencies
section.
[dependencies]
peak_alloc = "0.2.0"
Then in your main code, you will simply use it as shown below:
use peak_alloc::PeakAlloc;
#[global_allocator]
static PEAK_ALLOC: PeakAlloc = PeakAlloc;
fn main() {
// Do your funky stuff...
let current_mem = PEAK_ALLOC.current_usage_as_mb();
println!("This program currently uses {} MB of RAM.", current_mem);
let peak_mem = PEAK_ALLOC.peak_usage_as_gb();
println!("The max amount that was used {}", peak_mem);
}