From a6602ff22b4b00ecb7138a09f5c5a15e1b13ca62 Mon Sep 17 00:00:00 2001 From: Jos Dehaes Date: Tue, 16 Nov 2021 21:53:33 +0100 Subject: correctly iterate over devstat. still no idea how to map the devices we get back here to mountpoints --- src/freebsd/btop_collect.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 7e2be8d..5ffb7a5 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -478,12 +478,15 @@ namespace Mem { static std::unique_ptr lastDevInfo (reinterpret_cast(std::calloc(1, sizeof(struct devinfo))), std::free); cur.dinfo = curDevInfo.get(); last.dinfo = lastDevInfo.get(); - int n = devstat_getdevs(NULL, &cur); - for (int i = 0; i < n; i++) { - devstat_compute_statistics(&cur.dinfo->devices[i], NULL, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, - DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); - Logger::debug("dev " + string(cur.dinfo->devices[i].device_name) + " read=" + std::to_string(total_bytes_read) + " write=" + std::to_string(total_bytes_write)); - } + + if (devstat_getdevs(NULL, &cur) != -1) { + for (int i = 0; i < cur.dinfo->numdevs; i++) { + devstat_compute_statistics(&cur.dinfo->devices[i], NULL, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, + DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); + Logger::debug("dev " + string(cur.dinfo->devices[i].device_name) + std::to_string(cur.dinfo->devices[i].device_number) + " read=" + std::to_string(total_bytes_read) + " write=" + std::to_string(total_bytes_write)); + } + Logger::debug(""); + } } auto collect(const bool no_update) -> mem_info & { @@ -565,7 +568,6 @@ namespace Mem { std::error_code ec; string mountpoint = stfs[i].f_mntonname; string dev = stfs[i].f_mntfromname; - Logger::debug(dev + "->" + mountpoint); mapping[dev] = mountpoint; if (string(stfs[i].f_fstypename) == "autofs") { -- cgit v1.2.3