#[derive(Debug, Clone, Copy, Default)]
pub struct GpuMemoryMetrics {
pub total: u64,
pub used: u64,
pub free: u64,
pub allocations: u64,
}
impl GpuMemoryMetrics {
#[must_use]
pub const fn new(total: u64, used: u64, free: u64) -> Self {
Self { total, used, free, allocations: 0 }
}
#[must_use]
pub fn usage_percent(&self) -> f64 {
if self.total == 0 {
0.0
} else {
(self.used as f64 / self.total as f64) * 100.0
}
}
#[must_use]
pub fn used_mb(&self) -> u64 {
self.used / (1024 * 1024)
}
#[must_use]
pub fn free_mb(&self) -> u64 {
self.free / (1024 * 1024)
}
}