Skip to content

Commit

Permalink
Fix possible numeric underflow in sampler:43
Browse files Browse the repository at this point in the history
Fixes:
thread 'main' panicked at 'attempt to subtract with overflow', src/sampler.rs:43:44
  • Loading branch information
pkolaczk committed Jan 7, 2022
1 parent 8fc3b1d commit 728a555
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl<'a> Sampler<'a> {
/// Should be called when a workload iteration finished.
/// If there comes the time, it will send the stats to the output.
pub async fn cycle_completed(&mut self, cycle: u64, now: Instant) {
let current_interval_duration = now - self.last_snapshot_time;
let current_interval_cycle_count = cycle - self.last_snapshot_cycle;
let current_interval_duration = now.saturating_duration_since(self.last_snapshot_time);
let current_interval_cycle_count = cycle.saturating_sub(self.last_snapshot_cycle);

// Don't snapshot if we're too close to the end of the run,
// to avoid excessively small samples:
Expand Down

0 comments on commit 728a555

Please sign in to comment.