Struct metrics_util::Registry[][src]

pub struct Registry<K, H, G> where
    K: Eq + Hashable + Clone + 'static,
    H: 'static, 
{ /* fields omitted */ }
Expand description

A high-performance metric registry.

Registry provides the ability to maintain a central listing of metrics mapped by a given key.

In many cases, K will be a composite key, where the fundamental Key type from metrics is present, and differentiation is provided by storing the metric type alongside.

Metrics themselves are represented opaquely behind H. In most cases, this would be a thread-safe handle to the underlying metrics storage that the owner of the registry can use to update the actual metric value(s) as needed. Handle, from this crate, is a solid default choice.

As well, handles have an associated generation counter which is incremented any time an entry is operated on. This generation is returned with the handle when querying the registry, and can be used in order to delete a handle from the registry, allowing callers to prune old/stale handles over time.

Registry is optimized for reads.

Implementations

impl<K, H, G> Registry<K, H, G> where
    K: Eq + Hashable + Clone + 'static,
    H: 'static, 
[src]

pub fn untracked() -> Registry<K, H, NotTracked<H>>[src]

Creates a new Registry without generation semantics.

pub fn tracked() -> Registry<K, H, Tracked<H>>[src]

Creates a new Registry with generation semantics.

In some use cases, there is a requirement to understand what “generation” a metric is, for the purposes of understanding if a given metric has changed between two points in time.

This registry wraps metrics with a generation counter, which is incremented every time a metric is operated on. When queried for a list of metrics, they’ll be provided with their current generation.

impl<K, H, G> Registry<K, H, G> where
    K: Eq + Hashable + Clone + 'static,
    H: 'static,
    G: Generational<H>, 
[src]

pub fn clear(&self)[src]

Removes all metrics from the registry.

This operation is eventually consistent: metrics will be removed piecemeal, and this method does not ensure that callers will see the registry as entirely empty at any given point.

pub fn op<I, O, V>(&self, kind: MetricKind, key: &K, op: O, init: I) -> V where
    I: FnOnce() -> H,
    O: FnOnce(&H) -> V, 
[src]

Perform an operation on a given key.

The op function will be called for the handle under the given key.

If the key is not already mapped, the init function will be called, and the resulting handle will be stored in the registry.

pub fn delete(&self, kind: MetricKind, key: &K) -> bool[src]

Deletes a handle from the registry.

Returns true if the handle existed and was removed, false otherwise.

pub fn delete_with_gen(
    &self,
    kind: MetricKind,
    key: &K,
    generation: Generation
) -> bool
[src]

Deletes a handle from the registry.

The generation of a given key is passed along when querying the registry via get_handles. If the generation given here does not match the current generation, then the handle will not be removed.

Returns true if the handle existed and was removed, false otherwise.

pub fn visit<F>(&self, collect: F) where
    F: FnMut(MetricKind, (&K, &G)), 
[src]

Visits every handle stored in this registry.

The given function will be passed the metric kind as well as the key and handle references, which are wrapped in Generational-implementing holders.

This operation does not lock the entire registry, but proceeds directly through the “subshards” that are kept internally. As a result, all subshards will be visited, but a metric that existed at the exact moment that visit was called may not actually be observed if it is deleted before that subshard is reached. Likewise, a metric that is added after the call to visit, but before visit finishes, may also not be observed.

pub fn get_handles(&self) -> HashMap<(MetricKind, K), (Generation, H)> where
    H: Clone
[src]

Gets a map of all present handles, mapped by key.

Handles must implement Clone. This map is a point-in-time snapshot of the registry.

Trait Implementations

impl<K: Debug, H: Debug, G: Debug> Debug for Registry<K, H, G> where
    K: Eq + Hashable + Clone + 'static,
    H: 'static, 
[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<K, H, G> Default for Registry<K, H, G> where
    K: Eq + Hashable + Clone + 'static,
    H: 'static,
    G: Generational<H>, 
[src]

fn default() -> Self[src]

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

Auto Trait Implementations

impl<K, H, G> !RefUnwindSafe for Registry<K, H, G>

impl<K, H, G> Send for Registry<K, H, G> where
    G: Send,
    H: Send,
    K: Send

impl<K, H, G> Sync for Registry<K, H, G> where
    G: Send + Sync,
    H: Sync,
    K: Send + Sync

impl<K, H, G> Unpin for Registry<K, H, G> where
    G: Unpin,
    H: Unpin,
    K: Unpin

impl<K, H, G> UnwindSafe for Registry<K, H, G> where
    G: UnwindSafe,
    H: UnwindSafe,
    K: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T[src]

pub const ALIGN: usize[src]

The alignment of pointer.

type Init = T

The type for initializers.

pub unsafe fn init(init: <T as Pointable>::Init) -> usize[src]

Initializes a with the given initializer. Read more

pub unsafe fn deref<'a>(ptr: usize) -> &'a T[src]

Dereferences the given pointer. Read more

pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T[src]

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)[src]

Drops the object pointed to by the given pointer. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.