free.rs
1 use alloc::string::String as AllocString; 2 use core::fmt::Write; 3 4 pub fn run() -> AllocString { 5 let mut out = AllocString::new(); 6 let used = esp_alloc::HEAP.used(); 7 let free = esp_alloc::HEAP.free(); 8 let total = used + free; 9 let pct = if total > 0 { (used * 100) / total } else { 0 }; 10 11 let _ = write!(out, "\r\n"); 12 let _ = write!( 13 out, 14 " \x1b[33m{:<12}\x1b[0m {:<12} {:<12} {:<12}\r\n", 15 "", "total", "used", "free" 16 ); 17 let _ = write!( 18 out, 19 " \x1b[33m{:<12}\x1b[0m {:<12.1} {:<12.1} {:<12.1}\r\n", 20 "Heap (KiB)", 21 total as f32 / 1024.0, 22 used as f32 / 1024.0, 23 free as f32 / 1024.0, 24 ); 25 let _ = write!(out, " \x1b[33m{:<12}\x1b[0m {}%\r\n", "Usage", pct); 26 let _ = write!(out, "\r\n"); 27 out 28 }