Skip to content

Commit ccf855e

Browse files
authored
stats: only expose busy_duration_total (#4223)
1 parent 579f611 commit ccf855e

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

tokio/src/runtime/stats/stats.rs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ pub struct WorkerStats {
1717
park_count: AtomicU64,
1818
steal_count: AtomicU64,
1919
poll_count: AtomicU64,
20-
busy_duration_min: AtomicU64,
21-
busy_duration_max: AtomicU64,
22-
busy_duration_last: AtomicU64,
2320
busy_duration_total: AtomicU64,
2421
}
2522

@@ -31,9 +28,6 @@ impl RuntimeStats {
3128
park_count: AtomicU64::new(0),
3229
steal_count: AtomicU64::new(0),
3330
poll_count: AtomicU64::new(0),
34-
busy_duration_min: AtomicU64::new(0),
35-
busy_duration_max: AtomicU64::new(0),
36-
busy_duration_last: AtomicU64::new(0),
3731
busy_duration_total: AtomicU64::new(0),
3832
});
3933
}
@@ -66,39 +60,17 @@ impl WorkerStats {
6660
self.poll_count.load(Relaxed)
6761
}
6862

69-
/// Returns the duration for which the runtime was busy last time it was busy.
70-
pub fn busy_duration_last(&self) -> Duration {
71-
Duration::from_nanos(self.busy_duration_last.load(Relaxed))
72-
}
73-
7463
/// Returns the total amount of time this worker has been busy for.
75-
pub fn busy_duration_total(&self) -> Duration {
64+
pub fn total_busy_duration(&self) -> Duration {
7665
Duration::from_nanos(self.busy_duration_total.load(Relaxed))
7766
}
78-
79-
/// Returns the smallest busy duration since the last 16 parks.
80-
pub fn busy_duration_min(&self) -> Duration {
81-
Duration::from_nanos(self.busy_duration_min.load(Relaxed))
82-
}
83-
84-
/// Returns the largest busy duration since the last 16 parks.
85-
pub fn busy_duration_max(&self) -> Duration {
86-
Duration::from_nanos(self.busy_duration_max.load(Relaxed))
87-
}
8867
}
8968

9069
pub(crate) struct WorkerStatsBatcher {
9170
my_index: usize,
9271
park_count: u64,
9372
steal_count: u64,
9473
poll_count: u64,
95-
/// The last 16 busy durations in nanoseconds.
96-
///
97-
/// This array is set to contain the same value 16 times after the first
98-
/// iteration. Since we only publish the min, max and last value in the
99-
/// array, then this gives the correct result.
100-
busy_duration: [u64; 16],
101-
busy_duration_i: usize,
10274
/// The total busy duration in nanoseconds.
10375
busy_duration_total: u64,
10476
last_resume_time: Instant,
@@ -111,8 +83,6 @@ impl WorkerStatsBatcher {
11183
park_count: 0,
11284
steal_count: 0,
11385
poll_count: 0,
114-
busy_duration: [0; 16],
115-
busy_duration_i: usize::MAX,
11686
busy_duration_total: 0,
11787
last_resume_time: Instant::now(),
11888
}
@@ -124,20 +94,6 @@ impl WorkerStatsBatcher {
12494
worker.steal_count.store(self.steal_count, Relaxed);
12595
worker.poll_count.store(self.poll_count, Relaxed);
12696

127-
let mut min = u64::MAX;
128-
let mut max = 0;
129-
let last = self.busy_duration[self.busy_duration_i % 16];
130-
for &val in &self.busy_duration {
131-
if val <= min {
132-
min = val;
133-
}
134-
if val >= max {
135-
max = val;
136-
}
137-
}
138-
worker.busy_duration_min.store(min, Relaxed);
139-
worker.busy_duration_max.store(max, Relaxed);
140-
worker.busy_duration_last.store(last, Relaxed);
14197
worker
14298
.busy_duration_total
14399
.store(self.busy_duration_total, Relaxed);
@@ -149,15 +105,6 @@ impl WorkerStatsBatcher {
149105
let busy_duration = self.last_resume_time.elapsed();
150106
let busy_duration = u64::try_from(busy_duration.as_nanos()).unwrap_or(u64::MAX);
151107
self.busy_duration_total += busy_duration;
152-
if self.busy_duration_i == usize::MAX {
153-
// We are parking for the first time. Set array to contain current
154-
// duration in every slot.
155-
self.busy_duration_i = 0;
156-
self.busy_duration = [busy_duration; 16];
157-
} else {
158-
self.busy_duration_i = (self.busy_duration_i + 1) % 16;
159-
self.busy_duration[self.busy_duration_i] = busy_duration;
160-
}
161108
}
162109

163110
pub(crate) fn returned_from_park(&mut self) {

0 commit comments

Comments
 (0)