Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kthreads #446

Merged
merged 8 commits into from
Mar 20, 2023
2 changes: 1 addition & 1 deletion src/columns/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Column for Command {
cmd = cmd.replace(['\n', '\t'], " ");
cmd
} else {
proc.curr_proc.stat().comm.clone()
format!("[{}]", proc.curr_proc.stat().comm)
}
} else {
proc.curr_proc.stat().comm.clone()
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ pub struct ConfigDisplay {
pub abbr_sid: bool,
#[serde(default = "default_theme_auto")]
pub theme: ConfigTheme,
#[serde(default = "default_true")]
pub show_kthreads: bool,
}

impl Default for ConfigDisplay {
Expand Down Expand Up @@ -583,6 +585,7 @@ impl Default for ConfigDisplay {
],
abbr_sid: true,
theme: ConfigTheme::Auto,
show_kthreads: true,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/process/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ pub struct ProcessInfo {
pub interval: Duration,
}

pub fn collect_proc(interval: Duration, with_thread: bool) -> Vec<ProcessInfo> {
pub fn collect_proc(
interval: Duration,
with_thread: bool,
show_kthreads: bool,
) -> Vec<ProcessInfo> {
let mut base_procs = Vec::new();
let mut base_tasks = HashMap::new();
let mut ret = Vec::new();
Expand Down Expand Up @@ -128,6 +132,10 @@ pub fn collect_proc(interval: Duration, with_thread: bool) -> Vec<ProcessInfo> {
let interval = curr_time - prev_time;
let ppid = curr_stat.ppid;

if !show_kthreads && (ppid == 2 || pid == 2) {
continue;
}

let mut curr_tasks = HashMap::new();
if with_thread {
if let Ok(iter) = curr_proc.tasks() {
Expand Down
6 changes: 5 additions & 1 deletion src/process/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ pub struct ProcessInfo {
}

#[cfg_attr(tarpaulin, skip)]
pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo> {
pub fn collect_proc(
interval: Duration,
_with_thread: bool,
_show_kthreads: bool,
) -> Vec<ProcessInfo> {
let mut base_procs = Vec::new();
let mut ret = Vec::new();
let arg_max = get_arg_max();
Expand Down
6 changes: 5 additions & 1 deletion src/process/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ pub struct CpuInfo {
}

#[cfg_attr(tarpaulin, skip)]
pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo> {
pub fn collect_proc(
interval: Duration,
_with_thread: bool,
_show_kthreads: bool,
) -> Vec<ProcessInfo> {
let mut base_procs = Vec::new();
let mut ret = Vec::new();

Expand Down
6 changes: 5 additions & 1 deletion src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ impl View {
config.display.show_thread
};

let proc = collect_proc(Duration::from_millis(opt.interval), show_thread);
let proc = collect_proc(
Duration::from_millis(opt.interval),
show_thread,
config.display.show_kthreads,
);
for c in columns.iter_mut() {
for p in &proc {
c.column.add(p);
Expand Down