Crates.io | memoria |
lib.rs | memoria |
version | 0.1.0 |
source | src |
created_at | 2023-05-24 23:12:15.732588 |
updated_at | 2023-05-24 23:12:15.732588 |
description | Memory allocation tracker. A bad memory profiler for production. |
homepage | |
repository | https://github.com/untitaker/memoria |
max_upload_size | |
id | 873826 |
size | 30,077 |
A bad memory "profiler" for production.
UseCase
enum.Alloc::with_usecase
.use num_enum::{TryFromPrimitive, IntoPrimitive};
#[derive(TryFromPrimitive, IntoPrimitive, Default, Debug)]
#[repr(u32)]
enum MyUseCase {
#[default]
None,
LoadConfig,
ProcessData,
}
impl memoria::UseCase for MyUseCase {}
#[global_allocator]
static ALLOCATOR: memoria::Alloc<MyUseCase> = memoria::Alloc::new();
fn load_config() {
let _guard = ALLOCATOR.with_usecase(MyUseCase::LoadConfig);
println!("loading config...");
// consume some memory
let _temporary = vec![0u8; 256];
}
fn process_data() {
let _guard = ALLOCATOR.with_usecase(MyUseCase::ProcessData);
// consume some more memory
let _temporary = vec![0u8; 2048];
}
fn main() {
load_config();
process_data();
println!("memory usage stats:");
ALLOCATOR.with_recorder(|recorder| {
recorder.flush(
|usecase, stat| {
println!("{usecase:?}: {stat:?}");
},
|err, count| {
println!("{err:?}: {count}");
}
);
Ok(())
}).ok();
}
Licensed under the MIT license, see ./LICENSE
.