summaryrefslogtreecommitdiffstats
path: root/src/freebsd
diff options
context:
space:
mode:
authoraristocratos <gnmjpl@gmail.com>2022-01-12 20:49:27 +0100
committeraristocratos <gnmjpl@gmail.com>2022-01-12 20:49:27 +0100
commit64cdb4434371adee47c497c961eb5a4b2f447a4d (patch)
tree409fa6cb8e1c400df1bbd93bb1f6e7402e2b1530 /src/freebsd
parentb6e36a7147a8d1897d3e5b659101e29585a7263c (diff)
Fixed: Net speed rollover for 32-bit
Diffstat (limited to 'src/freebsd')
-rw-r--r--src/freebsd/btop_collect.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp
index e913c79..8531762 100644
--- a/src/freebsd/btop_collect.cpp
+++ b/src/freebsd/btop_collect.cpp
@@ -758,7 +758,7 @@ namespace Mem {
disk_ios = 0;
collect_disk(disks, mapping);
-
+
old_uptime = uptime;
}
return mem;
@@ -864,19 +864,21 @@ namespace Net {
for (const string dir : {"download", "upload"}) {
auto &saved_stat = net.at(iface).stat.at(dir);
auto &bandwidth = net.at(iface).bandwidth.at(dir);
- auto dirval = dir == "download" ? std::get<0>(ifstats[iface]) : std::get<1>(ifstats[iface]);
- uint64_t val = saved_stat.last;
- try {
- val = max(dirval, val);
- } catch (const std::invalid_argument &) {
- } catch (const std::out_of_range &) {
- }
+ uint64_t val = dir == "download" ? std::get<0>(ifstats[iface]) : std::get<1>(ifstats[iface]);
//? Update speed, total and top values
+ if (val < saved_stat.last) {
+ saved_stat.rollover += saved_stat.last;
+ saved_stat.last = 0;
+ }
+ if (cmp_greater((unsigned long long)saved_stat.rollover + (unsigned long long)val, numeric_limits<uint64_t>::max())) {
+ saved_stat.rollover = 0;
+ saved_stat.last = 0;
+ }
saved_stat.speed = round((double)(val - saved_stat.last) / ((double)(new_timestamp - timestamp) / 1000));
if (saved_stat.speed > saved_stat.top) saved_stat.top = saved_stat.speed;
- if (saved_stat.offset > val) saved_stat.offset = 0;
- saved_stat.total = val - saved_stat.offset;
+ if (saved_stat.offset > val + saved_stat.rollover) saved_stat.offset = 0;
+ saved_stat.total = (val + saved_stat.rollover) - saved_stat.offset;
saved_stat.last = val;
//? Add values to graph