From 98693aac2502ac4903b95dffcbc9664abe7c4739 Mon Sep 17 00:00:00 2001 From: Jos Dehaes Date: Sun, 24 Oct 2021 21:04:04 +0200 Subject: [PATCH] devstat WIP --- Makefile | 2 +- src/freebsd/btop_collect.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 80f5c57..c3b158c 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ else ifeq ($(PLATFORM_LC),freebsd) PLATFORM_DIR := freebsd THREADS := $(shell getconf NPROCESSORS_ONLN 2>/dev/null || echo 1) SU_GROUP := root - override ADDFLAGS += -lstdc++ -lm -lkvm -Wl,-rpath=/usr/local/lib/gcc11 + override ADDFLAGS += -lstdc++ -lm -lkvm -ldevstat -Wl,-rpath=/usr/local/lib/gcc11 export MAKE = gmake else ifeq ($(PLATFORM_LC),macos) PLATFORM_DIR := osx diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 6da2138..fafe30f 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -42,6 +42,7 @@ tab-size = 4 #include #include #include +#include #include #include @@ -466,6 +467,22 @@ namespace Mem { return Shared::totalMem; } + void collect_disk(unordered_flat_map &disks, unordered_flat_map &mapping) { + static struct statinfo cur, last; + long double etime = 0; + u_int64_t total_bytes_read; + u_int64_t total_bytes_write; + + cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); + last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); + 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)); + } + } + auto collect(const bool no_update) -> mem_info & { if (Runner::stopping or (no_update and not current_mem.percent.at("used").empty())) return current_mem; @@ -545,6 +562,7 @@ 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") { @@ -625,7 +643,8 @@ namespace Mem { mem.disks_order.push_back(name); disk_ios = 0; - + collect_disk(disks, mapping); + old_uptime = uptime; } return mem;