Skip to content

Commit

Permalink
bug: fix issues with macos and windows during refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed May 15, 2022
1 parent 07cdf08 commit eecf396
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
use typed_builder::*;

use data_farmer::*;
use data_harvester::{processes, temperature};
use data_harvester::temperature;
use layout_manager::*;
pub use states::*;

Expand Down Expand Up @@ -132,7 +132,7 @@ pub struct App {

#[cfg(target_family = "unix")]
#[builder(default, setter(skip))]
pub user_table: processes::UserTable,
pub user_table: data_harvester::processes::UserTable,

pub cpu_state: CpuState,
pub mem_state: MemState,
Expand Down
9 changes: 6 additions & 3 deletions src/app/data_harvester/processes/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ pub fn get_process_data(
};

let disk_usage = process_val.disk_usage();
let process_state = {
let ps = process_val.status();
(ps.to_string(), convert_process_status_to_char(ps))
};
process_vector.push(ProcessHarvest {
pid: process_val.pid().as_u32() as _,
parent_pid: process_val.parent().map(|p| p.as_u32() as _),
Expand All @@ -102,16 +106,15 @@ pub fn get_process_data(
write_bytes_per_sec: disk_usage.written_bytes,
total_read_bytes: disk_usage.total_read_bytes,
total_write_bytes: disk_usage.total_written_bytes,
process_state: process_val.status().to_string(),
process_state_char: convert_process_status_to_char(process_val.status()),
process_state,
uid: process_val.uid,
});
}

let unknown_state = ProcessStatus::Unknown(0).to_string();
let cpu_usage_unknown_pids: Vec<i32> = process_vector
.iter()
.filter(|process| process.process_state == unknown_state)
.filter(|process| process.process_state.0 == unknown_state)
.map(|process| process.pid)
.collect();
let cpu_usages = get_macos_process_cpu_usage(&cpu_usage_unknown_pids)?;
Expand Down
4 changes: 1 addition & 3 deletions src/app/data_harvester/processes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ cfg_if::cfg_if! {
}
}

use std::borrow::Cow;

use crate::Pid;

#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -71,7 +69,7 @@ pub struct ProcessHarvest {

/// This is the process' user. This is only used on Unix platforms.
#[cfg(target_family = "unix")]
pub user: Cow<'static, str>,
pub user: std::borrow::Cow<'static, str>,
// TODO: Additional fields
// pub rss_kb: u64,
// pub virt_kb: u64,
Expand Down
4 changes: 2 additions & 2 deletions src/app/data_harvester/processes/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn get_process_data(
};

let disk_usage = process_val.disk_usage();
let process_state = (process_val.status().to_string(), 'R');
process_vector.push(ProcessHarvest {
pid: process_val.pid().as_u32() as _,
parent_pid: process_val.parent().map(|p| p.as_u32() as _),
Expand All @@ -71,8 +72,7 @@ pub fn get_process_data(
write_bytes_per_sec: disk_usage.written_bytes,
total_read_bytes: disk_usage.total_read_bytes,
total_write_bytes: disk_usage.total_written_bytes,
process_state: process_val.status().to_string(),
process_state_char: 'R',
process_state,
});
}

Expand Down
13 changes: 8 additions & 5 deletions src/app/widgets/process_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,14 @@ impl ProcWidgetColumn {
}
}
ProcWidgetColumn::User => {
data.sort_by_cached_key(|p| p.name.to_lowercase());
if sort_descending {
data.sort_by_cached_key(|p| Reverse(p.user.to_lowercase()));
} else {
data.sort_by_cached_key(|p| p.user.to_lowercase());
#[cfg(target_family = "unix")]
{
data.sort_by_cached_key(|p| p.name.to_lowercase());
if sort_descending {
data.sort_by_cached_key(|p| Reverse(p.user.to_lowercase()));
} else {
data.sort_by_cached_key(|p| p.user.to_lowercase());
}
}
}
}
Expand Down

0 comments on commit eecf396

Please sign in to comment.