mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
refactor: re-use heim for ARM targets if possible (#360)
Use heim on ARM targets again where appropriate.
This commit is contained in:
parent
061cdb913b
commit
682f6493d1
8 changed files with 28 additions and 215 deletions
|
@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Bug Fixes
|
||||
|
||||
## [0.5.6] - Unreleased
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- [#361](https://github.com/ClementTsang/bottom/pull/361): Fixed temperature sensors not working on non-Linux platforms.
|
||||
|
||||
## [0.5.5] - 2020-12-14
|
||||
|
||||
## Bug Fixes
|
||||
|
|
|
@ -45,7 +45,7 @@ itertools = "0.9.0"
|
|||
libc = "~0.2"
|
||||
once_cell = "1.5.2"
|
||||
regex = "1.4.2"
|
||||
serde = {version = "~1.0", features = ["derive"] }
|
||||
serde = { version = "~1.0", features = ["derive"] }
|
||||
sysinfo = "0.15.3"
|
||||
thiserror = "1.0.22"
|
||||
toml = "0.5.7"
|
||||
|
@ -58,7 +58,6 @@ unicode-width = "0.1"
|
|||
fern = { version = "0.6.0", optional=true }
|
||||
log = { version="0.4.11", optional=true }
|
||||
|
||||
[target.'cfg(not(any(target_arch = "arm", target_arch = "aarch64")))'.dependencies]
|
||||
heim = { version = "0.1.0-rc.1", features = ["disk", "memory", "net", "sensors"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>>> {
|
||||
|
|
|
@ -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?;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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>>> {
|
||||
|
|
|
@ -43,7 +43,6 @@ impl From<std::io::Error> for BottomError {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
|
||||
impl From<heim::Error> for BottomError {
|
||||
fn from(err: heim::Error) -> Self {
|
||||
BottomError::InvalidHeim(err.to_string())
|
||||
|
|
Loading…
Reference in a new issue