saluki_common/resource_tracking/
mod.rs

1//! Process-level resource tracking: per-group memory allocation and CPU usage accounting.
2//!
3//! This module provides the primitives for attributing memory allocations and CPU time to
4//! user-defined "resource groups":
5//!
6//! - a global allocator wrapper ([`TrackingAllocator`]) that attributes every allocation to the
7//!   currently entered resource group,
8//! - a registry of resource groups ([`ResourceGroupRegistry`]) and per-group statistics
9//!   ([`ResourceStats`]),
10//! - a [`ResourceGroupToken`] that can be entered to scope allocations and CPU time to a group,
11//!   either directly (via a scope guard) or by wrapping a [`Future`](std::future::Future) with the
12//!   [`Track`] extension trait.
13//!
14//! # Memory usage
15//!
16//! For memory usage to be tracked, [`TrackingAllocator`] must be installed as the global allocator
17//! for the process. When installed, every allocation is attributed to the currently entered
18//! resource group, defaulting to a catch-all "root" group when no user-defined group is entered.
19//!
20//! # CPU usage
21//!
22//! CPU time is attributed to the currently entered resource group when that group is exited, based
23//! on the thread CPU time consumed while the group was entered. CPU usage tracking is only
24//! available on Linux; on other platforms it is a no-op.
25
26mod allocator;
27mod groups;
28mod stats;
29
30pub use self::allocator::TrackingAllocator;
31pub use self::groups::{ResourceGroupRegistry, ResourceGroupToken, ResourceTrackingGuard, Track, Tracked};
32pub use self::stats::{ResourceStats, ResourceStatsSnapshot};