Skip to content

Commit

Permalink
simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed May 19, 2021
1 parent 51e1071 commit c58af22
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,17 +1060,14 @@ impl ShrinkStats {
// last is initialized to 0 by ::default()
// thus, the first 'report' call would always log.
// Instead, the first call now initialializes 'last_report' to now.
let first_call = last == 0;
let time_elapsed = !first_call && now.saturating_sub(last) > 1000;
let should_report = (first_call || time_elapsed) && {
let we_exchanged =
self.last_report
.compare_exchange(last, now, Ordering::Relaxed, Ordering::Relaxed)
== Ok(last);
we_exchanged && !first_call
};

if should_report {
let is_first_call = last == 0;
let should_report = now.saturating_sub(last) > 1000
&& self
.last_report
.compare_exchange(last, now, Ordering::Relaxed, Ordering::Relaxed)
== Ok(last);

if !is_first_call && should_report {
datapoint_info!(
"shrink_stats",
(
Expand Down

0 comments on commit c58af22

Please sign in to comment.