From ced47a960f649d3c4e81c91128fe97a81e4c4ad5 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 25 Dec 2023 02:26:13 +0100 Subject: Replace robin_hood map and set with STD alternative and add safeVal() function for map/vector access with fallback --- src/freebsd/btop_collect.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/freebsd') diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 7f93322..670acdd 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -98,7 +98,7 @@ namespace Cpu { string cpu_sensor; vector core_sensors; - unordered_flat_map core_mapping; + std::unordered_map core_mapping; } // namespace Cpu namespace Mem { @@ -204,7 +204,7 @@ namespace Cpu { const array time_names = {"user", "nice", "system", "idle"}; - unordered_flat_map cpu_old = { + std::unordered_map cpu_old = { {"totals", 0}, {"idles", 0}, {"user", 0}, @@ -323,8 +323,8 @@ namespace Cpu { return std::to_string(freq / 1000.0 ).substr(0, 3); // seems to be in MHz } - auto get_core_mapping() -> unordered_flat_map { - unordered_flat_map core_map; + auto get_core_mapping() -> std::unordered_map { + std::unordered_map core_map; if (cpu_temp_only) return core_map; for (long i = 0; i < Shared::coreCount; i++) { @@ -557,7 +557,7 @@ namespace Mem { } } - void collect_disk(unordered_flat_map &disks, unordered_flat_map &mapping) { + void collect_disk(std::unordered_map &disks, std::unordered_map &mapping) { // this bit is for 'regular' mounts static struct statinfo cur; long double etime = 0; @@ -691,7 +691,7 @@ namespace Mem { } if (show_disks) { - unordered_flat_map mapping; // keep mapping from device -> mountpoint, since IOKit doesn't give us the mountpoint + std::unordered_map mapping; // keep mapping from device -> mountpoint, since IOKit doesn't give us the mountpoint double uptime = system_uptime(); auto &disks_filter = Config::getS("disks_filter"); bool filter_exclude = false; @@ -807,13 +807,13 @@ namespace Mem { } // namespace Mem namespace Net { - unordered_flat_map current_net; + std::unordered_map current_net; net_info empty_net = {}; vector interfaces; string selected_iface; int errors = 0; - unordered_flat_map graph_max = {{"download", {}}, {"upload", {}}}; - unordered_flat_map> max_count = {{"download", {}}, {"upload", {}}}; + std::unordered_map graph_max = {{"download", {}}, {"upload", {}}}; + std::unordered_map> max_count = {{"download", {}}, {"upload", {}}}; bool rescale = true; uint64_t timestamp = 0; @@ -892,7 +892,7 @@ namespace Net { } //else, ignoring family==AF_LINK (see man 3 getifaddrs) } - unordered_flat_map> ifstats; + std::unordered_map> ifstats; int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; size_t len; if (sysctl(mib, 6, nullptr, &len, nullptr, 0) < 0) { @@ -1037,7 +1037,7 @@ namespace Net { namespace Proc { vector current_procs; - unordered_flat_map uid_user; + std::unordered_map uid_user; string current_sort; string current_filter; bool current_rev = false; -- cgit v1.2.3 From 3a8ceacaf89e7443014613dbc888b8b1657832fe Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 25 Dec 2023 02:37:32 +0100 Subject: Fix call to compact and missing utility include --- src/freebsd/btop_collect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/freebsd') diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 670acdd..2a7a7f3 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -58,6 +58,7 @@ tab-size = 4 #include #include #include +#include #include "../btop_config.hpp" #include "../btop_shared.hpp" @@ -966,7 +967,6 @@ namespace Net { else it++; } - net.compact(); } timestamp = new_timestamp; -- cgit v1.2.3 From 3c04a7a380a5a27630193e8805ef5f9d249cecb3 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 25 Dec 2023 10:41:15 +0100 Subject: Added more checks and debug logging --- src/freebsd/btop_collect.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/freebsd') diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 2a7a7f3..8f0eee9 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -170,17 +170,23 @@ namespace Shared { Cpu::current_cpu.temp.insert(Cpu::current_cpu.temp.begin(), Shared::coreCount + 1, {}); Cpu::core_old_totals.insert(Cpu::core_old_totals.begin(), Shared::coreCount, 0); Cpu::core_old_idles.insert(Cpu::core_old_idles.begin(), Shared::coreCount, 0); + Logger::debug("Init -> Cpu::collect()"); Cpu::collect(); for (auto &[field, vec] : Cpu::current_cpu.cpu_percent) { if (not vec.empty() and not v_contains(Cpu::available_fields, field)) Cpu::available_fields.push_back(field); } + Logger::debug("Init -> Cpu::get_cpuName()"); Cpu::cpuName = Cpu::get_cpuName(); + Logger::debug("Init -> Cpu::get_sensors()"); Cpu::got_sensors = Cpu::get_sensors(); + Logger::debug("Init -> Cpu::get_core_mapping()"); Cpu::core_mapping = Cpu::get_core_mapping(); //? Init for namespace Mem Mem::old_uptime = system_uptime(); + Logger::debug("Init -> Mem::collect()"); Mem::collect(); + Logger::debug("Init -> Mem::get_zpools()"); Mem::get_zpools(); } @@ -576,13 +582,12 @@ namespace Mem { if (disk.dev.string().rfind(devStatName, 0) == 0) { devstat_compute_statistics(&d, nullptr, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); assign_values(disk, total_bytes_read, total_bytes_write); - string mountpoint = mapping.at(disk.dev); + string mountpoint = safeVal(mapping, disk.dev); Logger::debug("dev " + devStatName + " -> " + mountpoint + " read=" + std::to_string(total_bytes_read) + " write=" + std::to_string(total_bytes_write)); } } } - Logger::debug(""); } // this code is for ZFS mounts @@ -604,7 +609,7 @@ namespace Mem { // alternatively you could parse the objset-0x... when this changes, you have a new entry string datasetname = string(value);// this is the zfs volume, like 'zroot/usr/home' -> this maps onto the device we get back from getmntinfo(3) if (mapping.contains(datasetname)) { - string mountpoint = mapping.at(datasetname); + string mountpoint = safeVal(mapping, datasetname); if (disks.contains(mountpoint)) { auto& disk = disks.at(mountpoint); assign_values(disk, nread, nwritten); -- cgit v1.2.3 From b4eb397fc69696db18c6f2b90b79172882c39128 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 25 Dec 2023 10:52:52 +0100 Subject: Fix errors --- src/freebsd/btop_collect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/freebsd') diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 8f0eee9..2db49a2 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -579,10 +579,10 @@ namespace Mem { auto d = cur.dinfo->devices[i]; string devStatName = "/dev/" + string(d.device_name) + std::to_string(d.unit_number); for (auto& [ignored, disk] : disks) { // find matching mountpoints - could be multiple as d.device_name is only ada (and d.unit_number is the device number), while the disk.dev is like /dev/ada0s1 - if (disk.dev.string().rfind(devStatName, 0) == 0) { + if (disk.dev.string().rfind(devStatName, 0) == 0 and mapping.contains(disk.dev)) { devstat_compute_statistics(&d, nullptr, etime, DSM_TOTAL_BYTES_READ, &total_bytes_read, DSM_TOTAL_BYTES_WRITE, &total_bytes_write, DSM_NONE); assign_values(disk, total_bytes_read, total_bytes_write); - string mountpoint = safeVal(mapping, disk.dev); + string mountpoint = mapping.at(disk.dev); Logger::debug("dev " + devStatName + " -> " + mountpoint + " read=" + std::to_string(total_bytes_read) + " write=" + std::to_string(total_bytes_write)); } } @@ -609,7 +609,7 @@ namespace Mem { // alternatively you could parse the objset-0x... when this changes, you have a new entry string datasetname = string(value);// this is the zfs volume, like 'zroot/usr/home' -> this maps onto the device we get back from getmntinfo(3) if (mapping.contains(datasetname)) { - string mountpoint = safeVal(mapping, datasetname); + string mountpoint = mapping.at(datasetname); if (disks.contains(mountpoint)) { auto& disk = disks.at(mountpoint); assign_values(disk, nread, nwritten); -- cgit v1.2.3