From ccf855ec24db7e91af7d60d4524dcd44d25d98c2 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 11 Nov 2021 21:53:29 +0100 Subject: [PATCH] stats: only expose `busy_duration_total` (#4223) --- tokio/src/runtime/stats/stats.rs | 55 +------------------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/tokio/src/runtime/stats/stats.rs b/tokio/src/runtime/stats/stats.rs index 1dc184438..b2bcaccaa 100644 --- a/tokio/src/runtime/stats/stats.rs +++ b/tokio/src/runtime/stats/stats.rs @@ -17,9 +17,6 @@ pub struct WorkerStats { park_count: AtomicU64, steal_count: AtomicU64, poll_count: AtomicU64, - busy_duration_min: AtomicU64, - busy_duration_max: AtomicU64, - busy_duration_last: AtomicU64, busy_duration_total: AtomicU64, } @@ -31,9 +28,6 @@ impl RuntimeStats { park_count: AtomicU64::new(0), steal_count: AtomicU64::new(0), poll_count: AtomicU64::new(0), - busy_duration_min: AtomicU64::new(0), - busy_duration_max: AtomicU64::new(0), - busy_duration_last: AtomicU64::new(0), busy_duration_total: AtomicU64::new(0), }); } @@ -66,25 +60,10 @@ impl WorkerStats { self.poll_count.load(Relaxed) } - /// Returns the duration for which the runtime was busy last time it was busy. - pub fn busy_duration_last(&self) -> Duration { - Duration::from_nanos(self.busy_duration_last.load(Relaxed)) - } - /// Returns the total amount of time this worker has been busy for. - pub fn busy_duration_total(&self) -> Duration { + pub fn total_busy_duration(&self) -> Duration { Duration::from_nanos(self.busy_duration_total.load(Relaxed)) } - - /// Returns the smallest busy duration since the last 16 parks. - pub fn busy_duration_min(&self) -> Duration { - Duration::from_nanos(self.busy_duration_min.load(Relaxed)) - } - - /// Returns the largest busy duration since the last 16 parks. - pub fn busy_duration_max(&self) -> Duration { - Duration::from_nanos(self.busy_duration_max.load(Relaxed)) - } } pub(crate) struct WorkerStatsBatcher { @@ -92,13 +71,6 @@ pub(crate) struct WorkerStatsBatcher { park_count: u64, steal_count: u64, poll_count: u64, - /// The last 16 busy durations in nanoseconds. - /// - /// This array is set to contain the same value 16 times after the first - /// iteration. Since we only publish the min, max and last value in the - /// array, then this gives the correct result. - busy_duration: [u64; 16], - busy_duration_i: usize, /// The total busy duration in nanoseconds. busy_duration_total: u64, last_resume_time: Instant, @@ -111,8 +83,6 @@ impl WorkerStatsBatcher { park_count: 0, steal_count: 0, poll_count: 0, - busy_duration: [0; 16], - busy_duration_i: usize::MAX, busy_duration_total: 0, last_resume_time: Instant::now(), } @@ -124,20 +94,6 @@ impl WorkerStatsBatcher { worker.steal_count.store(self.steal_count, Relaxed); worker.poll_count.store(self.poll_count, Relaxed); - let mut min = u64::MAX; - let mut max = 0; - let last = self.busy_duration[self.busy_duration_i % 16]; - for &val in &self.busy_duration { - if val <= min { - min = val; - } - if val >= max { - max = val; - } - } - worker.busy_duration_min.store(min, Relaxed); - worker.busy_duration_max.store(max, Relaxed); - worker.busy_duration_last.store(last, Relaxed); worker .busy_duration_total .store(self.busy_duration_total, Relaxed); @@ -149,15 +105,6 @@ impl WorkerStatsBatcher { let busy_duration = self.last_resume_time.elapsed(); let busy_duration = u64::try_from(busy_duration.as_nanos()).unwrap_or(u64::MAX); self.busy_duration_total += busy_duration; - if self.busy_duration_i == usize::MAX { - // We are parking for the first time. Set array to contain current - // duration in every slot. - self.busy_duration_i = 0; - self.busy_duration = [busy_duration; 16]; - } else { - self.busy_duration_i = (self.busy_duration_i + 1) % 16; - self.busy_duration[self.busy_duration_i] = busy_duration; - } } pub(crate) fn returned_from_park(&mut self) {