Skip to content

Commit

Permalink
feat(console): add busy and idle percentages to task details (#137)
Browse files Browse the repository at this point in the history
This commit adds the percentage of a task's total lifetime that was
spent busy and idle to the task details screen, next to the busy and
idle time as durations. This should help make differences in scale
between these values clearer (which may not be immediately from the
durations due to differing units).

![image](https://user-images.githubusercontent.com/2796466/132955711-e553bc7a-e14d-4280-aa29-e8ace10c3fb0.png)

In the future, we may also want to add similar percentages to the task
list view, either as part of the `Busy` and `Idle` columns or as
separate columns?
  • Loading branch information
hawkw authored Sep 11, 2021
1 parent a6dce04 commit 73b6e45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions console/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ impl Percentage for u64 {
}
}

impl Percentage for f64 {
fn percent_of(self, total: Self) -> Self {
percentage(total, self)
}
}

pub(crate) fn percentage(total: f64, amount: f64) -> f64 {
debug_assert!(
total >= amount,
Expand Down
29 changes: 17 additions & 12 deletions console/src/view/task.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
input,
tasks::{Details, DetailsRef, Task},
util::Percentage,
view::{
self, bold,
mini_histogram::{HistogramMetadata, MiniHistogram},
Expand Down Expand Up @@ -154,22 +155,26 @@ impl TaskView {
if let Some(name) = task.name() {
metrics.push(Spans::from(vec![bold("Name: "), Span::raw(name)]));
}

metrics.push(Spans::from(vec![
bold("Target: "),
Span::raw(task.target()),
]));
metrics.push(Spans::from(vec![
bold("Total Time: "),
dur(styles, task.total(now)),
]));
metrics.push(Spans::from(vec![
bold("Busy: "),
dur(styles, task.busy(now)),
]));
metrics.push(Spans::from(vec![
bold("Idle: "),
dur(styles, task.idle(now)),
]));

let total = task.total(now);

let dur_percent = |name: &'static str, amt: Duration| -> Spans {
let percent = amt.as_secs_f64().percent_of(total.as_secs_f64());
Spans::from(vec![
bold(name),
dur(styles, amt),
Span::from(format!(" ({:.2}%)", percent)),
])
};

metrics.push(Spans::from(vec![bold("Total Time: "), dur(styles, total)]));
metrics.push(dur_percent("Busy: ", task.busy(now)));
metrics.push(dur_percent("Idle: ", task.idle(now)));

let mut waker_stats = vec![Spans::from(vec![
bold("Current wakers: "),
Expand Down

0 comments on commit 73b6e45

Please sign in to comment.