use rand::{RngExt, rng};
#[derive(Clone)]
pub struct GpuMetrics {
pub uuid: String,
pub utilization: f32,
pub memory_used_bytes: u64,
pub memory_total_bytes: u64,
pub temperature_celsius: u32,
pub power_consumption_watts: f32,
pub frequency_mhz: u32,
pub ane_utilization_watts: f32, #[allow(dead_code)]
pub thermal_pressure_level: Option<String>, }
impl GpuMetrics {
pub fn update(&mut self, platform: &super::PlatformType) {
let mut rng = rng();
match platform {
super::PlatformType::Furiosa => {
if self.utilization == 0.0 {
if rng.random_bool(0.1) {
self.utilization = rng.random_range(10.0..90.0);
}
} else {
if rng.random_bool(0.05) {
self.utilization = 0.0;
} else {
let utilization_delta = rng.random_range(-5.0..5.0);
self.utilization = (self.utilization + utilization_delta).clamp(1.0, 100.0);
}
}
}
_ => {
let utilization_delta = rng.random_range(-5.0..5.0);
self.utilization = (self.utilization + utilization_delta).clamp(0.0, 100.0);
}
}
match platform {
super::PlatformType::Furiosa => {
if self.utilization == 0.0 {
self.memory_used_bytes = 0;
} else {
let memory_delta =
rng.random_range(-(1024 * 1024 * 1024)..(1024 * 1024 * 1024));
self.memory_used_bytes = self
.memory_used_bytes
.saturating_add_signed(memory_delta)
.clamp(1024 * 1024 * 1024, self.memory_total_bytes); }
}
_ => {
let memory_delta =
rng.random_range(-(3 * 1024 * 1024 * 1024)..(3 * 1024 * 1024 * 1024));
self.memory_used_bytes = self
.memory_used_bytes
.saturating_add_signed(memory_delta)
.min(self.memory_total_bytes);
}
}
let memory_usage_percent =
(self.memory_used_bytes as f32 / self.memory_total_bytes as f32) * 100.0;
let base_power = rng.random_range(80.0..120.0);
let util_power_contribution = self.utilization * rng.random_range(4.0..6.0);
let memory_power_contribution = memory_usage_percent * rng.random_range(1.0..2.0);
let gpu_bias = rng.random_range(-30.0..30.0);
let random_variation = rng.random_range(-15.0..15.0);
let max_power = match platform {
super::PlatformType::Furiosa => 180.0, _ => 700.0,
};
self.power_consumption_watts = match platform {
super::PlatformType::Furiosa => {
40.0 + rng.random_range(-1.0..2.0) + (self.utilization * 0.01 * 140.0)
}
_ => (base_power
+ util_power_contribution
+ memory_power_contribution
+ gpu_bias
+ random_variation)
.clamp(80.0, max_power),
};
self.temperature_celsius = match platform {
super::PlatformType::Furiosa => {
(35.0 + rng.random_range(0.0..4.0) + (self.utilization * 0.01 * 20.0))
.clamp(35.0, 70.0) as u32
}
_ => {
let base_temp = 45.0;
let util_temp_contribution = self.utilization * 0.25;
let power_temp_contribution = (self.power_consumption_watts - 200.0) * 0.05;
let temp_variation = rng.random_range(-3.0..3.0);
(base_temp + util_temp_contribution + power_temp_contribution + temp_variation)
.clamp(35.0, 85.0) as u32
}
};
self.frequency_mhz = match platform {
super::PlatformType::Furiosa => {
500
}
_ => {
let base_freq = 1200.0;
let util_freq_contribution = self.utilization * 6.0; let freq_variation = rng.random_range(-100.0..100.0);
(base_freq + util_freq_contribution + freq_variation).clamp(1000.0, 1980.0) as u32
}
};
if self.ane_utilization_watts > 0.0 {
let ane_delta = rng.random_range(-0.3..0.3);
self.ane_utilization_watts = (self.ane_utilization_watts + ane_delta).clamp(0.0, 3.0);
}
}
}
pub fn generate_uuid() -> String {
generate_uuid_with_rng(&mut rng())
}
pub fn generate_uuid_with_rng<R: rand::RngExt>(rng: &mut R) -> String {
let bytes: [u8; 16] = rng.random();
format!(
"{:02X}{:02X}{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
bytes[0],
bytes[1],
bytes[2],
bytes[3],
bytes[4],
bytes[5],
bytes[6],
bytes[7],
bytes[8],
bytes[9],
bytes[10],
bytes[11],
bytes[12],
bytes[13],
bytes[14],
bytes[15]
)
}