pub struct ResourceGroupRegistry { /* private fields */ }Expand description
A registry of resource groups and the statistics for each of them.
Resource groups are user-defined groups which can then be associated with memory and CPU usage in distinct code regions. This mechanism allows for granular resource accounting at the level which makes sense to the application, such as per-thread, per-async task, and so on.
§Token guard
When an resource group is registered, an ResourceGroupToken is returned. This token can be used to “enter” the
group, which causes memory and CPU usage on the current thread to be attributed to that group. Entering the group
returns a drop guard that restores the previously entered group when dropped.
This allows for arbitrarily nested resource groups.
Additionally, Tracked can be used to wrap a Future, attaching it to a specific resource group token. This
causes the future to track all memory and CPU usage during polls such that the usage is properly attributed to the
resource group.
§Resources tracked
§Memory usage
In order for memory usage to be tracked, TrackingAllocator must be installed
as the global allocator for the process.
§CPU usage
CPU usage is automatically tracked if platform support is detected.
Currently, only Linux is supported for CPU usage tracking.
Implementations§
Source§impl ResourceGroupRegistry
impl ResourceGroupRegistry
Sourcepub fn allocator_installed() -> bool
pub fn allocator_installed() -> bool
Returns true if TrackingAllocator is installed as the global allocator.
Sourcepub fn register_resource_group<S>(&self, name: S) -> ResourceGroupToken
pub fn register_resource_group<S>(&self, name: S) -> ResourceGroupToken
Registers a new resource group with the given name.
Returns an ResourceGroupToken that can be used to attribute CPU and memory usage to the
newly created resource group.
Sourcepub fn visit_resource_groups<F>(&self, f: F)
pub fn visit_resource_groups<F>(&self, f: F)
Visits all resource groups in the registry and calls the given closure with their names and statistics.
Auto Trait Implementations§
impl !Freeze for ResourceGroupRegistry
impl RefUnwindSafe for ResourceGroupRegistry
impl Send for ResourceGroupRegistry
impl Sync for ResourceGroupRegistry
impl Unpin for ResourceGroupRegistry
impl UnsafeUnpin for ResourceGroupRegistry
impl UnwindSafe for ResourceGroupRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self> ⓘ
Tracked wrapper. Read more