Skip to content

Commit

Permalink
use safer duration for linux in case of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Apr 30, 2023
1 parent 0b74b9a commit 2e5d86f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/data_harvester/processes/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,15 @@ fn read_proc(

let uid = process.uid()?;

let time =
Duration::from_secs(stat.utime + stat.stime) / u32::try_from(procfs::ticks_per_second())?;
let time = if let Ok(ticks_per_sec) = u32::try_from(procfs::ticks_per_second()) {
if ticks_per_sec == 0 {
Duration::ZERO
} else {
Duration::from_secs(stat.utime + stat.stime) / ticks_per_sec
}
} else {
Duration::ZERO
};

Ok((
ProcessHarvest {
Expand Down

0 comments on commit 2e5d86f

Please sign in to comment.