mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-31 01:24:31 +02:00
feature: Add support for displaying process usernames on Windows (#1016)
This commit is contained in:
parent
e7b682a550
commit
d956f336a9
@ -182,6 +182,10 @@ impl DataCollector {
|
|||||||
self.sys.refresh_networks_list();
|
self.sys.refresh_networks_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg!(target_os = "windows") && self.widgets_to_harvest.use_proc {
|
||||||
|
self.sys.refresh_users_list();
|
||||||
|
}
|
||||||
|
|
||||||
if self.widgets_to_harvest.use_proc || self.widgets_to_harvest.use_cpu {
|
if self.widgets_to_harvest.use_proc || self.widgets_to_harvest.use_cpu {
|
||||||
self.sys.refresh_cpu();
|
self.sys.refresh_cpu();
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,7 @@ pub struct ProcessHarvest {
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub uid: Option<libc::uid_t>,
|
pub uid: Option<libc::uid_t>,
|
||||||
|
|
||||||
/// This is the process' user. This is only used on Unix platforms.
|
/// This is the process' user.
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
pub user: std::borrow::Cow<'static, str>,
|
pub user: std::borrow::Cow<'static, str>,
|
||||||
// TODO: Additional fields
|
// TODO: Additional fields
|
||||||
// pub rss_kb: u64,
|
// pub rss_kb: u64,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Process data collection for Windows. Uses sysinfo.
|
//! Process data collection for Windows. Uses sysinfo.
|
||||||
|
|
||||||
use sysinfo::{CpuExt, PidExt, ProcessExt, System, SystemExt};
|
use sysinfo::{CpuExt, PidExt, ProcessExt, System, SystemExt, UserExt};
|
||||||
|
|
||||||
use super::ProcessHarvest;
|
use super::ProcessHarvest;
|
||||||
|
|
||||||
@ -75,6 +75,10 @@ pub fn get_process_data(
|
|||||||
total_read_bytes: disk_usage.total_read_bytes,
|
total_read_bytes: disk_usage.total_read_bytes,
|
||||||
total_write_bytes: disk_usage.total_written_bytes,
|
total_write_bytes: disk_usage.total_written_bytes,
|
||||||
process_state,
|
process_state,
|
||||||
|
user: process_val
|
||||||
|
.user_id()
|
||||||
|
.and_then(|uid| sys.get_user_by_id(uid))
|
||||||
|
.map_or_else(|| "N/A".into(), |user| user.name().to_owned().into()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,16 +670,7 @@ impl Prefix {
|
|||||||
}),
|
}),
|
||||||
PrefixType::Pid => r.is_match(process.pid.to_string().as_str()),
|
PrefixType::Pid => r.is_match(process.pid.to_string().as_str()),
|
||||||
PrefixType::State => r.is_match(process.process_state.0.as_str()),
|
PrefixType::State => r.is_match(process.process_state.0.as_str()),
|
||||||
PrefixType::User => {
|
PrefixType::User => r.is_match(process.user.as_ref()),
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
{
|
|
||||||
r.is_match(process.user.as_ref())
|
|
||||||
}
|
|
||||||
#[cfg(not(target_family = "unix"))]
|
|
||||||
{
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,12 +101,8 @@ impl ProcWidgetState {
|
|||||||
pub const WPS: usize = 5;
|
pub const WPS: usize = 5;
|
||||||
pub const T_READ: usize = 6;
|
pub const T_READ: usize = 6;
|
||||||
pub const T_WRITE: usize = 7;
|
pub const T_WRITE: usize = 7;
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
pub const USER: usize = 8;
|
pub const USER: usize = 8;
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
pub const STATE: usize = 9;
|
pub const STATE: usize = 9;
|
||||||
#[cfg(not(target_family = "unix"))]
|
|
||||||
pub const STATE: usize = 8;
|
|
||||||
|
|
||||||
fn new_sort_table(config: &AppConfigFields, colours: &CanvasColours) -> SortTable {
|
fn new_sort_table(config: &AppConfigFields, colours: &CanvasColours) -> SortTable {
|
||||||
const COLUMNS: [Column<SortTableColumn>; 1] = [Column::hard(SortTableColumn, 7)];
|
const COLUMNS: [Column<SortTableColumn>; 1] = [Column::hard(SortTableColumn, 7)];
|
||||||
@ -162,7 +158,6 @@ impl ProcWidgetState {
|
|||||||
wps,
|
wps,
|
||||||
tr,
|
tr,
|
||||||
tw,
|
tw,
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
SortColumn::soft(User, Some(0.05)),
|
SortColumn::soft(User, Some(0.05)),
|
||||||
state,
|
state,
|
||||||
]
|
]
|
||||||
@ -677,7 +672,6 @@ impl ProcWidgetState {
|
|||||||
*col = ProcColumn::Count;
|
*col = ProcColumn::Count;
|
||||||
sort_col.default_order = SortOrder::Descending;
|
sort_col.default_order = SortOrder::Descending;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
self.hide_column(Self::USER);
|
self.hide_column(Self::USER);
|
||||||
self.hide_column(Self::STATE);
|
self.hide_column(Self::STATE);
|
||||||
self.mode = ProcWidgetMode::Grouped;
|
self.mode = ProcWidgetMode::Grouped;
|
||||||
@ -686,7 +680,6 @@ impl ProcWidgetState {
|
|||||||
*col = ProcColumn::Pid;
|
*col = ProcColumn::Pid;
|
||||||
sort_col.default_order = SortOrder::Ascending;
|
sort_col.default_order = SortOrder::Ascending;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
self.show_column(Self::USER);
|
self.show_column(Self::USER);
|
||||||
self.show_column(Self::STATE);
|
self.show_column(Self::STATE);
|
||||||
self.mode = ProcWidgetMode::Normal;
|
self.mode = ProcWidgetMode::Normal;
|
||||||
@ -821,6 +814,8 @@ mod test {
|
|||||||
process_char: '?',
|
process_char: '?',
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
user: "root".to_string(),
|
user: "root".to_string(),
|
||||||
|
#[cfg(not(target_family = "unix"))]
|
||||||
|
user: "N/A".to_string(),
|
||||||
num_similar: 0,
|
num_similar: 0,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
};
|
};
|
||||||
|
@ -109,13 +109,10 @@ impl SortsRow for ProcColumn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProcColumn::User => {
|
ProcColumn::User => {
|
||||||
#[cfg(target_family = "unix")]
|
if descending {
|
||||||
{
|
data.sort_by_cached_key(|pd| Reverse(pd.user.to_lowercase()));
|
||||||
if descending {
|
} else {
|
||||||
data.sort_by_cached_key(|pd| Reverse(pd.user.to_lowercase()));
|
data.sort_by_cached_key(|pd| pd.user.to_lowercase());
|
||||||
} else {
|
|
||||||
data.sort_by_cached_key(|pd| pd.user.to_lowercase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,6 @@ pub struct ProcWidgetData {
|
|||||||
pub total_write: u64,
|
pub total_write: u64,
|
||||||
pub process_state: String,
|
pub process_state: String,
|
||||||
pub process_char: char,
|
pub process_char: char,
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
pub user: String,
|
pub user: String,
|
||||||
pub num_similar: u64,
|
pub num_similar: u64,
|
||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
@ -155,7 +154,6 @@ impl ProcWidgetData {
|
|||||||
total_write: process.total_write_bytes,
|
total_write: process.total_write_bytes,
|
||||||
process_state: process.process_state.0.clone(),
|
process_state: process.process_state.0.clone(),
|
||||||
process_char: process.process_state.1,
|
process_char: process.process_state.1,
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
user: process.user.to_string(),
|
user: process.user.to_string(),
|
||||||
num_similar: 1,
|
num_similar: 1,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
@ -205,16 +203,7 @@ impl ProcWidgetData {
|
|||||||
ProcColumn::TotalRead => dec_bytes_string(self.total_read),
|
ProcColumn::TotalRead => dec_bytes_string(self.total_read),
|
||||||
ProcColumn::TotalWrite => dec_bytes_string(self.total_write),
|
ProcColumn::TotalWrite => dec_bytes_string(self.total_write),
|
||||||
ProcColumn::State => self.process_char.to_string(),
|
ProcColumn::State => self.process_char.to_string(),
|
||||||
ProcColumn::User => {
|
ProcColumn::User => self.user.clone(),
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
{
|
|
||||||
self.user.clone()
|
|
||||||
}
|
|
||||||
#[cfg(not(target_family = "unix"))]
|
|
||||||
{
|
|
||||||
"".to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,16 +236,7 @@ impl DataToCell<ProcColumn> for ProcWidgetData {
|
|||||||
self.process_state.clone()
|
self.process_state.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProcColumn::User => {
|
ProcColumn::User => self.user.clone(),
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
{
|
|
||||||
self.user.clone()
|
|
||||||
}
|
|
||||||
#[cfg(not(target_family = "unix"))]
|
|
||||||
{
|
|
||||||
"".to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
calculated_width,
|
calculated_width,
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user