pub struct ComponentRegistry { /* private fields */ }Expand description
A registry for components for tracking memory bounds and runtime memory usage.
This registry provides a unified interface for declaring the memory bounds of a “component”, as well as registering
that component for runtime memory usage tracking when using the tracking allocator implementation in memory-accounting.
§Components
Components are any logical grouping of memory usage within a program, and they can be arbitrarily nested.
For example, a data plane will generally have a topology that defines the components used to accept, process, and forward data. The topology itself could be considered a component, and each individual source, transform, and destination within it could be subcomponents of the topology.
Components are generally meant to be tied to something that has its own memory bounds and is somewhat “standalone”,
but this is not an absolute requirement and components can be nested more granularly for organizational/aesthetic
purposes. Again, for example, one might opt to create a component in their topology for each component type –
sources, transforms, and destinations – and then add the actual instances of those components as subcomponents to
each grouping, leading to a nested structure such as topology/sources/source1, topology/transforms/transform1,
and so on.
§Bounds
Every component is able to define memory bounds for itself and its subcomponents. A builder-style API is exposed to allow for ergonomically defining these bounds – both minimum and firm – for components, as well as extending the nestable aspect of the registry itself to the bounds builder, allowing for flexibility in where components are defined from and how they are nested.
§Allocation tracking
Every component is also able to be registered with its own allocation group when using the tracking allocator implementation. This is done on demand when the component’s token is requested, which avoids polluting the tracking allocator with components that are never actually used, such as those used for organizational/aesthetic purposes.
Implementations§
Source§impl ComponentRegistry
impl ComponentRegistry
Sourcepub fn root(&self) -> ComponentRegistryHandle
pub fn root(&self) -> ComponentRegistryHandle
Creates a handle to this registry.
The handle provides read-only access to root-level operations like creating API handlers and verifying bounds. It can be freely cloned and shared.
Sourcepub fn get_or_create<S>(&self, name: S) -> Self
pub fn get_or_create<S>(&self, name: S) -> Self
Gets a component by name, or creates it if it doesn’t exist.
The name provided can be given in a direct (component_name) or nested (path.to.component_name) form. If the
nested form is given, each component in the path will be created if it doesn’t exist.
Returns a ComponentRegistry scoped to the component.
Sourcepub fn bounds_builder(&mut self) -> MemoryBoundsBuilder<'_>
pub fn bounds_builder(&mut self) -> MemoryBoundsBuilder<'_>
Gets a bounds builder attached to the root component.
Sourcepub fn token(&mut self) -> AllocationGroupToken
pub fn token(&mut self) -> AllocationGroupToken
Gets the tracking token for the component scoped to this registry.
If the component is the root component (has no name), the root allocation token is returned. Otherwise, the component is registered (using its full name) if it hasn’t already been, and that token is returned.
Sourcepub fn as_bounds(&self) -> ComponentBounds
pub fn as_bounds(&self) -> ComponentBounds
Gets the total minimum required bytes for this component and all subcomponents.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ComponentRegistry
impl RefUnwindSafe for ComponentRegistry
impl Send for ComponentRegistry
impl Sync for ComponentRegistry
impl Unpin for ComponentRegistry
impl UnsafeUnpin for ComponentRegistry
impl UnwindSafe for ComponentRegistry
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_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
Tracked wrapper. Read more