Skip to content

Commit

Permalink
Use human readable durations for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed Feb 9, 2021
1 parent 69ad0bc commit c87028a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license = "MIT"
[dependencies]
log = "0.4"
rand = "0.8"
humantime = "2.1"
async-lock = "2.3"
async-timer = "0.7"

Expand Down
14 changes: 7 additions & 7 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ where
/// cache storing expired entries (assuming the monitor just ran), so make sure
/// to tune your frequency, sample size, and threshold accordingly.
pub async fn purge(&self, sample: usize, threshold: f64) {
let started = Instant::now();
let start = Instant::now();
let locked = Duration::from_nanos(0);

let mut locked = 0;
let mut removed = 0;

loop {
Expand Down Expand Up @@ -228,8 +228,8 @@ where
store.remove(key);
}

// increment the lock timer in millis
locked += acquired.elapsed().as_millis();
// increment the lock timer tracking directly
locked.checked_add(acquired.elapsed()).unwrap();
}

// log out now many of the sampled keys were removed
Expand All @@ -254,11 +254,11 @@ where

// log out the completion as well as the time taken in millis
debug!(
"{}purge loop removed {} entries in {}ms ({}ms locked)",
"{}purge loop removed {} entries in {} ({} locked)",
self.label,
removed,
started.elapsed().as_millis(),
locked
humantime::format_duration(start.elapsed()),
humantime::format_duration(locked)
);
}

Expand Down

0 comments on commit c87028a

Please sign in to comment.