Skip to content

Commit

Permalink
fix(console): fix calculation of busy time during poll (#405)
Browse files Browse the repository at this point in the history
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 <eliza@buoyant.io>
  • Loading branch information
hds and hawkw committed Sep 29, 2023
1 parent a944dbc commit e2c536a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tokio-console/src/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ impl Task {
}

pub(crate) fn busy(&self, since: SystemTime) -> Duration {
if let (Some(last_poll_started), None) =
(self.stats.last_poll_started, self.stats.last_poll_ended)
{
// in this case the task is being polled at the moment
let current_time_in_poll = since.duration_since(last_poll_started).unwrap_or_default();
return self.stats.busy + current_time_in_poll;
if let Some(started) = self.stats.last_poll_started {
if self.stats.last_poll_started > self.stats.last_poll_ended {
// in this case the task is being polled at the moment
let current_time_in_poll = since.duration_since(started).unwrap_or_default();
return self.stats.busy + current_time_in_poll;
}
}
self.stats.busy
}
Expand Down

0 comments on commit e2c536a

Please sign in to comment.