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
impl RingMetrics
pub fn new() -> Self
Sourcepub fn record_cas_retry(&self)
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.
Sourcepub fn snapshot(&self) -> RingMetricsSnapshot
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§
Auto Trait Implementations§
impl !Freeze for RingMetrics
impl RefUnwindSafe for RingMetrics
impl Send for RingMetrics
impl Sync for RingMetrics
impl Unpin for RingMetrics
impl UnsafeUnpin for RingMetrics
impl UnwindSafe for RingMetrics
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
Mutably borrows from an owned value. Read more