diff options
author | Jos Dehaes <jos.dehaes@gmail.com> | 2021-10-03 22:56:14 +0200 |
---|---|---|
committer | Jos Dehaes <jos.dehaes@gmail.com> | 2021-10-03 22:56:14 +0200 |
commit | 17f9f3703c1dd52a86176131a2239cd52ee285bd (patch) | |
tree | caa5efff23a5ff4b8d30f49b746ab997de95dcab /src/osx | |
parent | 8462ae6431fcfe1985d1bbb4404452ddc03cc1de (diff) |
try to get disks to show
Diffstat (limited to 'src/osx')
-rw-r--r-- | src/osx/btop_collect.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/osx/btop_collect.cpp b/src/osx/btop_collect.cpp index addafa6..e44e323 100644 --- a/src/osx/btop_collect.cpp +++ b/src/osx/btop_collect.cpp @@ -262,6 +262,7 @@ namespace Mem if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty())) return current_mem; + auto &show_disks = Config::getB("show_disks"); auto &mem = current_mem; FILE *fpIn = popen("/usr/bin/vm_stat", "r"); if (fpIn) @@ -280,7 +281,8 @@ namespace Mem uint64_t f = stoull(trim(val)); mem.stats.at("available") = f * 4096; mem.stats.at("free") = f * 4096; - // } else if (strstr(label, "Pages free")) { + mem.stats.at("cached") = 1; + mem.stats.at("used") = Shared::totalMem - (f*4096); } tokens = strtok(nullptr, delim); } @@ -291,7 +293,30 @@ namespace Mem { Logger::error("failed to read vm_stat"); } - mem.stats.at("used") = Shared::totalMem - mem.stats.at("available"); + //? Calculate percentages + for (const auto& name : mem_names) { + mem.percent.at(name).push_back(round((double)mem.stats.at(name) * 100 / Shared::totalMem)); + while (cmp_greater(mem.percent.at(name).size(), width * 2)) mem.percent.at(name).pop_front(); + } + + if (show_disks) + { + auto& disks = mem.disks; + struct statfs *stfs; + int count = getmntinfo(&stfs, MNT_WAIT); + for (int i = 0; i < count; i++) + { + std::error_code ec; + string mountpoint = stfs[i].f_mntonname; + Logger::debug("found mountpoint " + mountpoint); + string dev = stfs[i].f_mntfromname; + disks[mountpoint] = disk_info{fs::canonical(dev, ec), fs::path(mountpoint).filename()}; + if (disks.at(mountpoint).dev.empty()) disks.at(mountpoint).dev = dev; + if (disks.at(mountpoint).name.empty()) disks.at(mountpoint).name = (mountpoint == "/" ? "root" : mountpoint); + disks.at(mountpoint).free = stfs[i].f_bfree; + disks.at(mountpoint).total = stfs[i].f_iosize; + } + } return mem; } |