use std::collections::HashMap;
#[derive(Debug, Clone, Default)]
pub struct DistributedStats {
pub operations_count: usize,
pub bytes_transferred: usize,
pub comm_time_ms: u64,
pub compute_time_ms: u64,
pub comm_events: usize,
pub load_balance_efficiency: f64,
pub memory_usage_per_node: HashMap<usize, usize>,
}
impl DistributedStats {
pub fn new() -> Self {
Self::default()
}
pub fn record_communication(&mut self, bytes: usize, time_ms: u64) {
self.bytes_transferred += bytes;
self.comm_time_ms += time_ms;
self.comm_events += 1;
}
pub fn record_computation(&mut self, time_ms: u64) {
self.compute_time_ms += time_ms;
self.operations_count += 1;
}
pub fn update_memory_usage(&mut self, node_rank: usize, bytes: usize) {
self.memory_usage_per_node.insert(node_rank, bytes);
}
pub fn comm_compute_ratio(&self) -> f64 {
if self.compute_time_ms == 0 {
return 0.0;
}
self.comm_time_ms as f64 / self.compute_time_ms as f64
}
pub fn bandwidth_utilization(&self) -> f64 {
if self.comm_time_ms == 0 {
return 0.0;
}
self.bytes_transferred as f64 / self.comm_time_ms as f64
}
}