summaryrefslogtreecommitdiffstats
path: root/src/osx
diff options
context:
space:
mode:
authorJos Dehaes <jos.dehaes@gmail.com>2021-10-03 22:56:14 +0200
committeraristocratos <gnmjpl@gmail.com>2021-10-06 12:45:30 +0200
commit40da88e9ca91f3db540b63b15da5bc34dc9175e9 (patch)
tree9005f534cfebab9e0571380033cd63166029f6de /src/osx
parenteaf2bb56a503fd2bf3787bfd90b5bc8640b7d628 (diff)
try to get disks to show
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/btop_collect.cpp29
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;
}