Skip to content

Commit

Permalink
Use checked_sub duration ops for handling cpu time (#1926)
Browse files Browse the repository at this point in the history
This is never supposed to fail, but better check for it than avoiding it.

Fixes an issue reported in #1880.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Feb 15, 2023
1 parent 594ebde commit 7731fd2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions profiling/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,9 @@ impl Profiler {
let now = cpu_time::ThreadTime::try_now()
.expect("CPU time to work since it's worked before during this process");
let old_cpu_time = now
.duration_since(last_cpu_time)
.as_nanos()
.try_into()
.as_duration()
.checked_sub(last_cpu_time.as_duration())
.and_then(|t| t.as_nanos().try_into().ok())
.unwrap_or(i64::MAX);
cpu_time = old_cpu_time;
locals.last_cpu_time = Some(now);
Expand Down

0 comments on commit 7731fd2

Please sign in to comment.