From 09ab583f64b62274f1f05713be36f87a5b038d2a Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:55:30 -0500 Subject: [PATCH] add `start_time` to `ps -l` on macos (#14127) # Description This PR adds `start_time` to the MacOS `ps -l` command. Was requested in discord. `start_time` is displayed in `Local` time. ![image](https://github.com/user-attachments/assets/b3743cde-af43-4756-9e2a-54689104fb25) # User-Facing Changes # Tests + Formatting # After Submitting /cc @cablehead --- crates/nu-command/src/system/ps.rs | 6 ++++++ crates/nu-system/src/macos.rs | 3 +++ 2 files changed, 9 insertions(+) diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index 6f39061dab..cece41e56f 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -1,3 +1,5 @@ +#[cfg(target_os = "macos")] +use chrono::{Local, TimeZone}; #[cfg(windows)] use itertools::Itertools; use nu_engine::command_prelude::*; @@ -175,6 +177,10 @@ fn run_ps( #[cfg(target_os = "macos")] { record.push("cwd", Value::string(proc.cwd(), span)); + let timestamp = Local + .timestamp_nanos(proc.start_time * 1_000_000_000) + .into(); + record.push("start_time", Value::date(timestamp, span)); } } diff --git a/crates/nu-system/src/macos.rs b/crates/nu-system/src/macos.rs index e9b927c1fe..8d6ab59d4b 100644 --- a/crates/nu-system/src/macos.rs +++ b/crates/nu-system/src/macos.rs @@ -25,6 +25,7 @@ pub struct ProcessInfo { pub curr_res: Option, pub prev_res: Option, pub interval: Duration, + pub start_time: i64, } pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec { @@ -94,6 +95,7 @@ pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec let curr_time = Instant::now(); let interval = curr_time.saturating_duration_since(prev_time); let ppid = curr_task.pbsd.pbi_ppid as i32; + let start_time = curr_task.pbsd.pbi_start_tvsec as i64; let proc = ProcessInfo { pid, @@ -107,6 +109,7 @@ pub fn collect_proc(interval: Duration, _with_thread: bool) -> Vec curr_res, prev_res, interval, + start_time, }; ret.push(proc);