4 releases (2 breaking)
new 0.3.0 | Mar 26, 2025 |
---|---|
0.2.1 | Mar 26, 2025 |
0.2.0 | Mar 26, 2025 |
0.1.1 | Mar 26, 2025 |
#10 in #memory-profiling
7KB
75 lines
memtrack
A procedural macro for tracking memory usage of Rust functions.
Overview
memtrack
provides a simple way to monitor memory usage of functions in Rust programs. It works by wrapping functions with memory tracking code that measures the resident set size (RSS) before and after function execution.
Installation
Add this to your Cargo.toml
:
[dependencies]
memtrack = "0.3.0"
Usage
Add the #[track_mem]
attribute to the functions you want to track:
use memtrack::track_mem;
#[track_mem]
fn allocate_memory() {
let data: Vec<u8> = vec![0; 1_000_000];
println!("Allocated {} bytes", data.len());
}
This will print the memory usage before and after the function execution.
Example
See the examples/demo.rs file for a more comprehensive example.
cargo run --example demo
Dependencies
~0.8–1.4MB
~29K SLoC