Skip to main content

ObservationRing

Struct ObservationRing 

Source
pub struct ObservationRing { /* private fields */ }
Expand description

SPSC ring used by one producer thread (push) and one consumer (sidecar).

Head is written by the consumer, read by the producer. Tail is written by the producer, read by the consumer.

Implementations§

Source§

impl ObservationRing

Source

pub const fn new() -> Self

Source

pub fn push(&self, obs: Observation) -> bool

Push one observation. Returns true on success, false if the ring was full (observation dropped).

If obs.producer_thread_id is 0 (the default), the current thread’s id is stamped in automatically via thread_id. Call sites that prefer explicit attribution can pre-fill the field; the auto-stamp keeps the per-primitive push sites mechanical.

Source

pub fn push_op(&self, op_kind: u16, flags: u16) -> bool

Push an observation described by just its op kind and flags - the shape essentially every primitive uses. Passing scalars (not a built Observation) is what keeps the win whole: the struct is constructed only inside the #[cold] body, so the caller’s hot path is a lone relaxed load + predicted branch and nothing materializes on it. This is the preferred per-op observation entry point; reserve push for the rare site that pre-fills latency_ticks / instance_id.

Source

pub fn pop(&self) -> Option<Observation>

Consumer-side pop. Single-consumer; caller must serialize.

Source

pub fn arm(&self)

Arm the ring so producers begin pushing observations. Called once when a consumer (the sidecar) registers the owning instance. This lazily allocates the ~96 KiB observation buffer (zero-filled, i.e. all Observation::ZERO) and publishes it before setting armed, so a raw create() handle that never arms pays nothing - neither the per-push work nor the buffer allocation. Until armed, push is a single relaxed load + return. Idempotent; the buffer is allocated at most once even under racing callers.

Source

pub fn is_armed(&self) -> bool

True once a consumer has armed the ring.

Trait Implementations§

Source§

impl Default for ObservationRing

Source§

fn default() -> Self

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

impl Drop for ObservationRing

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Sync for ObservationRing

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, 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, 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.