mirror of
https://github.com/nushell/nushell.git
synced 2024-12-26 08:59:12 +01:00
fix the ps command's virtual mem (#3007)
This commit is contained in:
parent
3083346884
commit
67aaf4cb2d
@ -17,39 +17,41 @@ pub async fn ps(tag: Tag, long: bool) -> Result<Vec<Value>, ShellError> {
|
|||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
let duration = std::time::Duration::from_millis(500);
|
let duration = std::time::Duration::from_millis(500);
|
||||||
std::thread::sleep(duration);
|
std::thread::sleep(duration);
|
||||||
sys.refresh_all();
|
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
|
||||||
let result = sys.get_processes();
|
let result: Vec<_> = sys.get_processes().iter().map(|x| *x.0).collect();
|
||||||
|
|
||||||
for (pid, process) in result.iter() {
|
for pid in result.into_iter() {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
sys.refresh_process(pid);
|
||||||
dict.insert_untagged("pid", UntaggedValue::int(*pid));
|
if let Some(result) = sys.get_process(pid) {
|
||||||
dict.insert_untagged("name", UntaggedValue::string(process.name()));
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
dict.insert_untagged(
|
dict.insert_untagged("pid", UntaggedValue::int(pid));
|
||||||
"status",
|
dict.insert_untagged("name", UntaggedValue::string(result.name()));
|
||||||
UntaggedValue::string(format!("{:?}", process.status())),
|
dict.insert_untagged(
|
||||||
);
|
"status",
|
||||||
dict.insert_untagged(
|
UntaggedValue::string(format!("{:?}", result.status())),
|
||||||
"cpu",
|
);
|
||||||
UntaggedValue::decimal_from_float(process.cpu_usage() as f64, tag.span),
|
dict.insert_untagged(
|
||||||
);
|
"cpu",
|
||||||
dict.insert_untagged("mem", UntaggedValue::filesize(process.memory() * 1000));
|
UntaggedValue::decimal_from_float(result.cpu_usage() as f64, tag.span),
|
||||||
dict.insert_untagged(
|
);
|
||||||
"virtual",
|
dict.insert_untagged("mem", UntaggedValue::filesize(result.memory() * 1000));
|
||||||
UntaggedValue::filesize(process.virtual_memory() * 1000),
|
dict.insert_untagged(
|
||||||
);
|
"virtual",
|
||||||
|
UntaggedValue::filesize(result.virtual_memory() * 1000),
|
||||||
|
);
|
||||||
|
|
||||||
if long {
|
if long {
|
||||||
if let Some(parent) = process.parent() {
|
if let Some(parent) = result.parent() {
|
||||||
dict.insert_untagged("parent", UntaggedValue::int(parent));
|
dict.insert_untagged("parent", UntaggedValue::int(parent));
|
||||||
|
}
|
||||||
|
dict.insert_untagged("exe", UntaggedValue::filepath(result.exe()));
|
||||||
|
dict.insert_untagged("command", UntaggedValue::string(result.cmd().join(" ")));
|
||||||
}
|
}
|
||||||
dict.insert_untagged("exe", UntaggedValue::filepath(process.exe()));
|
|
||||||
dict.insert_untagged("command", UntaggedValue::string(process.cmd().join(" ")));
|
|
||||||
}
|
|
||||||
|
|
||||||
output.push(dict.into_value());
|
output.push(dict.into_value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
|
Loading…
Reference in New Issue
Block a user