Remove unnecessary work from ps (#3407)

The ps plugin has an unnecessary call to `std:🧵:sleep(500ms)` that
delays runtime by 500ms. Additionally, there is a call to
`sysinfo::SystemExt::refresh_process`, which is not required as the previous
call to sysinfo::SystemExt::refresh_all handles the "refresh" of all processes
without a need to do this individually. Combining both of these improvements
means that running ps runs nearly instentaneously.

Fixes #3402
This commit is contained in:
Nate Mara 2021-05-11 00:59:24 -07:00 committed by GitHub
parent 48128c9db6
commit b93b80ccaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,15 +15,12 @@ impl Ps {
pub async fn ps(tag: Tag, long: bool) -> Result<Vec<Value>, ShellError> {
let mut sys = System::new_all();
sys.refresh_all();
let duration = std::time::Duration::from_millis(500);
std::thread::sleep(duration);
let mut output = vec![];
let result: Vec<_> = sys.get_processes().iter().map(|x| *x.0).collect();
for pid in result.into_iter() {
sys.refresh_process(pid);
if let Some(result) = sys.get_process(pid) {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("pid", UntaggedValue::int(pid));