#memory #performance


A cross-platform memory profiler for Rust

2 stable releases

1.1.0 Dec 26, 2022
1.0.0 Mar 20, 2022

#30 in Profiling

Download history 6865/week @ 2023-08-15 8950/week @ 2023-08-22 11179/week @ 2023-08-29 7823/week @ 2023-09-05 7271/week @ 2023-09-12 8269/week @ 2023-09-19 9104/week @ 2023-09-26 9608/week @ 2023-10-03 9248/week @ 2023-10-10 10782/week @ 2023-10-17 11270/week @ 2023-10-24 11808/week @ 2023-10-31 11109/week @ 2023-11-07 10706/week @ 2023-11-14 10124/week @ 2023-11-21 8622/week @ 2023-11-28

42,567 downloads per month
Used in 23 crates (13 directly)


173 lines

Memory Stats

Crates.io License Build Status Dragon Powered

A cross-platform memory profiler for Rust, supporting Windows, Linux, and MacOS. This crate provides two metrics:

  • "Physical" Memory, which corresponds to the Resident Set Size on Linux and MacOS and the Working Set on Windows.
  • "Virtual" Memory, which corresponds to the Virtual Size on Linux and MacOS and the Pagefile Usage on Windows.


Add memory-stats as a dependency to your Cargo.toml:

memory-stats = "1.0.0"

Optional Features

serde: Enables serialization and deserialization of the MemoryStats struct.


Here's an example that prints out the current memory usage:

use memory_stats::memory_stats;

fn main() {
    if let Some(usage) = memory_stats() {
        println!("Current physical memory usage: {}", usage.physical_mem);
        println!("Current virtual memory usage: {}", usage.virtual_mem);
    } else {
        println!("Couldn't get the current memory usage :(");


Getting accurate memory usage on Linux is fairly expensive and not always possible. This crate always attempts to use the statistics from /proc/self/smaps if avaliable. However, since support for /proc/self/smaps might not be compiled in on all kernels, this crate will also use the faster but less accurate statistics from /proc/self/statm as a fallback.

If speed is needed over accuracy, the always_use_statm feature can be enabled to always use the /proc/self/statm statistics.


This crate is dual-licensed under either:

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.