MCPcopy Index your code
hub / github.com/Arc-blroth/memory-stats

github.com/Arc-blroth/memory-stats @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
11 symbols 16 edges 7 files 2 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Usage

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

[dependencies]
memory-stats = "1.2.0"

Optional Features

serde: Enables serialization and deserialization of the MemoryStats struct.

Example

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 :(");
    }
}

Caveats

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.

License

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.

Core symbols most depended-on inside this repo

scan_int
called by 4
src/linux.rs
memory_stats
called by 3
src/lib.rs
load_page_size
called by 3
src/page_size.rs
memory_stats
called by 0
src/linux.rs
memory_stats
called by 0
src/darwin.rs
memory_stats
called by 0
src/freebsd.rs
drop
called by 0
src/freebsd.rs
memory_stats
called by 0
src/windows.rs

Shape

Function 8
Class 2
Method 1

Languages

Rust100%

Modules by API surface

src/freebsd.rs3 symbols
src/linux.rs2 symbols
src/lib.rs2 symbols
tests/allocate_4mb_of_memory.rs1 symbols
src/windows.rs1 symbols
src/page_size.rs1 symbols
src/darwin.rs1 symbols

For agents

$ claude mcp add memory-stats \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact