ComponentRegistry

Struct ComponentRegistry 

Source
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

Source

pub fn get_or_create<S>(&self, name: S) -> Self
where S: AsRef<str>,

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.

Source

pub fn bounds_builder(&mut self) -> MemoryBoundsBuilder<'_>

Gets a bounds builder attached to the root component.

Source

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.

Source

pub fn verify_bounds( &self, initial_grant: MemoryGrant, ) -> Result<VerifiedBounds, VerifierError>

Validates that all components are able to respect the calculated effective limit.

If validation succeeds, VerifiedBounds is returned, which provides information about the effective limit that can be used for allocating memory.

§Errors

A number of invalid conditions are checked and will cause an error to be returned:

  • when a component has invalid bounds (e.g. minimum required bytes higher than firm limit)
  • when the combined total of the firm limit for all components exceeds the effective limit
Source

pub fn api_handler(&self) -> MemoryAPIHandler

Gets an API handler for reporting the memory bounds and usage of all components.

This handler exposes routes for querying the memory bounds and usage of all registered components. See MemoryAPIHandler for more information about routes and responses.

Source

pub fn as_bounds(&self) -> ComponentBounds

Gets the total minimum required bytes for this component and all subcomponents.

Trait Implementations§

Source§

impl Default for ComponentRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Track for T

Source§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
Source§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more