summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-12-17 14:57:38 -0800
committerGitHub <noreply@github.com>2020-12-17 17:57:38 -0500
commit682f6493d1b0cd7e138b734cf5e789d81530bda5 (patch)
tree2ed64d9b0f23086bacfb9578851e3b7a327e4adc /src/app
parent061cdb913b04aa6cd7e29cf0cc285227ac21846a (diff)
refactor: re-use heim for ARM targets if possible (#360)
Use heim on ARM targets again where appropriate.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_harvester.rs107
-rw-r--r--src/app/data_harvester/disks.rs43
-rw-r--r--src/app/data_harvester/mem.rs37
-rw-r--r--src/app/data_harvester/network.rs42
-rw-r--r--src/app/data_harvester/temperature.rs4
5 files changed, 21 insertions, 212 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 9915e6d0..3644654f 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -97,7 +97,7 @@ impl Default for DataCollector {
// trace!("Creating default data collector...");
DataCollector {
data: Data::default(),
- sys: System::new_with_specifics(sysinfo::RefreshKind::new()),
+ sys: System::new_with_specifics(sysinfo::RefreshKind::new()), // FIXME: Make this run on only macOS and Windows.
#[cfg(target_os = "linux")]
pid_mapping: FnvHashMap::default(),
#[cfg(target_os = "linux")]
@@ -127,10 +127,13 @@ impl Default for DataCollector {
impl DataCollector {
pub fn init(&mut self) {
- // trace!("Initializing data collector.");
self.sys.refresh_memory();
self.mem_total_kb = self.sys.get_total_memory();
- // trace!("Total memory in KB: {}", self.mem_total_kb);
+
+ // Refresh components list once...
+ if self.widgets_to_harvest.use_temp {
+ self.sys.refresh_components_list();
+ }
if self.widgets_to_harvest.use_battery {
// trace!("First run battery vec creation.");
@@ -145,11 +148,6 @@ impl DataCollector {
}
}
- // Refresh components list once...
- if self.widgets_to_harvest.use_temp {
- self.sys.refresh_components_list();
- }
-
// trace!("Running first run.");
futures::executor::block_on(self.update_data());
// trace!("First run done. Sleeping for 250ms...");
@@ -182,32 +180,13 @@ impl DataCollector {
self.sys.refresh_cpu();
}
- if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
- // ARM stuff
+ if cfg!(not(target_os = "linux")) {
if self.widgets_to_harvest.use_proc {
self.sys.refresh_processes();
}
if self.widgets_to_harvest.use_temp {
self.sys.refresh_components();
}
- if self.widgets_to_harvest.use_net {
- self.sys.refresh_networks();
- }
- if self.widgets_to_harvest.use_mem {
- self.sys.refresh_memory();
- }
- } else {
- if cfg!(not(target_os = "linux")) {
- if self.widgets_to_harvest.use_proc {
- self.sys.refresh_processes();
- }
- if self.widgets_to_harvest.use_temp {
- 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();
@@ -256,63 +235,19 @@ impl DataCollector {
// 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"))]
- {
- 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(any(target_os = "windows", target_arch = "aarch64", target_arch = "arm")))]
- {
- 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 = {
- #[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
- {
- mem::get_mem_data(&self.sys, self.widgets_to_harvest.use_mem)
- }
-
- #[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
- {
- mem::get_mem_data(self.widgets_to_harvest.use_mem)
- }
- };
- let disk_data_fut = {
- #[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
- {
- disks::get_disk_usage(&self.sys, self.widgets_to_harvest.use_disk)
- }
-
- #[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
- {
- disks::get_disk_usage(self.widgets_to_harvest.use_disk)
- }
- };
- let disk_io_usage_fut = {
- #[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
- {
- disks::get_io_usage(&self.sys, self.widgets_to_harvest.use_disk)
- }
-
- #[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
- {
- disks::get_io_usage(false, self.widgets_to_harvest.use_disk)
- }
+ 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);
+ let disk_io_usage_fut = disks::get_io_usage(false, self.widgets_to_harvest.use_disk);
let temp_data_fut = {
- #[cfg(any(not(target_os = "linux"), target_arch = "aarch64", target_arch = "arm"))]
+ #[cfg(not(target_os = "linux"))]
{
temperature::get_temperature_data(
&self.sys,
@@ -321,11 +256,7 @@ impl DataCollector {
)
}
- #[cfg(not(any(
- not(target_os = "linux"),
- target_arch = "aarch64",
- target_arch = "arm"
- )))]
+ #[cfg(target_os = "linux")]
{
temperature::get_temperature_data(
&self.temperature_type,
diff --git a/src/app/data_harvester/disks.rs b/src/app/data_harvester/disks.rs
index 294288a0..8c447a46 100644
--- a/src/app/data_harvester/disks.rs
+++ b/src/app/data_harvester/disks.rs
@@ -15,48 +15,6 @@ pub struct IOData {
pub type IOHarvest = std::collections::HashMap<String, Option<IOData>>;
-#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
-pub async fn get_io_usage(
- _sys: &sysinfo::System, _actually_get: bool,
-) -> crate::utils::error::Result<Option<IOHarvest>> {
- let io_hash: std::collections::HashMap<String, Option<IOData>> =
- std::collections::HashMap::new();
- Ok(Some(io_hash))
-
- // TODO: Sysinfo disk I/O usage.
- // ...sadly, this cannot be done as of now (other than me writing my own), it requires further
- // work. See https://github.com/GuillaumeGomez/sysinfo/issues/304.
-}
-
-#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
-pub async fn get_disk_usage(
- sys: &sysinfo::System, actually_get: bool,
-) -> crate::utils::error::Result<Option<Vec<DiskHarvest>>> {
- use sysinfo::{DiskExt, SystemExt};
-
- if !actually_get {
- return Ok(None);
- }
-
- let mut vec_disks = sys
- .get_disks()
- .iter()
- .map(|disk| DiskHarvest {
- name: disk.get_name().to_string_lossy().into(),
- mount_point: disk.get_mount_point().to_string_lossy().into(),
- free_space: disk.get_available_space(),
- used_space: disk
- .get_total_space()
- .saturating_sub(disk.get_available_space()),
- total_space: disk.get_total_space(),
- })
- .collect::<Vec<DiskHarvest>>();
- vec_disks.sort_by(|a, b| a.name.cmp(&b.name));
-
- Ok(Some(vec_disks))
-}
-
-#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
pub async fn get_io_usage(
get_physical: bool, actually_get: bool,
) -> crate::utils::error::Result<Option<IOHarvest>> {
@@ -105,7 +63,6 @@ pub async fn get_io_usage(
Ok(Some(io_hash))
}
-#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
pub async fn get_disk_usage(
actually_get: bool,
) -> crate::utils::error::Result<Option<Vec<DiskHarvest>>> {
diff --git a/src/app/data_harvester/mem.rs b/src/app/data_harvester/mem.rs
index 7348cdea..7dd0f4ca 100644
--- a/src/app/data_harvester/mem.rs
+++ b/src/app/data_harvester/mem.rs
@@ -13,41 +13,6 @@ impl Default for MemHarvest {
}
}
-#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
-pub async fn get_mem_data(
- sys: &sysinfo::System, actually_get: bool,
-) -> (
- crate::utils::error::Result<Option<MemHarvest>>,
- crate::utils::error::Result<Option<MemHarvest>>,
-) {
- if !actually_get {
- (Ok(None), Ok(None))
- } else {
- (get_ram_data(sys), get_swap_data(sys))
- }
-}
-
-#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
-pub fn get_ram_data(sys: &sysinfo::System) -> crate::utils::error::Result<Option<MemHarvest>> {
- use sysinfo::SystemExt;
-
- Ok(Some(MemHarvest {
- mem_total_in_mb: sys.get_total_memory() / 1024,
- mem_used_in_mb: sys.get_used_memory() / 1024,
- }))
-}
-
-#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
-pub fn get_swap_data(sys: &sysinfo::System) -> crate::utils::error::Result<Option<MemHarvest>> {
- use sysinfo::SystemExt;
-
- Ok(Some(MemHarvest {
- mem_total_in_mb: sys.get_total_swap() / 1024,
- mem_used_in_mb: sys.get_used_swap() / 1024,
- }))
-}
-
-#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
pub async fn get_mem_data(
actually_get: bool,
) -> (
@@ -63,7 +28,6 @@ pub async fn get_mem_data(
}
}
-#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
pub async fn get_ram_data() -> crate::utils::error::Result<Option<MemHarvest>> {
let memory = heim::memory::memory().await?;
@@ -76,7 +40,6 @@ pub async fn get_ram_data() -> crate::utils::error::Result<Option<MemHarvest>> {
}))
}
-#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
pub async fn get_swap_data() -> crate::utils::error::Result<Option<MemHarvest>> {
let memory = heim::memory::swap().await?;
diff --git a/src/app/data_harvester/network.rs b/src/app/data_harvester/network.rs
index 37c8b46c..e15409c5 100644
--- a/src/app/data_harvester/network.rs
+++ b/src/app/data_harvester/network.rs
@@ -15,48 +15,6 @@ impl NetworkHarvest {
}
}
-#[cfg(any(target_os = "windows", target_arch = "aarch64", target_arch = "arm"))]
-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<Option<NetworkHarvest>> {
- 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(any(target_os = "windows", target_arch = "aarch64", target_arch = "arm")))]
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,
diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs
index 470b1dbb..512850c9 100644
--- a/src/app/data_harvester/temperature.rs
+++ b/src/app/data_harvester/temperature.rs
@@ -20,7 +20,7 @@ impl Default for TemperatureType {
}
}
-#[cfg(any(not(target_os = "linux"), target_arch = "aarch64", target_arch = "arm"))]
+#[cfg(not(target_os = "linux"))]
pub async fn get_temperature_data(
sys: &sysinfo::System, temp_type: &TemperatureType, actually_get: bool,
) -> crate::utils::error::Result<Option<Vec<TempHarvest>>> {
@@ -59,7 +59,7 @@ pub async fn get_temperature_data(
Ok(Some(temperature_vec))
}
-#[cfg(not(any(not(target_os = "linux"), target_arch = "aarch64", target_arch = "arm")))]
+#[cfg(target_os = "linux")]
pub async fn get_temperature_data(
temp_type: &TemperatureType, actually_get: bool,
) -> crate::utils::error::Result<Option<Vec<TempHarvest>>> {