Skip to content

Commit

Permalink
Smarter counter measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicEric committed Nov 28, 2024
1 parent c0b0252 commit dc0680f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ impl Counter {
let Some(element) = self.history.front() else {
break self.count;
};
if element.0.elapsed() < self.window {
if element.1 == self.count {
self.history.pop_front();
break self.count;
} else if element.0.elapsed() < self.window {
break element.1;
} else {
self.history.pop_front();
}
};
self.history.push_back((Instant::now(), self.count));
if let Some(element) = self.history.back() {
if element.1 != self.count {
self.history.push_back((Instant::now(), self.count));
}
} else {
self.history.push_back((Instant::now(), self.count));
}
(self.count - delta) as f64 / self.period
}
}
Expand Down

0 comments on commit dc0680f

Please sign in to comment.