Seems ps still needs a delay to be accurate (#484)

This commit is contained in:
JT 2021-12-13 16:28:35 +11:00 committed by GitHub
parent 2013e9300a
commit 1336acd34a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

4
Cargo.lock generated
View File

@ -2896,9 +2896,9 @@ dependencies = [
[[package]] [[package]]
name = "sysinfo" name = "sysinfo"
version = "0.20.5" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e223c65cd36b485a34c2ce6e38efa40777d31c4166d9076030c74cdcf971679f" checksum = "8f88d66f3341b688163d3585037954ff276cf24a234d015b30025318a3e3449a"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"core-foundation-sys", "core-foundation-sys",

View File

@ -23,7 +23,7 @@ csv = "1.1.3"
glob = "0.3.0" glob = "0.3.0"
Inflector = "0.11" Inflector = "0.11"
thiserror = "1.0.29" thiserror = "1.0.29"
sysinfo = "0.20.4" sysinfo = "0.21.2"
chrono = { version = "0.4.19", features = ["serde"] } chrono = { version = "0.4.19", features = ["serde"] }
chrono-humanize = "0.2.1" chrono-humanize = "0.2.1"
chrono-tz = "0.6.0" chrono-tz = "0.6.0"

View File

@ -54,11 +54,15 @@ fn run_ps(engine_state: &EngineState, call: &Call) -> Result<PipelineData, Shell
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_all(); sys.refresh_all();
let duration = std::time::Duration::from_millis(500);
std::thread::sleep(duration);
let mut output = vec![]; let mut output = vec![];
let result: Vec<_> = sys.processes().iter().map(|x| *x.0).collect(); let result: Vec<_> = sys.processes().iter().map(|x| *x.0).collect();
for pid in result { for pid in result {
sys.refresh_process(pid);
if let Some(result) = sys.process(pid) { if let Some(result) = sys.process(pid) {
let mut cols = vec![]; let mut cols = vec![];
let mut vals = vec![]; let mut vals = vec![];