Skip to content

Commit

Permalink
Add thread information #30
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Jan 28, 2021
1 parent de076ca commit 12cf334
Show file tree
Hide file tree
Showing 30 changed files with 209 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased](https://github.com/dalance/procs/compare/v0.11.0...Unreleased) - ReleaseDate

* [Added] thread information [#30](https://github.com/dalance/procs/issues/30)

## [v0.11.0](https://github.com/dalance/procs/compare/v0.10.10...v0.11.0) - 2021-01-28

* [Added] automatic theme detection [#78](https://github.com/dalance/procs/issues/78)
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ logic = "And"

[display]
show_self = false
show_thread = false
show_thread_in_tree = true
cut_to_terminal = true
cut_to_pager = false
cut_to_pipe = false
Expand Down Expand Up @@ -549,18 +551,20 @@ style = "223" # 223 for both theme

`[display]` section defines option for output display.

| Key | Value | Default | Description |
| --------------- | --------------------- | ---------------- | ---------------------------------------------------------------------------- |
| show_self | true, false | false | Whether the self process ( `procs` ) is shown |
| cut_to_terminal | true, false | true | Whether output lines are truncated for output into terminal |
| cut_to_pager | true, false | false | Whether output lines are truncated for output into pager |
| cut_to_pipe | true, false | false | Whether output lines are truncated for output into pipe |
| color_mode | Auto, Always, Disable | Auto | The default behavior of output coloring without `--color` commandline option |
| separator | [String] || String used as Separator |
| ascending | [String] || Ascending sort indicator |
| descending | [String] || Descending sort indicator |
| tree_symbols | [String; 5] | [│, ─, ┬, ├, └] | Symbols used by tree view |
| abbr_sid | true, false | true | Whether machine SID is abbreviated ( windows only ) |
| Key | Value | Default | Description |
| ------------------- | --------------------- | ---------------- | ---------------------------------------------------------------------------- |
| show_self | true, false | false | Whether the self process ( `procs` ) is shown |
| show_thread | true, false | false | Whether the thread information is shown ( Linux only ) |
| show_thread_in_tree | true, false | true | Whether the thread information is shown in tree mode ( Linux only ) |
| cut_to_terminal | true, false | true | Whether output lines are truncated for output into terminal |
| cut_to_pager | true, false | false | Whether output lines are truncated for output into pager |
| cut_to_pipe | true, false | false | Whether output lines are truncated for output into pipe |
| color_mode | Auto, Always, Disable | Auto | The default behavior of output coloring without `--color` commandline option |
| separator | [String] || String used as Separator |
| ascending | [String] || Ascending sort indicator |
| descending | [String] || Descending sort indicator |
| tree_symbols | [String; 5] | [│, ─, ┬, ├, └] | Symbols used by tree view |
| abbr_sid | true, false | true | Whether machine SID is abbreviated ( Windows only ) |

If `color_mode` is `Auto`, color is enabled for terminal and pager, disabled for pipe.

Expand Down
4 changes: 2 additions & 2 deletions src/columns/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ impl Column for Command {
cmd = cmd.replace("\n", " ").replace("\t", " ");
cmd
} else {
proc.curr_proc.stat.comm.clone()
proc.curr_proc.stat().comm.clone()
}
} else {
proc.curr_proc.stat.comm.clone()
proc.curr_proc.stat().comm.clone()
};
let raw_content = fmt_content.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/columns/cpu_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl CpuTime {
#[cfg(target_os = "linux")]
impl Column for CpuTime {
fn add(&mut self, proc: &ProcessInfo) {
let time_sec = (proc.curr_proc.stat.utime + proc.curr_proc.stat.stime)
let time_sec = (proc.curr_proc.stat().utime + proc.curr_proc.stat().stime)
/ procfs::ticks_per_second().unwrap_or(100) as u64;

let fmt_content = util::parse_time(time_sec);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/eip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Eip {

impl Column for Eip {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.kstkeip;
let raw_content = proc.curr_proc.stat().kstkeip;
let fmt_content = format!("{:016x}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/esp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Esp {

impl Column for Esp {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.kstkesp;
let raw_content = proc.curr_proc.stat().kstkesp;
let fmt_content = format!("{:016x}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/maj_flt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl MajFlt {
#[cfg(target_os = "linux")]
impl Column for MajFlt {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.majflt;
let raw_content = proc.curr_proc.stat().majflt;
let fmt_content = format!("{}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/min_flt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl MinFlt {
#[cfg(target_os = "linux")]
impl Column for MinFlt {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.minflt;
let raw_content = proc.curr_proc.stat().minflt;
let fmt_content = format!("{}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/nice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Nice {
#[cfg(target_os = "linux")]
impl Column for Nice {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.nice;
let raw_content = proc.curr_proc.stat().nice;
let fmt_content = format!("{}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
17 changes: 17 additions & 0 deletions src/columns/pid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ impl Pid {
}
}

#[cfg(target_os = "linux")]
impl Column for Pid {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.pid;
let fmt_content = match proc.curr_proc {
crate::process::ProcessTask::Process(_) => format!("{}", raw_content),
_ => format!("[{}]", raw_content),
};

self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}

column_default!(i32);
}

#[cfg(not(target_os = "linux"))]
impl Column for Pid {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.pid;
Expand Down
2 changes: 1 addition & 1 deletion src/columns/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Policy {
#[cfg(target_os = "linux")]
impl Column for Policy {
fn add(&mut self, proc: &ProcessInfo) {
let fmt_content = match proc.curr_proc.stat.policy.map(|x| x as i32) {
let fmt_content = match proc.curr_proc.stat().policy.map(|x| x as i32) {
Some(libc::SCHED_BATCH) => String::from("B"),
Some(libc::SCHED_FIFO) => String::from("FF"),
Some(libc::SCHED_IDLE) => String::from("IDL"),
Expand Down
2 changes: 1 addition & 1 deletion src/columns/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Priority {
#[cfg(target_os = "linux")]
impl Column for Priority {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.priority;
let raw_content = proc.curr_proc.stat().priority;
let fmt_content = format!("{}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
4 changes: 2 additions & 2 deletions src/columns/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl Processor {

impl Column for Processor {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.processor.unwrap_or_default();
let fmt_content = if let Some(p) = proc.curr_proc.stat.processor {
let raw_content = proc.curr_proc.stat().processor.unwrap_or_default();
let fmt_content = if let Some(p) = proc.curr_proc.stat().processor {
format!("{}", p)
} else {
String::from("")
Expand Down
4 changes: 2 additions & 2 deletions src/columns/rt_priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl RtPriority {

impl Column for RtPriority {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.rt_priority.unwrap_or_default();
let fmt_content = if let Some(p) = proc.curr_proc.stat.rt_priority {
let raw_content = proc.curr_proc.stat().rt_priority.unwrap_or_default();
let fmt_content = if let Some(p) = proc.curr_proc.stat().rt_priority {
format!("{}", p)
} else {
String::from("")
Expand Down
2 changes: 1 addition & 1 deletion src/columns/start_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl StartTime {
#[cfg(target_os = "linux")]
impl Column for StartTime {
fn add(&mut self, proc: &ProcessInfo) {
let starttime = proc.curr_proc.stat.starttime;
let starttime = proc.curr_proc.stat().starttime;
let seconds_since_boot = starttime as f32 / *TICKS_PER_SECOND as f32;
let raw_content =
self.boot_time + Duration::milliseconds((seconds_since_boot * 1000.0) as i64);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl State {
#[cfg(target_os = "linux")]
impl Column for State {
fn add(&mut self, proc: &ProcessInfo) {
let fmt_content = format!("{}", proc.curr_proc.stat.state);
let fmt_content = format!("{}", proc.curr_proc.stat().state);
let raw_content = fmt_content.clone();

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Threads {
#[cfg(target_os = "linux")]
impl Column for Threads {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.num_threads;
let raw_content = proc.curr_proc.stat().num_threads;
let fmt_content = format!("{}", raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
13 changes: 7 additions & 6 deletions src/columns/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl Column for Tree {
#[cfg(target_os = "linux")]
mod tests {
use super::*;
use crate::process::ProcessTask;
use procfs::process::Process;
use std::time::Duration;

Expand All @@ -228,8 +229,8 @@ mod tests {
let p0 = ProcessInfo {
pid: 0,
ppid: 0,
curr_proc: Process::myself().unwrap(),
prev_proc: Process::myself().unwrap(),
curr_proc: ProcessTask::Process(Process::myself().unwrap()),
prev_proc: ProcessTask::Process(Process::myself().unwrap()),
curr_io: None,
prev_io: None,
curr_status: None,
Expand All @@ -239,8 +240,8 @@ mod tests {
let p1 = ProcessInfo {
pid: 1,
ppid: 0,
curr_proc: Process::myself().unwrap(),
prev_proc: Process::myself().unwrap(),
curr_proc: ProcessTask::Process(Process::myself().unwrap()),
prev_proc: ProcessTask::Process(Process::myself().unwrap()),
curr_io: None,
prev_io: None,
curr_status: None,
Expand All @@ -250,8 +251,8 @@ mod tests {
let p2 = ProcessInfo {
pid: 2,
ppid: 1,
curr_proc: Process::myself().unwrap(),
prev_proc: Process::myself().unwrap(),
curr_proc: ProcessTask::Process(Process::myself().unwrap()),
prev_proc: ProcessTask::Process(Process::myself().unwrap()),
curr_io: None,
prev_io: None,
curr_status: None,
Expand Down
2 changes: 1 addition & 1 deletion src/columns/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Tty {
#[cfg(target_os = "linux")]
impl Column for Tty {
fn add(&mut self, proc: &ProcessInfo) {
let (major, minor) = proc.curr_proc.stat.tty_nr();
let (major, minor) = proc.curr_proc.stat().tty_nr();
let fmt_content = if major == 136 {
format!("pts/{}", minor)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/columns/usage_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl UsageCpu {
#[cfg(target_os = "linux")]
impl Column for UsageCpu {
fn add(&mut self, proc: &ProcessInfo) {
let curr_time = proc.curr_proc.stat.utime + proc.curr_proc.stat.stime;
let prev_time = proc.prev_proc.stat.utime + proc.prev_proc.stat.stime;
let curr_time = proc.curr_proc.stat().utime + proc.curr_proc.stat().stime;
let prev_time = proc.prev_proc.stat().utime + proc.prev_proc.stat().stime;
let usage_ms =
(curr_time - prev_time) * 1000 / procfs::ticks_per_second().unwrap_or(100) as u64;
let interval_ms = proc.interval.as_secs() * 1000 + u64::from(proc.interval.subsec_millis());
Expand Down
2 changes: 1 addition & 1 deletion src/columns/usage_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn get_mem_total() -> u64 {
#[cfg(target_os = "linux")]
impl Column for UsageMem {
fn add(&mut self, proc: &ProcessInfo) {
let usage = proc.curr_proc.stat.rss_bytes() as f64 * 100.0 / self.mem_total as f64;
let usage = proc.curr_proc.stat().rss_bytes() as f64 * 100.0 / self.mem_total as f64;
let fmt_content = format!("{:.1}", usage);
let raw_content = (usage * 1000.0) as u32;

Expand Down
4 changes: 2 additions & 2 deletions src/columns/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl User {
#[cfg(target_os = "linux")]
impl Column for User {
fn add(&mut self, proc: &ProcessInfo) {
let user = users::get_user_by_uid(proc.curr_proc.owner);
let user = users::get_user_by_uid(proc.curr_proc.owner());
let fmt_content = if let Some(user) = user {
format!("{}", user.name().to_string_lossy())
} else {
format!("{}", proc.curr_proc.owner)
format!("{}", proc.curr_proc.owner())
};
let raw_content = fmt_content.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/columns/vm_rss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl VmRss {
#[cfg(target_os = "linux")]
impl Column for VmRss {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.rss_bytes() as u64;
let raw_content = proc.curr_proc.stat().rss_bytes() as u64;
let fmt_content = bytify(raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
2 changes: 1 addition & 1 deletion src/columns/vm_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl VmSize {
#[cfg(target_os = "linux")]
impl Column for VmSize {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = proc.curr_proc.stat.vsize;
let raw_content = proc.curr_proc.stat().vsize;
let fmt_content = bytify(raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ pub enum ConfigSearchLogic {
pub struct ConfigDisplay {
#[serde(default = "default_false")]
pub show_self: bool,
#[serde(default = "default_false")]
pub show_thread: bool,
#[serde(default = "default_true")]
pub show_thread_in_tree: bool,
#[serde(default = "default_true")]
pub cut_to_terminal: bool,
#[serde(default = "default_false")]
Expand All @@ -528,6 +532,8 @@ impl Default for ConfigDisplay {
fn default() -> Self {
ConfigDisplay {
show_self: false,
show_thread: false,
show_thread_in_tree: true,
cut_to_terminal: true,
cut_to_pager: false,
cut_to_pipe: false,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ pub struct Opt {
#[structopt(short = "l", long = "list")]
pub list: bool,

/// Show thread
#[structopt(long = "thread")]
pub thread: bool,

/// Tree view
#[structopt(short = "t", long = "tree")]
pub tree: bool,
Expand Down

0 comments on commit 12cf334

Please sign in to comment.