process_memory/lib.rs
1//! Process memory querying.
2//!
3//! This crate provides a cross-platform way to query the RSS (resident set size) usage of a process.
4//!
5//! ## Linux
6//!
7//! On Linux, [procfs](https://docs.kernel.org/filesystems/proc.html) is used, and one of three files may be read,
8//! depending on their availability:
9//!
10//! - `/proc/self/smaps_rollup`: This file is a pre-aggregated version of `/proc/self/smaps`, and is the most efficient way
11//! to query RSS. (Available in Linux 4.14+)
12//! - `/proc/self/smaps`: This file contains detailed information about the memory mappings of the process, and can be
13//! aggregated to determine the resident set size. (Available in Linux 2.6.14+)
14//! - `/proc/self/statm`: This file contains lazily-updated memory statistics about the process, and is the least
15//! accurate, but is generally good enough for most use-cases. (Available in Linux 2.6+)
16//!
17//! ## macOS
18//!
19//! On macOS, we query the kernel directly for Mach task information.
20//!
21//! Available since Mac OS X 10.0 (Cheetah).
22//!
23//! ## Windows
24//!
25//! On Windows, we query the kernel directly for process memory counters.
26//!
27//! Available since Windows XP/Server 2003.
28
29#[cfg(target_os = "linux")]
30mod linux;
31
32#[cfg(target_os = "linux")]
33pub use linux::Querier;
34
35#[cfg(target_os = "macos")]
36mod darwin;
37
38#[cfg(target_os = "macos")]
39pub use darwin::Querier;
40
41#[cfg(target_os = "windows")]
42mod windows;
43
44#[cfg(target_os = "windows")]
45pub use windows::Querier;
46
47#[cfg(all(not(target_os = "linux"), not(target_os = "macos"), not(target_os = "windows")))]
48compile_error!("This crate only supports Linux, macOS, and Windows at the moment.");