Skip to content

Commit

Permalink
bug: fix occasionally wrong run time reported by sysinfo (#1542)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ClementTsang authored Aug 6, 2024
1 parent 3967285 commit 32f64f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/data_collection/processes/unix/process_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 3 additions & 1 deletion src/data_collection/processes/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 32f64f4

Please sign in to comment.