Skip to content

Commit e2c536a

Browse files
hdshawkw
andcommitted
fix(console): fix calculation of busy time during poll (#405)
The Console API specifies sending task busy duration only for completed polls, it doesn't include the time spent in the current poll if the task is active. Tokio Console then calculates the busy time including the time spent in the current poll - based on the last poll start and poll end times sent by the Console Subscriber. However, there was an error in the logic which determined when a task is being polled for the purpose of calculating the busy time. The logic only considered the first poll, when there was no recorded end poll time at all. This change adapts the logic so that it also considers the case where the last recorded poll start is later than the last recorded poll end. This indicates that the task is being polled. Co-authored-by: Eliza Weisman <[email protected]>
1 parent a944dbc commit e2c536a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tokio-console/src/state/tasks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,12 @@ impl Task {
321321
}
322322

323323
pub(crate) fn busy(&self, since: SystemTime) -> Duration {
324-
if let (Some(last_poll_started), None) =
325-
(self.stats.last_poll_started, self.stats.last_poll_ended)
326-
{
327-
// in this case the task is being polled at the moment
328-
let current_time_in_poll = since.duration_since(last_poll_started).unwrap_or_default();
329-
return self.stats.busy + current_time_in_poll;
324+
if let Some(started) = self.stats.last_poll_started {
325+
if self.stats.last_poll_started > self.stats.last_poll_ended {
326+
// in this case the task is being polled at the moment
327+
let current_time_in_poll = since.duration_since(started).unwrap_or_default();
328+
return self.stats.busy + current_time_in_poll;
329+
}
330330
}
331331
self.stats.busy
332332
}

0 commit comments

Comments
 (0)