diff options
author | crestfalln <no-reply@crestfalln.com> | 2023-09-28 04:57:05 +0530 |
---|---|---|
committer | Jakob P. Liljenberg <admin@qvantnet.com> | 2023-09-29 09:51:18 +0200 |
commit | 9b4e85f08dc3be40d8f4904093cd2bdd096e60fa (patch) | |
tree | 9a172b8232e0b5f6cb626f82bdcd26900c1e74e7 | |
parent | 889623874ef6233610ed529bff18e1ba2c407e14 (diff) |
fixed bug where updated disks stats overrided disk io data
-rw-r--r-- | src/btop_shared.hpp | 1 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 14 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/btop_shared.hpp b/src/btop_shared.hpp index ecf97f2..6f0dee5 100644 --- a/src/btop_shared.hpp +++ b/src/btop_shared.hpp @@ -147,6 +147,7 @@ namespace Mem { int64_t free{}; // defaults to 0 int used_percent{}; // defaults to 0 int free_percent{}; // defaults to 0 + bool is_ready = false; array<int64_t, 3> old_io = {0, 0, 0}; deque<long long> io_read = {}; diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index d26405a..1d449f5 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1105,10 +1105,17 @@ namespace Mem { it = disks.erase(it); continue; } - disk = promise_res.first; + auto &updated_stats = promise_res.first; + disk.total = updated_stats.total; + disk.free = updated_stats.free; + disk.used = updated_stats.used; + disk.used_percent = updated_stats.used_percent; + disk.free_percent = updated_stats.free_percent; + disk.is_ready = true; } - disks_stats_promises[mountpoint] = async(std::launch::async, [mountpoint, &free_priv](disk_info disk) -> pair<disk_info, int> { + disks_stats_promises[mountpoint] = async(std::launch::async, [mountpoint, &free_priv]() -> pair<disk_info, int> { struct statvfs vfs; + disk_info disk; if (statvfs(mountpoint.c_str(), &vfs) < 0) { return pair{disk, errno}; } @@ -1118,7 +1125,7 @@ namespace Mem { disk.used_percent = round((double)disk.used * 100 / disk.total); disk.free_percent = 100 - disk.used_percent; return pair{disk, -1}; - }, disk); + }); ++it; } @@ -1149,6 +1156,7 @@ namespace Mem { int64_t sectors_read, sectors_write, io_ticks, io_ticks_temp; disk_ios = 0; for (auto& [ignored, disk] : disks) { + if(!disk.is_ready) continue; if (disk.stat.empty() or access(disk.stat.c_str(), R_OK) != 0) continue; if (disk.fstype == "zfs" && zfs_hide_datasets && zfs_collect_pool_total_stats(disk)) { disk_ios++; |