pub fn format_memory(bytes: u64) -> String {
const KB: u64 = 1_024;
const MB: u64 = 1_024 * KB;
const GB: u64 = 1_024 * MB;
if bytes >= GB {
format!("{:.1} GB", bytes as f64 / GB as f64)
} else if bytes >= MB {
format!("{:.1} MB", bytes as f64 / MB as f64)
} else {
format!("{:.1} KB", bytes as f64 / KB as f64)
}
}
pub fn format_duration_compact(seconds: u64) -> String {
let days = seconds / 86_400;
let hours = (seconds % 86_400) / 3_600;
let mins = (seconds % 3_600) / 60;
let secs = seconds % 60;
if days > 0 || hours > 0 {
format!("{}d {}h {}m", days, hours, mins)
} else {
format!("{}m {}s", mins, secs)
}
}
pub fn format_duration_full(seconds: u64) -> String {
let d = seconds / 86_400;
let h = (seconds % 86_400) / 3_600;
let m = (seconds % 3_600) / 60;
let s = seconds % 60;
format!("{}d {}h {}m {}s", d, h, m, s)
}