bfree 0.1.13

bfree - memory stats for humans
Documentation
use crate::core::memory_stats::MemoryStats;
use crate::render::format::fmt_short;

/// Extended, multi-line output with an extra cache breakdown section.
pub fn render(s: &MemoryStats) -> String {
    format!(
        "\
Memory
  Total:        {total}
  Used:         {used} ({used_pct:.0}%)
  Cache:        {cache} ({cache_pct:.0}%)
  Available:    {avail} ({avail_pct:.0}%)

Swap
  Total:        {swap_total}
  Used:         {swap_used} ({swap_pct:.0}%)
  Free:         {swap_free} ({swap_free_pct:.0}%)

Cache Breakdown
  Cached:        {cached}
  SReclaimable:  {sreclaimable}
  Shmem:         {shmem}",
        total = fmt_short(s.mem_total),
        used = fmt_short(s.mem_used()),
        used_pct = s.mem_used_percent(),
        cache = fmt_short(s.mem_cache_effective()),
        cache_pct = s.mem_cache_percent(),
        avail = fmt_short(s.mem_available),
        avail_pct = s.mem_available_percent(),
        swap_total = fmt_short(s.swap_total),
        swap_used = fmt_short(s.swap_used()),
        swap_pct = s.swap_used_percent(),
        swap_free = fmt_short(s.swap_free),
        swap_free_pct = if s.swap_total == 0 {
            0.0
        } else {
            (s.swap_free as f64) * 100.0 / (s.swap_total as f64)
        },
        cached = fmt_short(s.mem_cached),
        sreclaimable = fmt_short(s.mem_sreclaimable),
        shmem = fmt_short(s.mem_shmem),
    )
}