Expand description
Process-level resource tracking: per-group memory allocation and CPU usage accounting.
This module provides the primitives for attributing memory allocations and CPU time to user-defined “resource groups”:
- a global allocator wrapper (
TrackingAllocator) that attributes every allocation to the currently entered resource group, - a registry of resource groups (
ResourceGroupRegistry) and per-group statistics (ResourceStats), - a
ResourceGroupTokenthat can be entered to scope allocations and CPU time to a group, either directly (via a scope guard) or by wrapping aFuturewith theTrackextension trait.
§Memory usage
For memory usage to be tracked, TrackingAllocator must be installed as the global allocator
for the process. When installed, every allocation is attributed to the currently entered
resource group, defaulting to a catch-all “root” group when no user-defined group is entered.
§CPU usage
CPU time is attributed to the currently entered resource group when that group is exited, based on the thread CPU time consumed while the group was entered. CPU usage tracking is only available on Linux; on other platforms it is a no-op.
Structs§
- Resource
Group Registry - A registry of resource groups and the statistics for each of them.
- Resource
Group Token - A token associated with a specific resource group.
- Resource
Stats - Statistics for an resource group.
- Resource
Stats Snapshot - Snapshot of allocation statistics for a group.
- Resource
Tracking Guard - A guard representing an resource group which has been entered.
- Tracked
- An object wrapper that tracks allocations and attributes them to a specific group.
- Tracking
Allocator - A global allocator that tracks allocations on a per-group basis.