Skip to main content

CountersFile

Struct CountersFile 

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

View over a counters file region. Owns no memory; constructed from a pointer into a shared-memory mapping or a stack buffer (test only).

Implementations§

Source§

impl CountersFile

Source

pub unsafe fn init(ptr: NonNull<u8>) -> Self

Initialise a freshly-zeroed reserved region as a counters file. Must be called exactly once per segment, by whichever process creates the segment.

§Safety

ptr must point to at least COUNTERS_FILE_RESERVED_BYTES of writable memory that outlives the returned view, and that memory must be zero-initialised before this call.

Source

pub unsafe fn attach(ptr: NonNull<u8>) -> Result<Self, AttachError>

Attach to an existing counters file region. Validates the magic and version.

§Safety

ptr must point to at least COUNTERS_FILE_RESERVED_BYTES of readable memory whose lifetime contains the returned view. The memory must already have been initialised by a writer.

Source

pub fn header(&self) -> &CountersHeader

Header reference.

Source

pub fn register( &self, id: u32, flags: u32, label: &str, ) -> Option<CounterHandle>

Reserve a new slot, populate id, flags, and label, and return a writer handle. Returns None when the slot capacity is exhausted.

Source

pub fn boxed() -> OwnedCountersFile

Allocate a fresh, zero-initialised counters file on the heap and initialise it. Returns an OwnedCountersFile that owns the backing buffer alongside the CountersFile view.

Safe alternative to CountersFile::init for single-process use cases (tests, in-process metrics) where the counters file does not need to be shared across processes via SHM or mmap.

The returned OwnedCountersFile derefs to &CountersFile, so all register / snapshot / etc. operations work directly:

use disruptor_mp::observability::CountersFile;
let file = CountersFile::boxed();
let handle = file.register(1, 0, "events_published").unwrap();
handle.inc();
assert_eq!(file.snapshot()[0].value, 1);
Source

pub fn snapshot(&self) -> Vec<CounterSnapshot>

Snapshot all in-use slots — (id, flags, value, label) tuples. Intended for external readers and tests.

Trait Implementations§

Source§

impl Debug for CountersFile

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Send for CountersFile

Source§

impl Sync for CountersFile

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V