don't log shrink metrics on first call (#17328)

* don't log shrink metrics on first call

* simplify logic
This commit is contained in:
Jeff Washington (jwash) 2021-05-19 19:15:35 -05:00 committed by GitHub
parent 32ec8341f9
commit a544010b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -1057,13 +1057,17 @@ impl ShrinkStats {
let last = self.last_report.load(Ordering::Relaxed); let last = self.last_report.load(Ordering::Relaxed);
let now = solana_sdk::timing::timestamp(); let now = solana_sdk::timing::timestamp();
// 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 is_first_call = last == 0;
let should_report = now.saturating_sub(last) > 1000 let should_report = now.saturating_sub(last) > 1000
&& self && self
.last_report .last_report
.compare_exchange(last, now, Ordering::Relaxed, Ordering::Relaxed) .compare_exchange(last, now, Ordering::Relaxed, Ordering::Relaxed)
== Ok(last); == Ok(last);
if should_report { if !is_first_call && should_report {
datapoint_info!( datapoint_info!(
"shrink_stats", "shrink_stats",
( (