#[derive(Debug, Clone, Copy, PartialEq)]
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,
}
impl PoolStats {
pub fn utilization_percent(&self) -> f64 {
self.utilization * 100.0
}
pub fn success_rate_percent(&self) -> f64 {
let total_attempts = self.total_allocations + self.failed_allocations;
if total_attempts == 0 {
100.0 } else {
(self.total_allocations as f64 / total_attempts as f64) * 100.0
}
}
pub fn total_memory_bytes(&self) -> usize {
self.capacity * self.buffer_size
}
pub fn memory_in_use_bytes(&self) -> usize {
self.in_use * self.buffer_size
}
pub fn is_under_pressure(&self) -> bool {
self.utilization > 0.8
}
pub fn has_allocation_failures(&self) -> bool {
self.failed_allocations > 0
}
}