Skip to content

Commit 32f64f4

Browse files
authored
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
1 parent 3967285 commit 32f64f4

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Bug Fixes
1515

1616
- [#1541](https://github.com/ClementTsang/bottom/pull/1541): Fix some process details not updating for macOS and Windows.
17+
- [#1542](https://github.com/ClementTsang/bottom/pull/1542): Fix confusing process run times being reported on macOS.
1718
- [#1543](https://github.com/ClementTsang/bottom/pull/1543): Fix the `--default_cpu_entry` argument not being checked.
1819

1920
## [0.10.1] - 2024-08-01

src/data_collection/processes/unix/process_ext.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ pub(crate) trait UnixProcessExt {
9090
.ok()
9191
})
9292
.unwrap_or_else(|| "N/A".into()),
93-
time: Duration::from_secs(process_val.run_time()),
93+
time: if process_val.start_time() == 0 {
94+
// Workaround for sysinfo occasionally returning a start time equal to UNIX
95+
// epoch, giving a run time in the range of 50+ years. We just
96+
// return a time of zero in this case for simplicity.
97+
//
98+
// TODO: Maybe return an option instead?
99+
Duration::ZERO
100+
} else {
101+
Duration::from_secs(process_val.run_time())
102+
},
94103
#[cfg(feature = "gpu")]
95104
gpu_mem: 0,
96105
#[cfg(feature = "gpu")]

src/data_collection/processes/windows.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ pub fn sysinfo_process_data(
104104
.and_then(|uid| users.get_user_by_id(uid))
105105
.map_or_else(|| "N/A".into(), |user| user.name().to_owned().into()),
106106
time: if process_val.start_time() == 0 {
107-
// Workaround for Windows occasionally returning a start time equal to UNIX
107+
// Workaround for sysinfo occasionally returning a start time equal to UNIX
108108
// epoch, giving a run time in the range of 50+ years. We just
109109
// return a time of zero in this case for simplicity.
110+
//
111+
// TODO: Maybe return an option instead?
110112
Duration::ZERO
111113
} else {
112114
Duration::from_secs(process_val.run_time())

0 commit comments

Comments
 (0)