Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: 1.76.0
toolchain: 1.88.0
targets: x86_64-unknown-linux-gnu
- name: Run build
run: cargo build
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ categories = ["command-line-utilities"]
license = "MIT"
readme = "README.md"
description = "A modern replacement for ps"
edition = "2021"
edition = "2024"
exclude = ["img/*", "config/*"]
rust-version = "1.76"
rust-version = "1.88"

[package.metadata.release]
pre-release-commit-message = "Prepare to v{{version}}"
Expand Down
8 changes: 4 additions & 4 deletions src/columns/context_sw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ impl ContextSw {
impl Column for ContextSw {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if let Some(ref status) = proc.curr_status {
if status.voluntary_ctxt_switches.is_some()
&& status.nonvoluntary_ctxt_switches.is_some()
if let Some(voluntary_ctxt_switches) = status.voluntary_ctxt_switches
&& let Some(nonvoluntary_ctxt_switches) = status.nonvoluntary_ctxt_switches
{
let sw = status.voluntary_ctxt_switches.unwrap()
+ status.nonvoluntary_ctxt_switches.unwrap();
let sw = voluntary_ctxt_switches
+ nonvoluntary_ctxt_switches;
(bytify(sw), sw)
} else {
(String::new(), 0)
Expand Down
20 changes: 10 additions & 10 deletions src/columns/env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::process::ProcessInfo;
use crate::{column_default, Column};
use crate::{Column, column_default};
use std::cmp;
use std::collections::HashMap;
use std::path::PathBuf;
Expand Down Expand Up @@ -33,15 +33,15 @@ impl Env {
impl Column for Env {
fn add(&mut self, proc: &ProcessInfo) {
let mut fmt_content = String::new();
if let Ok(proc) = crate::util::process_new(proc.pid, &self.procfs) {
if let Ok(envs) = proc.environ() {
for (k, v) in envs {
fmt_content.push_str(&format!(
"{}=\"{}\" ",
k.to_string_lossy(),
v.to_string_lossy().replace('\"', "\\\"")
));
}
if let Ok(proc) = crate::util::process_new(proc.pid, &self.procfs)
&& let Ok(envs) = proc.environ()
{
for (k, v) in envs {
fmt_content.push_str(&format!(
"{}=\"{}\" ",
k.to_string_lossy(),
v.to_string_lossy().replace('\"', "\\\"")
));
}
}
let raw_content = fmt_content.clone();
Expand Down
7 changes: 3 additions & 4 deletions src/columns/involuntary_context_sw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::process::ProcessInfo;
use crate::util::bytify;
use crate::{column_default, Column};
use crate::{Column, column_default};
use std::cmp;
use std::collections::HashMap;

Expand Down Expand Up @@ -30,9 +30,8 @@ impl InvoluntaryContextSw {
impl Column for InvoluntaryContextSw {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if let Some(ref status) = proc.curr_status {
if status.nonvoluntary_ctxt_switches.is_some()
{
let sw = status.nonvoluntary_ctxt_switches.unwrap();
if let Some(nonvoluntary_ctxt_switches) = status.nonvoluntary_ctxt_switches {
let sw = nonvoluntary_ctxt_switches;
(bytify(sw), sw)
} else {
(String::new(), 0)
Expand Down
11 changes: 5 additions & 6 deletions src/columns/read_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::process::ProcessInfo;
use crate::util::bytify;
use crate::{column_default, Column};
use crate::{Column, column_default};
use std::cmp;
use std::collections::HashMap;

Expand Down Expand Up @@ -29,12 +29,11 @@ impl ReadBytes {
#[cfg(any(target_os = "linux", target_os = "android"))]
impl Column for ReadBytes {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if proc.curr_io.is_some() && proc.prev_io.is_some() {
let (fmt_content, raw_content) = if let Some(curr_io) = proc.curr_io
&& let Some(prev_io) = proc.prev_io
{
let interval_ms = proc.interval.as_secs() + u64::from(proc.interval.subsec_millis());
let io = (proc.curr_io.as_ref().unwrap().read_bytes
- proc.prev_io.as_ref().unwrap().read_bytes)
* 1000
/ interval_ms;
let io = (curr_io.read_bytes - prev_io.read_bytes) * 1000 / interval_ms;
(bytify(io), io)
} else {
(String::new(), 0)
Expand Down
12 changes: 6 additions & 6 deletions src/columns/tcp_port.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::process::ProcessInfo;
use crate::Column;
use crate::process::ProcessInfo;
#[cfg(target_os = "macos")]
use libproc::libproc::net_info::TcpSIState;
#[cfg(any(target_os = "linux", target_os = "android"))]
Expand All @@ -14,7 +14,7 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use windows_sys::Win32::Foundation::{ERROR_INSUFFICIENT_BUFFER, NO_ERROR};
#[cfg(target_os = "windows")]
use windows_sys::Win32::NetworkManagement::IpHelper::{
GetTcp6Table2, GetTcpTable2, MIB_TCP6TABLE2, MIB_TCPTABLE2, MIB_TCP_STATE, MIB_TCP_STATE_LISTEN,
GetTcp6Table2, GetTcpTable2, MIB_TCP_STATE, MIB_TCP_STATE_LISTEN, MIB_TCP6TABLE2, MIB_TCPTABLE2,
};
#[cfg(target_os = "windows")]
use windows_sys::Win32::Networking::WinSock::{ntohl, ntohs};
Expand Down Expand Up @@ -68,10 +68,10 @@ impl Column for TcpPort {
for sock in &socks {
let mut tcp_iter = self.tcp_entry.iter().chain(self.tcp6_entry.iter());
let entry = tcp_iter.find(|&x| x.inode == *sock);
if let Some(entry) = entry {
if entry.state == TcpState::Listen {
ports.push(entry.local_address.port());
}
if let Some(entry) = entry
&& entry.state == TcpState::Listen
{
ports.push(entry.local_address.port());
}
}
ports.sort_unstable();
Expand Down
10 changes: 5 additions & 5 deletions src/columns/tree.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::process::ProcessInfo;
use crate::Column;
use crate::process::ProcessInfo;
use std::cmp;
use std::collections::HashMap;

Expand Down Expand Up @@ -136,10 +136,10 @@ impl Column for Tree {
for p in self.rev_tree.values() {
if !self.rev_tree.contains_key(p) {
root_pids.push(*p);
} else if let Some(ppid) = self.rev_tree.get(p) {
if *ppid == *p {
root_pids.push(*p);
}
} else if let Some(ppid) = self.rev_tree.get(p)
&& *ppid == *p
{
root_pids.push(*p);
}
}
root_pids.sort_unstable();
Expand Down
10 changes: 4 additions & 6 deletions src/columns/voluntary_context_sw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::process::ProcessInfo;
use crate::util::bytify;
use crate::{column_default, Column};
use crate::{Column, column_default};
use std::cmp;
use std::collections::HashMap;

Expand Down Expand Up @@ -30,9 +30,8 @@ impl VoluntaryContextSw {
impl Column for VoluntaryContextSw {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if let Some(ref status) = proc.curr_status {
if status.voluntary_ctxt_switches.is_some()
{
let sw = status.voluntary_ctxt_switches.unwrap();
if let Some(voluntary_ctxt_switches) = status.voluntary_ctxt_switches {
let sw = voluntary_ctxt_switches;
(bytify(sw), sw)
} else {
(String::new(), 0)
Expand All @@ -51,8 +50,7 @@ impl Column for VoluntaryContextSw {
#[cfg(target_os = "freebsd")]
impl Column for VoluntaryContextSw {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content =
proc.curr_proc.info.rusage.nvcsw as u64;
let raw_content = proc.curr_proc.info.rusage.nvcsw as u64;
let fmt_content = bytify(raw_content);

self.fmt_contents.insert(proc.pid, fmt_content);
Expand Down
11 changes: 5 additions & 6 deletions src/columns/write_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::process::ProcessInfo;
use crate::util::bytify;
use crate::{column_default, Column};
use crate::{Column, column_default};
use std::cmp;
use std::collections::HashMap;

Expand Down Expand Up @@ -29,12 +29,11 @@ impl WriteBytes {
#[cfg(any(target_os = "linux", target_os = "android"))]
impl Column for WriteBytes {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if proc.curr_io.is_some() && proc.prev_io.is_some() {
let (fmt_content, raw_content) = if let Some(curr_io) = proc.curr_io
&& let Some(prev_io) = proc.prev_io
{
let interval_ms = proc.interval.as_secs() + u64::from(proc.interval.subsec_millis());
let io = (proc.curr_io.as_ref().unwrap().write_bytes
- proc.prev_io.as_ref().unwrap().write_bytes)
* 1000
/ interval_ms;
let io = (curr_io.write_bytes - prev_io.write_bytes) * 1000 / interval_ms;
(bytify(io), io)
} else {
(String::new(), 0)
Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use console::Term;
use std::cmp;
use std::collections::HashMap;
use std::fs;
use std::io::{stdout, Read};
use std::io::{Read, stdout};
use std::path::PathBuf;
use std::time::Instant;
use unicode_width::UnicodeWidthStr;
Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs"];
let args = ["procs"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -226,39 +226,39 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs", "root"];
let args = ["procs", "root"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "1"];
let args = ["procs", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "--or", "root", "1"];
let args = ["procs", "--or", "root", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "--and", "root", "1"];
let args = ["procs", "--and", "root", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "--nor", "root", "1"];
let args = ["procs", "--nor", "root", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "--nand", "root", "1"];
let args = ["procs", "--nand", "root", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

config.search.nonnumeric_search = ConfigSearchKind::Exact;
config.search.numeric_search = ConfigSearchKind::Partial;
let args = vec!["procs", "root", "1"];
let args = ["procs", "root", "1"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -276,7 +276,7 @@ mod tests {
config.display.cut_to_terminal = false;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs"];
let args = ["procs"];
let mut opt = Opt::parse_from(args.iter());
config.pager.mode = ConfigPagerMode::Disable;
let ret = run_default(&mut opt, &config);
Expand All @@ -289,7 +289,7 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs", "--insert", "ppid"];
let args = ["procs", "--insert", "ppid"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -301,12 +301,12 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs", "--sorta", "cpu"];
let args = ["procs", "--sorta", "cpu"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());

let args = vec!["procs", "--sortd", "cpu"];
let args = ["procs", "--sortd", "cpu"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -318,7 +318,7 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs", "--tree"];
let args = ["procs", "--tree"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -333,7 +333,7 @@ mod tests {
let _tcp = std::net::TcpListener::bind("127.0.0.1:10000");
let _udp = std::net::UdpSocket::bind("127.0.0.1:10000");

let args = vec!["procs"];
let args = ["procs"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand All @@ -345,7 +345,7 @@ mod tests {
config.pager.mode = ConfigPagerMode::Disable;
config.display.theme = ConfigTheme::Dark;

let args = vec!["procs", "--use-config", "large"];
let args = ["procs", "--use-config", "large"];
let mut opt = Opt::parse_from(args.iter());
let ret = run_default(&mut opt, &config);
assert!(ret.is_ok());
Expand Down
4 changes: 2 additions & 2 deletions src/opt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Error};
use clap::builder::styling::{AnsiColor, Effects, Styles};
use anyhow::{Error, anyhow};
use clap::CommandFactory;
use clap::builder::styling::{AnsiColor, Effects, Styles};
use clap::{Parser, ValueEnum};
use clap_complete::Shell;
use std::path::{Path, PathBuf};
Expand Down
16 changes: 6 additions & 10 deletions src/process/linux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use procfs::process::{FDInfo, Io, Process, Stat, Status, TasksIter};
use procfs::ProcError;
use procfs::ProcessCGroup;
use procfs::process::{FDInfo, Io, Process, Stat, Status, TasksIter};
use std::collections::HashMap;
use std::path::PathBuf;
use std::thread;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn collect_proc(
let mut base_tasks = HashMap::new();
let mut ret = Vec::new();

let all_proc = if let Some(ref x) = procfs_path {
let all_proc = if let Some(x) = procfs_path {
procfs::process::all_processes_with_root(x)
} else {
procfs::process::all_processes()
Expand All @@ -101,10 +101,8 @@ pub fn collect_proc(
if let Ok(stat) = proc.stat() {
let io = proc.io().ok();
let time = Instant::now();
if with_thread {
if let Ok(iter) = proc.tasks() {
collect_task(iter, &mut base_tasks);
}
if with_thread && let Ok(iter) = proc.tasks() {
collect_task(iter, &mut base_tasks);
}
base_procs.push((proc.pid(), stat, io, time));
}
Expand Down Expand Up @@ -143,10 +141,8 @@ pub fn collect_proc(
}

let mut curr_tasks = HashMap::new();
if with_thread {
if let Ok(iter) = curr_proc.tasks() {
collect_task(iter, &mut curr_tasks);
}
if with_thread && let Ok(iter) = curr_proc.tasks() {
collect_task(iter, &mut curr_tasks);
}

let curr_proc = ProcessTask::Process {
Expand Down
Loading