#memory #performance #profiling


A cross-platform memory profiler for Rust

1 stable release

Uses new Rust 2021

1.0.0 Mar 20, 2022

#74 in Profiling

Download history 8/week @ 2022-04-26 9/week @ 2022-05-03 16/week @ 2022-05-10 5/week @ 2022-05-17 6/week @ 2022-05-24 13/week @ 2022-05-31 4/week @ 2022-06-07 46/week @ 2022-06-14 301/week @ 2022-06-21 523/week @ 2022-06-28 197/week @ 2022-07-05 19/week @ 2022-07-12 17/week @ 2022-07-19 32/week @ 2022-07-26 30/week @ 2022-08-02 96/week @ 2022-08-09

176 downloads per month


161 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.


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.