From e56367fcbb933850f82140962542fb3f31627517 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Thu, 3 Dec 2020 23:45:54 -0500 Subject: refactor: Clean up some parts of data harvesting (#336) --- .cargo-husky/hooks/pre-push | 4 +- Cargo.lock | 239 ---------------------------- Cargo.toml | 1 - src/app/data_harvester.rs | 24 +-- src/app/data_harvester/battery_harvester.rs | 32 ++-- src/app/data_harvester/disks.rs | 1 + src/app/data_harvester/mem.rs | 44 +++-- src/app/data_harvester/network.rs | 1 - src/app/data_harvester/processes.rs | 5 +- src/app/data_harvester/temperature.rs | 13 +- 10 files changed, 64 insertions(+), 300 deletions(-) diff --git a/.cargo-husky/hooks/pre-push b/.cargo-husky/hooks/pre-push index 28871639..183d3365 100755 --- a/.cargo-husky/hooks/pre-push +++ b/.cargo-husky/hooks/pre-push @@ -4,8 +4,8 @@ set -e echo "Running pre-push hook:" -echo "Executing: cargo clippy -- -D clippy::all" -cargo clippy -- -D clippy::all +echo "Executing: cargo clippy --all-targets --workspace -- -D warnings" +cargo clippy --all-targets --workspace -- -D warnings # echo "Executing: cargo test" # cargo test diff --git a/Cargo.lock b/Cargo.lock index f1522e9f..11b7aeda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,111 +52,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "async-channel" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "vec-arena", -] - -[[package]] -name = "async-fs" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2" -dependencies = [ - "async-lock", - "blocking", - "futures-lite", -] - -[[package]] -name = "async-io" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458c8f66c246624e7cf87c01451f3392ab77d66a0f105a49d9353b30ea97ced8" -dependencies = [ - "concurrent-queue", - "fastrand", - "futures-lite", - "libc", - "log", - "nb-connect", - "once_cell", - "parking", - "polling", - "vec-arena", - "waker-fn", - "winapi", -] - -[[package]] -name = "async-lock" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1996609732bde4a9988bc42125f55f2af5f3c36370e27c778d5191a4a1b63bfb" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-net" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06de475c85affe184648202401d7622afb32f0f74e02192857d0201a16defbe5" -dependencies = [ - "async-io", - "blocking", - "fastrand", - "futures-lite", -] - -[[package]] -name = "async-process" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8cea09c1fb10a317d1b5af8024eeba256d6554763e85ecd90ff8df31c7bbda" -dependencies = [ - "async-io", - "blocking", - "cfg-if 0.1.10", - "event-listener", - "futures-lite", - "once_cell", - "signal-hook", - "winapi", -] - -[[package]] -name = "async-task" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" - -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -211,20 +106,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blocking" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - [[package]] name = "bottom" version = "0.5.3" @@ -250,7 +131,6 @@ dependencies = [ "predicates", "regex", "serde", - "smol", "sysinfo", "thiserror", "toml", @@ -261,12 +141,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "cache-padded" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" - [[package]] name = "cargo-husky" version = "1.5.0" @@ -334,15 +208,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", -] - [[package]] name = "const_fn" version = "0.4.3" @@ -506,21 +371,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - -[[package]] -name = "fastrand" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" -dependencies = [ - "instant", -] - [[package]] name = "fern" version = "0.6.0" @@ -587,21 +437,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" -[[package]] -name = "futures-lite" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6c079abfac3ab269e2927ec048dabc89d009ebfdda6b8ee86624f30c689658" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.8" @@ -988,16 +823,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "nb-connect" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "nix" version = "0.17.0" @@ -1111,12 +936,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "parking_lot" version = "0.11.0" @@ -1163,12 +982,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" - [[package]] name = "pin-utils" version = "0.1.0" @@ -1181,19 +994,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e" -[[package]] -name = "polling" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "log", - "wepoll-sys", - "winapi", -] - [[package]] name = "predicates" version = "1.0.5" @@ -1411,24 +1211,6 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" -[[package]] -name = "smol" -version = "1.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4" -dependencies = [ - "async-channel", - "async-executor", - "async-fs", - "async-io", - "async-lock", - "async-net", - "async-process", - "blocking", - "futures-lite", - "once_cell", -] - [[package]] name = "socket2" version = "0.3.15" @@ -1605,12 +1387,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "vec-arena" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" - [[package]] name = "vec_map" version = "0.8.2" @@ -1632,12 +1408,6 @@ dependencies = [ "libc", ] -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -1650,15 +1420,6 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -[[package]] -name = "wepoll-sys" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" -dependencies = [ - "cc", -] - [[package]] name = "widestring" version = "0.4.3" diff --git a/Cargo.toml b/Cargo.toml index 62e72140..2897398c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ libc = "0.2" once_cell = "1.5.2" regex = "1.4.2" serde = {version = "1.0", features = ["derive"] } -smol = "1.2.5" sysinfo = "0.15.3" thiserror = "1.0.22" toml = "0.5.7" diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 0f59b54f..9cf8de62 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -272,7 +272,7 @@ impl DataCollector { } } - // Async if Heim + // I am *well* aware that the sysinfo part w/ blocking code is... not great. let network_data_fut = { #[cfg(any(target_os = "windows", target_arch = "aarch64", target_arch = "arm"))] { @@ -307,17 +307,6 @@ impl DataCollector { mem::get_mem_data(self.widgets_to_harvest.use_mem) } }; - let swap_data_fut = { - #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] - { - mem::get_swap_data(&self.sys, self.widgets_to_harvest.use_mem) - } - - #[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))] - { - mem::get_swap_data(self.widgets_to_harvest.use_mem) - } - }; let disk_data_fut = { #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] { @@ -343,7 +332,7 @@ impl DataCollector { let temp_data_fut = { #[cfg(any(not(target_os = "linux"), target_arch = "aarch64", target_arch = "arm"))] { - temperature::arm_and_non_linux_temperature_data( + temperature::get_temperature_data( &self.sys, &self.temperature_type, self.widgets_to_harvest.use_temp, @@ -356,17 +345,16 @@ impl DataCollector { target_arch = "arm" )))] { - temperature::linux_temperature_data( + temperature::get_temperature_data( &self.temperature_type, self.widgets_to_harvest.use_temp, ) } }; - let (net_data, mem_res, swap_res, disk_res, io_res, temp_res) = join!( + let (net_data, mem_res, disk_res, io_res, temp_res) = join!( network_data_fut, mem_data_fut, - swap_data_fut, disk_data_fut, disk_io_usage_fut, temp_data_fut @@ -388,14 +376,14 @@ impl DataCollector { } } - if let Ok(memory) = mem_res { + if let Ok(memory) = mem_res.0 { self.data.memory = memory; if log_enabled!(log::Level::Trace) { trace!("mem: {:?} results", self.data.memory); } } - if let Ok(swap) = swap_res { + if let Ok(swap) = mem_res.1 { self.data.swap = swap; if log_enabled!(log::Level::Trace) { trace!("swap: {:?} results", self.data.swap); diff --git a/src/app/data_harvester/battery_harvester.rs b/src/app/data_harvester/battery_harvester.rs index c4623cad..66e3c76b 100644 --- a/src/app/data_harvester/battery_harvester.rs +++ b/src/app/data_harvester/battery_harvester.rs @@ -1,5 +1,5 @@ use battery::{ - units::{power::watt, ratio::percent, time::second, Time}, + units::{power::watt, ratio::percent, time::second}, Battery, Manager, }; @@ -12,26 +12,28 @@ pub struct BatteryHarvest { pub health_percent: f64, } -fn convert_optional_time_to_optional_seconds(optional_time: Option