diff options
-rw-r--r-- | src/btop_input.cpp | 4 | ||||
-rw-r--r-- | src/btop_shared.hpp | 2 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 12 | ||||
-rw-r--r-- | src/osx/btop_collect.cpp | 12 |
4 files changed, 23 insertions, 7 deletions
diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 85ba644..39fbd8a 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -517,8 +517,8 @@ namespace Input { ndev.stat.at("upload").offset = 0; } else { - ndev.stat.at("download").offset = ndev.stat.at("download").last; - ndev.stat.at("upload").offset = ndev.stat.at("upload").last; + ndev.stat.at("download").offset = ndev.stat.at("download").last + ndev.stat.at("download").rollover; + ndev.stat.at("upload").offset = ndev.stat.at("upload").last + ndev.stat.at("upload").rollover; } no_update = false; } diff --git a/src/btop_shared.hpp b/src/btop_shared.hpp index c9f66df..22c6204 100644 --- a/src/btop_shared.hpp +++ b/src/btop_shared.hpp @@ -171,7 +171,7 @@ namespace Net { extern unordered_flat_map<string, uint64_t> graph_max; struct net_stat { - uint64_t speed = 0, top = 0, total = 0, last = 0, offset = 0; + uint64_t speed = 0, top = 0, total = 0, last = 0, offset = 0, rollover = 0; }; struct net_info { diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 5a71e11..4fe120d 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1103,10 +1103,18 @@ namespace Net { catch (const std::out_of_range&) {} //? 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 diff --git a/src/osx/btop_collect.cpp b/src/osx/btop_collect.cpp index 9f5355c..5537d75 100644 --- a/src/osx/btop_collect.cpp +++ b/src/osx/btop_collect.cpp @@ -927,10 +927,18 @@ namespace Net { } //? 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 |