mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 22:57:07 +02:00
add more columns to macos ps -l
(#15341)
# Description This PR adds a few more columns to the macos version of `ps -l` to bring it more inline with the Linux and Windows version. Columns added: user_id, priority, process_threads I also added some comments that describe the TaskInfo structure. I couldn't find any good information to add to the BSDInfo structure. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
820d0c0959
commit
862d53bb6e
@ -176,11 +176,14 @@ fn run_ps(
|
|||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
record.push("cwd", Value::string(proc.cwd(), span));
|
|
||||||
let timestamp = Local
|
let timestamp = Local
|
||||||
.timestamp_nanos(proc.start_time * 1_000_000_000)
|
.timestamp_nanos(proc.start_time * 1_000_000_000)
|
||||||
.into();
|
.into();
|
||||||
record.push("start_time", Value::date(timestamp, span));
|
record.push("start_time", Value::date(timestamp, span));
|
||||||
|
record.push("user_id", Value::int(proc.user_id, span));
|
||||||
|
record.push("priority", Value::int(proc.priority, span));
|
||||||
|
record.push("process_threads", Value::int(proc.task_thread_num, span));
|
||||||
|
record.push("cwd", Value::string(proc.cwd(), span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@ pub struct ProcessInfo {
|
|||||||
pub prev_res: Option<RUsageInfoV2>,
|
pub prev_res: Option<RUsageInfoV2>,
|
||||||
pub interval: Duration,
|
pub interval: Duration,
|
||||||
pub start_time: i64,
|
pub start_time: i64,
|
||||||
|
pub user_id: i64,
|
||||||
|
pub priority: i64,
|
||||||
|
pub task_thread_num: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo> {
|
pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo> {
|
||||||
@ -96,6 +99,9 @@ pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo>
|
|||||||
let interval = curr_time.saturating_duration_since(prev_time);
|
let interval = curr_time.saturating_duration_since(prev_time);
|
||||||
let ppid = curr_task.pbsd.pbi_ppid as i32;
|
let ppid = curr_task.pbsd.pbi_ppid as i32;
|
||||||
let start_time = curr_task.pbsd.pbi_start_tvsec as i64;
|
let start_time = curr_task.pbsd.pbi_start_tvsec as i64;
|
||||||
|
let user_id = curr_task.pbsd.pbi_uid as i64;
|
||||||
|
let priority = curr_task.ptinfo.pti_priority as i64;
|
||||||
|
let task_thread_num = curr_task.ptinfo.pti_threadnum as i64;
|
||||||
|
|
||||||
let proc = ProcessInfo {
|
let proc = ProcessInfo {
|
||||||
pid,
|
pid,
|
||||||
@ -110,6 +116,9 @@ pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec<ProcessInfo>
|
|||||||
prev_res,
|
prev_res,
|
||||||
interval,
|
interval,
|
||||||
start_time,
|
start_time,
|
||||||
|
user_id,
|
||||||
|
priority,
|
||||||
|
task_thread_num,
|
||||||
};
|
};
|
||||||
|
|
||||||
ret.push(proc);
|
ret.push(proc);
|
||||||
@ -276,24 +285,44 @@ fn clone_task_all_info(src: &TaskAllInfo) -> TaskAllInfo {
|
|||||||
pbi_start_tvsec: src.pbsd.pbi_start_tvsec,
|
pbi_start_tvsec: src.pbsd.pbi_start_tvsec,
|
||||||
pbi_start_tvusec: src.pbsd.pbi_start_tvusec,
|
pbi_start_tvusec: src.pbsd.pbi_start_tvusec,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Comments taken from here https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/sys/proc_info.h#L127
|
||||||
let ptinfo = TaskInfo {
|
let ptinfo = TaskInfo {
|
||||||
|
// virtual memory size (bytes)
|
||||||
pti_virtual_size: src.ptinfo.pti_virtual_size,
|
pti_virtual_size: src.ptinfo.pti_virtual_size,
|
||||||
|
// resident memory size (bytes)
|
||||||
pti_resident_size: src.ptinfo.pti_resident_size,
|
pti_resident_size: src.ptinfo.pti_resident_size,
|
||||||
|
// total user time
|
||||||
pti_total_user: src.ptinfo.pti_total_user,
|
pti_total_user: src.ptinfo.pti_total_user,
|
||||||
|
// total system time
|
||||||
pti_total_system: src.ptinfo.pti_total_system,
|
pti_total_system: src.ptinfo.pti_total_system,
|
||||||
|
// existing threads only user
|
||||||
pti_threads_user: src.ptinfo.pti_threads_user,
|
pti_threads_user: src.ptinfo.pti_threads_user,
|
||||||
|
// existing threads only system
|
||||||
pti_threads_system: src.ptinfo.pti_threads_system,
|
pti_threads_system: src.ptinfo.pti_threads_system,
|
||||||
|
// default policy for new threads
|
||||||
pti_policy: src.ptinfo.pti_policy,
|
pti_policy: src.ptinfo.pti_policy,
|
||||||
|
// number of page faults
|
||||||
pti_faults: src.ptinfo.pti_faults,
|
pti_faults: src.ptinfo.pti_faults,
|
||||||
|
// number of actual pageins
|
||||||
pti_pageins: src.ptinfo.pti_pageins,
|
pti_pageins: src.ptinfo.pti_pageins,
|
||||||
|
// number of copy-on-write faults
|
||||||
pti_cow_faults: src.ptinfo.pti_cow_faults,
|
pti_cow_faults: src.ptinfo.pti_cow_faults,
|
||||||
|
// number of messages sent
|
||||||
pti_messages_sent: src.ptinfo.pti_messages_sent,
|
pti_messages_sent: src.ptinfo.pti_messages_sent,
|
||||||
|
// number of messages received
|
||||||
pti_messages_received: src.ptinfo.pti_messages_received,
|
pti_messages_received: src.ptinfo.pti_messages_received,
|
||||||
|
// number of mach system calls
|
||||||
pti_syscalls_mach: src.ptinfo.pti_syscalls_mach,
|
pti_syscalls_mach: src.ptinfo.pti_syscalls_mach,
|
||||||
|
// number of unix system calls
|
||||||
pti_syscalls_unix: src.ptinfo.pti_syscalls_unix,
|
pti_syscalls_unix: src.ptinfo.pti_syscalls_unix,
|
||||||
|
// number of context switches
|
||||||
pti_csw: src.ptinfo.pti_csw,
|
pti_csw: src.ptinfo.pti_csw,
|
||||||
|
// number of threads in the task
|
||||||
pti_threadnum: src.ptinfo.pti_threadnum,
|
pti_threadnum: src.ptinfo.pti_threadnum,
|
||||||
|
// number of running threads
|
||||||
pti_numrunning: src.ptinfo.pti_numrunning,
|
pti_numrunning: src.ptinfo.pti_numrunning,
|
||||||
|
// task priority
|
||||||
pti_priority: src.ptinfo.pti_priority,
|
pti_priority: src.ptinfo.pti_priority,
|
||||||
};
|
};
|
||||||
TaskAllInfo { pbsd, ptinfo }
|
TaskAllInfo { pbsd, ptinfo }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user