From 88366b37140656f6b6e5364db296fc3b37641fc4 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Thu, 17 Dec 2020 15:42:08 -0800 Subject: uptick: 0.5.6 (#362) (cherry picked from commit bfdaa09e3a397df08ff45c44022537195bab0c2b) --- CHANGELOG.md | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 15 +++++++------- src/app/data_harvester.rs | 37 ++++++++++++++++++++++++++-------- src/app/data_harvester/network.rs | 42 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92a13ab..a14a0023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Bug Fixes -## [0.5.6] - Unreleased +## [0.5.6] - 2020-12-17 ## Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index e9bdff02..ac817d83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,7 +233,7 @@ dependencies = [ [[package]] name = "bottom" -version = "0.5.5" +version = "0.5.6" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index f3500813..d005431c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bottom" -version = "0.5.5" +version = "0.5.6" authors = ["Clement Tsang "] edition = "2018" repository = "https://github.com/ClementTsang/bottom" diff --git a/README.md b/README.md index 3518659f..04a0d828 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ cd bottom cargo install --path . # Download from releases and install -curl -LO https://github.com/ClementTsang/bottom/archive/0.5.5.tar.gz -tar -xzvf 0.5.5.tar.gz +curl -LO https://github.com/ClementTsang/bottom/archive/0.5.6.tar.gz +tar -xzvf 0.5.6.tar.gz cargo install --path . ``` @@ -120,8 +120,8 @@ yay -S bottom-bin A `.deb` file is provided on each [release](https://github.com/ClementTsang/bottom/releases/latest): ```bash -curl -LO https://github.com/ClementTsang/bottom/releases/download/0.5.5/bottom_0.5.5_amd64.deb -sudo dpkg -i bottom_0.5.5_amd64.deb +curl -LO https://github.com/ClementTsang/bottom/releases/download/0.5.6/bottom_0.5.6_amd64.deb +sudo dpkg -i bottom_0.5.6_amd64.deb ``` ### Fedora/CentOS @@ -175,7 +175,7 @@ to appear. choco install bottom # Version number may be required for newer releases, if available: -choco install bottom --version=0.5.5 +choco install bottom --version=0.5.6 ``` ### winget @@ -763,9 +763,8 @@ Thanks to all contributors ([emoji key](https://allcontributors.org/docs/en/emoj ## Thanks -- This project is very much inspired by both - [gotop](https://github.com/cjbassi/gotop), its successor - [ytop](https://github.com/cjbassi/ytop), and [gtop](https://github.com/aksakalli/gtop). +- This project is very much inspired by [gotop](https://github.com/cjbassi/gotop), + its successor [ytop](https://github.com/cjbassi/ytop), and [gtop](https://github.com/aksakalli/gtop). - Basic mode is heavily inspired by [htop's](https://hisham.hm/htop/) design. diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 3644654f..cff9bc2e 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -135,6 +135,11 @@ impl DataCollector { self.sys.refresh_components_list(); } + // Refresh network list once... + if cfg!(target_os = "windows") && self.widgets_to_harvest.use_net { + self.sys.refresh_networks_list(); + } + if self.widgets_to_harvest.use_battery { // trace!("First run battery vec creation."); if let Ok(battery_manager) = Manager::new() { @@ -188,6 +193,9 @@ impl DataCollector { self.sys.refresh_components(); } } + if cfg!(target_os = "windows") && self.widgets_to_harvest.use_net { + self.sys.refresh_networks(); + } let current_instant = std::time::Instant::now(); @@ -233,15 +241,28 @@ impl DataCollector { } } - // I am *well* aware that the sysinfo part w/ blocking code is... not great. let network_data_fut = { - network::get_network_data( - self.last_collection_time, - &mut self.total_rx, - &mut self.total_tx, - current_instant, - self.widgets_to_harvest.use_net, - ) + #[cfg(target_os = "windows")] + { + network::get_network_data( + &self.sys, + self.last_collection_time, + &mut self.total_rx, + &mut self.total_tx, + current_instant, + self.widgets_to_harvest.use_net, + ) + } + #[cfg(not(target_os = "windows"))] + { + network::get_network_data( + self.last_collection_time, + &mut self.total_rx, + &mut self.total_tx, + current_instant, + self.widgets_to_harvest.use_net, + ) + } }; let mem_data_fut = mem::get_mem_data(self.widgets_to_harvest.use_mem); let disk_data_fut = disks::get_disk_usage(self.widgets_to_harvest.use_disk); diff --git a/src/app/data_harvester/network.rs b/src/app/data_harvester/network.rs index e15409c5..d4ff3ca9 100644 --- a/src/app/data_harvester/network.rs +++ b/src/app/data_harvester/network.rs @@ -15,6 +15,48 @@ impl NetworkHarvest { } } +#[cfg(target_os = "windows")] +pub async fn get_network_data( + sys: &sysinfo::System, prev_net_access_time: Instant, prev_net_rx: &mut u64, + prev_net_tx: &mut u64, curr_time: Instant, actually_get: bool, +) -> crate::utils::error::Result> { + use sysinfo::{NetworkExt, SystemExt}; + + if !actually_get { + return Ok(None); + } + + let mut total_rx: u64 = 0; + let mut total_tx: u64 = 0; + + let networks = sys.get_networks(); + for (_, network) in networks { + total_rx += network.get_total_received(); + total_tx += network.get_total_transmitted(); + } + + let elapsed_time = curr_time.duration_since(prev_net_access_time).as_secs_f64(); + + let (rx, tx) = if elapsed_time == 0.0 { + (0, 0) + } else { + ( + ((total_rx.saturating_sub(*prev_net_rx)) as f64 / elapsed_time) as u64, + ((total_tx.saturating_sub(*prev_net_tx)) as f64 / elapsed_time) as u64, + ) + }; + + *prev_net_rx = total_rx; + *prev_net_tx = total_tx; + Ok(Some(NetworkHarvest { + rx, + tx, + total_rx, + total_tx, + })) +} + +#[cfg(not(target_os = "windows"))] pub async fn get_network_data( prev_net_access_time: Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64, curr_time: Instant, actually_get: bool, -- cgit v1.2.3