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: usizeTotal capacity of the pool
available: usizeNumber of buffers currently available
in_use: usizeNumber of buffers currently in use
buffer_size: usizeSize of each buffer in bytes
total_allocations: u64Total successful allocations since pool creation
failed_allocations: u64Total failed allocation attempts since pool creation
utilization: f64Current utilization as a ratio (0.0 to 1.0)
total_buffers: usizeTotal number of buffers in the pool (same as capacity)
available_buffers: usizeNumber of buffers currently available (same as available)
in_use_buffers: usizeNumber of buffers currently in use (same as in_use)
Implementations§
Source§impl PoolStats
impl PoolStats
Sourcepub fn utilization_percent(&self) -> f64
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);Sourcepub fn success_rate_percent(&self) -> f64
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);Sourcepub fn total_memory_bytes(&self) -> usize
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 * 4096Sourcepub fn memory_in_use_bytes(&self) -> usize
pub fn memory_in_use_bytes(&self) -> usize
Get the memory currently in use in bytes.
Sourcepub fn is_under_pressure(&self) -> bool
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());Sourcepub fn has_allocation_failures(&self) -> bool
pub fn has_allocation_failures(&self) -> bool
Check if the pool has experienced allocation failures.