Skip to main content

RingMetrics

Struct RingMetrics 

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

Shared counter set. Hold an Arc<RingMetrics> across producer + consumer so the snapshot reflects both sides.

Implementations§

Source§

impl RingMetrics

Source

pub fn new() -> Self

Source

pub fn record_cas_retry(&self)

Bump the CAS-retry counter. Called by the mpmc-disruptor path; the SPSC paths never retry under the wait-free invariant.

Source

pub fn snapshot(&self) -> RingMetricsSnapshot

Capture a point-in-time snapshot of every counter. Consistent enough for monitoring; not a transactional read across all six values.

Examples found in repository?
examples/sample_app.rs (line 300)
273fn instrumented_handoff() {
274    use subms_spsc_ring_buffer::InstrumentedSpsc;
275
276    println!("\n== metrics: instrumented feed handoff ==");
277    let (tx, rx) = SpscRingBuffer::with_capacity::<Tick>(4);
278    let (mut tx, mut rx, metrics) = InstrumentedSpsc::wrap(tx, rx);
279
280    // Fill to capacity, one overflow drop, then drain plus one empty poll.
281    for seq in 0..4u64 {
282        tx.try_push(Tick {
283            seq,
284            price_cents: 60_000,
285        })
286        .unwrap();
287    }
288    assert!(
289        tx.try_push(Tick {
290            seq: 99,
291            price_cents: 0
292        })
293        .is_err()
294    );
295    for _ in 0..4 {
296        rx.try_pop().unwrap();
297    }
298    assert!(rx.try_pop().is_none());
299
300    let snap = metrics.snapshot();
301    println!(
302        "  enqueued {} (dropped {}), dequeued {} (empty {}), peak depth {}",
303        snap.enqueue_success,
304        snap.enqueue_fail,
305        snap.dequeue_success,
306        snap.dequeue_fail,
307        snap.max_depth_observed
308    );
309    assert_eq!(snap.enqueue_success, 4);
310    assert_eq!(snap.enqueue_fail, 1);
311    assert_eq!(snap.dequeue_success, 4);
312    assert_eq!(snap.dequeue_fail, 1);
313    assert_eq!(snap.max_depth_observed, 4);
314}

Trait Implementations§

Source§

impl Default for RingMetrics

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