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//! ## AIX
30//!
31//! On AIX, we read `/proc/<pid>/psinfo` and extract the resident set size from the `psinfo_t` structure.
32
33#[cfg(target_os = "linux")]
34mod linux;
35
36#[cfg(target_os = "linux")]
37pub use linux::Querier;
38
39#[cfg(target_os = "macos")]
40mod darwin;
41
42#[cfg(target_os = "macos")]
43pub use darwin::Querier;
44
45#[cfg(target_os = "windows")]
46mod windows;
47
48#[cfg(target_os = "windows")]
49pub use windows::Querier;
50
51#[cfg(target_os = "aix")]
52mod aix;
53
54#[cfg(target_os = "aix")]
55pub use aix::Querier;
56
57#[cfg(all(
58 not(target_os = "linux"),
59 not(target_os = "macos"),
60 not(target_os = "windows"),
61 not(target_os = "aix")
62))]
63compile_error!("This crate only supports Linux, macOS, Windows, and AIX at the moment.");