mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Merge branch 'master' of https://github.com/nushell/nushell
This commit is contained in:
@ -113,7 +113,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
||||
}
|
||||
Primitive::Duration(sec) => format_duration(*sec),
|
||||
Primitive::Int(i) => i.to_string(),
|
||||
Primitive::Decimal(decimal) => decimal.to_string(),
|
||||
Primitive::Decimal(decimal) => format!("{:.4}", decimal),
|
||||
Primitive::Range(range) => format!(
|
||||
"{}..{}",
|
||||
format_primitive(&range.from.0.item, None),
|
||||
|
@ -3,7 +3,7 @@ use futures::executor::block_on;
|
||||
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use heim::process::{self as process, Process, ProcessResult};
|
||||
use heim::units::{ratio, Ratio};
|
||||
use heim::units::{information, ratio, Ratio};
|
||||
use std::usize;
|
||||
|
||||
use nu_errors::ShellError;
|
||||
@ -22,12 +22,14 @@ impl Ps {
|
||||
}
|
||||
}
|
||||
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
|
||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
|
||||
let usage_1 = process.cpu_usage().await?;
|
||||
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
||||
let usage_2 = process.cpu_usage().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1))
|
||||
let memory = process.memory().await?;
|
||||
|
||||
Ok((process, usage_2 - usage_1, memory))
|
||||
}
|
||||
|
||||
async fn ps(tag: Tag) -> Vec<Value> {
|
||||
@ -43,7 +45,7 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
|
||||
let mut output = vec![];
|
||||
while let Some(res) = processes.next().await {
|
||||
if let Ok((process, usage)) = res {
|
||||
if let Ok((process, usage, memory)) = res {
|
||||
let mut dict = TaggedDictBuilder::new(&tag);
|
||||
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||
if let Ok(name) = process.name().await {
|
||||
@ -53,6 +55,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||
}
|
||||
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||
dict.insert_untagged(
|
||||
"mem",
|
||||
UntaggedValue::bytes(memory.rss().get::<information::byte>()),
|
||||
);
|
||||
dict.insert_untagged(
|
||||
"virtual",
|
||||
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
|
||||
);
|
||||
output.push(dict.into_value());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user