From 32f64f4d52a0135acd9c5f1a15e97d60cf539d2e Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 6 Aug 2024 00:15:22 +0000 Subject: [PATCH] bug: fix occasionally wrong run time reported by sysinfo (#1542) * bug: fix occasionally wrong runtime reported by sysinfo Seems like on other platforms, sysinfo will sometimes report a run time that starts from UNIX epoch - this gives a non-sensical value of 19000+ days, and it at least looks a little more reasonable to just return 0 in this case. I guess we can also make it return N/A in the future but this is a quick fix for now. * update changelog --- CHANGELOG.md | 1 + src/data_collection/processes/unix/process_ext.rs | 11 ++++++++++- src/data_collection/processes/windows.rs | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 745183086..e193b40a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes - [#1541](https://github.com/ClementTsang/bottom/pull/1541): Fix some process details not updating for macOS and Windows. +- [#1542](https://github.com/ClementTsang/bottom/pull/1542): Fix confusing process run times being reported on macOS. - [#1543](https://github.com/ClementTsang/bottom/pull/1543): Fix the `--default_cpu_entry` argument not being checked. ## [0.10.1] - 2024-08-01 diff --git a/src/data_collection/processes/unix/process_ext.rs b/src/data_collection/processes/unix/process_ext.rs index 953549ebc..322f56a43 100644 --- a/src/data_collection/processes/unix/process_ext.rs +++ b/src/data_collection/processes/unix/process_ext.rs @@ -90,7 +90,16 @@ pub(crate) trait UnixProcessExt { .ok() }) .unwrap_or_else(|| "N/A".into()), - time: Duration::from_secs(process_val.run_time()), + time: if process_val.start_time() == 0 { + // Workaround for sysinfo occasionally returning a start time equal to UNIX + // epoch, giving a run time in the range of 50+ years. We just + // return a time of zero in this case for simplicity. + // + // TODO: Maybe return an option instead? + Duration::ZERO + } else { + Duration::from_secs(process_val.run_time()) + }, #[cfg(feature = "gpu")] gpu_mem: 0, #[cfg(feature = "gpu")] diff --git a/src/data_collection/processes/windows.rs b/src/data_collection/processes/windows.rs index ba6be2b83..a597f264b 100644 --- a/src/data_collection/processes/windows.rs +++ b/src/data_collection/processes/windows.rs @@ -104,9 +104,11 @@ pub fn sysinfo_process_data( .and_then(|uid| users.get_user_by_id(uid)) .map_or_else(|| "N/A".into(), |user| user.name().to_owned().into()), time: if process_val.start_time() == 0 { - // Workaround for Windows occasionally returning a start time equal to UNIX + // Workaround for sysinfo occasionally returning a start time equal to UNIX // epoch, giving a run time in the range of 50+ years. We just // return a time of zero in this case for simplicity. + // + // TODO: Maybe return an option instead? Duration::ZERO } else { Duration::from_secs(process_val.run_time())