PoolStats

Struct PoolStats 

Source
pub struct PoolStats {
    pub capacity: usize,
    pub available: usize,
    pub in_use: usize,
    pub buffer_size: usize,
    pub total_allocations: u64,
    pub failed_allocations: u64,
    pub utilization: f64,
    pub total_buffers: usize,
    pub available_buffers: usize,
    pub in_use_buffers: usize,
}
Expand description

Statistics about buffer pool usage.

Provides insights into pool performance and utilization patterns. All statistics are captured at a specific point in time and may become stale as the pool state changes.

§Examples

use safer_ring::pool::BufferPool;

let pool = BufferPool::new(10, 4096);
let stats = pool.stats();

println!("Pool utilization: {:.1}%", stats.utilization_percent());
println!("Success rate: {:.1}%", stats.success_rate_percent());

Fields§

§capacity: usize

Total capacity of the pool

§available: usize

Number of buffers currently available

§in_use: usize

Number of buffers currently in use

§buffer_size: usize

Size of each buffer in bytes

§total_allocations: u64

Total successful allocations since pool creation

§failed_allocations: u64

Total failed allocation attempts since pool creation

§utilization: f64

Current utilization as a ratio (0.0 to 1.0)

§total_buffers: usize

Total number of buffers in the pool (same as capacity)

§available_buffers: usize

Number of buffers currently available (same as available)

§in_use_buffers: usize

Number of buffers currently in use (same as in_use)

Implementations§

Source§

impl PoolStats

Source

pub fn utilization_percent(&self) -> f64

Get utilization as a percentage (0.0 to 100.0).

§Examples
let stats = PoolStats {
    capacity: 10,
    available: 3,
    in_use: 7,
    buffer_size: 4096,
    total_allocations: 100,
    failed_allocations: 5,
    utilization: 0.7,
    total_buffers: 10,
    available_buffers: 3,
    in_use_buffers: 7,
};
assert_eq!(stats.utilization_percent(), 70.0);
Source

pub fn success_rate_percent(&self) -> f64

Get the success rate of allocations as a percentage (0.0 to 100.0).

Returns 100.0 if no allocation attempts have been made.

§Examples
let stats = PoolStats {
    capacity: 10,
    available: 5,
    in_use: 5,
    buffer_size: 4096,
    total_allocations: 95,
    failed_allocations: 5,
    utilization: 0.5,
    total_buffers: 10,
    available_buffers: 5,
    in_use_buffers: 5,
};
assert_eq!(stats.success_rate_percent(), 95.0);
Source

pub fn total_memory_bytes(&self) -> usize

Get the total memory allocated by the pool in bytes.

§Examples
let stats = PoolStats {
    capacity: 10,
    buffer_size: 4096,
    // ... other fields
};
assert_eq!(stats.total_memory_bytes(), 40960); // 10 * 4096
Source

pub fn memory_in_use_bytes(&self) -> usize

Get the memory currently in use in bytes.

Source

pub fn is_under_pressure(&self) -> bool

Check if the pool is under high pressure (utilization > 80%).

This can be used to trigger alerts or scaling decisions.

§Examples
let high_pressure = PoolStats {
    utilization: 0.85, // 85% utilization
};
assert!(high_pressure.is_under_pressure());

let normal_pressure = PoolStats {
    utilization: 0.60, // 60% utilization
};
assert!(!normal_pressure.is_under_pressure());
Source

pub fn has_allocation_failures(&self) -> bool

Check if the pool has experienced allocation failures.

Trait Implementations§

Source§

impl Clone for PoolStats

Source§

fn clone(&self) -> PoolStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoolStats

Source§

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

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

impl PartialEq for PoolStats

Source§

fn eq(&self, other: &PoolStats) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PoolStats

Source§

impl StructuralPartialEq for PoolStats

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.