https://github.com/pseitz/peakmem-alloc
Measure the peak memory consumption of a given scope in rust
https://github.com/pseitz/peakmem-alloc
Last synced: about 1 year ago
JSON representation
Measure the peak memory consumption of a given scope in rust
- Host: GitHub
- URL: https://github.com/pseitz/peakmem-alloc
- Owner: PSeitz
- License: mit
- Created: 2023-04-05T05:07:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-18T10:15:18.000Z (about 2 years ago)
- Last Synced: 2025-04-11T21:14:39.532Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# peakmem_alloc
An instrumenting middleware for global allocators in Rust, useful to find the peak memory consumed by a function.
## Example
```rust
use peakmem_alloc::*;
use std::alloc::System;
#[global_allocator]
static GLOBAL: &PeakMemAlloc = &INSTRUMENTED_SYSTEM;
#[test]
fn example_using_region() {
GLOBAL.reset_peak_memory(); // Note that other threads may impact the peak memory computation.
let _x: Vec = Vec::with_capacity(1_024);
println!(
"Peak Memory used by function : {:#?}",
GLOBAL.get_peak_memory()
);
}
```
## Custom allocators
You can wrap your existing allocator as follows:
```rust
use jemallocator::Jemalloc;
use peakmem_alloc::*;
#[global_allocator]
static GLOBAL: PeakMemAlloc = PeakMemAlloc::new(Jemalloc);
```