Skip to content

Commit 35d675f

Browse files
authored
feat(console): nicer poll time layout in details view (console-rs#58)
This branch slightly improves the layout of the poll time stats in the task details view. Now, instead of doing a 50/50 horizontal split that requires us to break the percentiles into two columns, we do an asymmetrical horizontal split, and make the poll time area two lines longer. This allows us to fit the percentiles in a single column, and lets us draw a slightly bigger histogram (hopefully making it a little nicer to read). This also simplifies the code a little, since we can remove the code for splitting the poll time histogram area into two columns. Before: ![image](https://user-images.githubusercontent.com/2796466/124795284-b71e1f80-df04-11eb-87f4-6bb4e5b93518.png) After: ![image](https://user-images.githubusercontent.com/2796466/124795123-96ee6080-df04-11eb-839c-c1cd5be8a329.png)
1 parent 94e7834 commit 35d675f

File tree

1 file changed

+33
-60
lines changed

1 file changed

+33
-60
lines changed

console/src/view/task.rs

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TaskView {
5757
[
5858
layout::Constraint::Length(1),
5959
layout::Constraint::Length(6),
60-
layout::Constraint::Length(7),
60+
layout::Constraint::Length(9),
6161
layout::Constraint::Percentage(60),
6262
]
6363
.as_ref(),
@@ -80,29 +80,18 @@ impl TaskView {
8080
.direction(layout::Direction::Horizontal)
8181
.constraints(
8282
[
83-
layout::Constraint::Percentage(50),
84-
layout::Constraint::Percentage(50),
83+
// 24 chars is long enough for the title "Poll Times Percentiles"
84+
layout::Constraint::Max(24),
85+
layout::Constraint::Min(50),
8586
]
8687
.as_ref(),
8788
)
8889
.split(chunks[2]);
8990

90-
let percentiles_columns = Layout::default()
91-
.direction(layout::Direction::Horizontal)
92-
.constraints(
93-
[
94-
layout::Constraint::Percentage(50),
95-
layout::Constraint::Percentage(50),
96-
]
97-
.as_ref(),
98-
)
99-
.split(histogram_area[0].inner(&layout::Margin {
100-
horizontal: 1,
101-
vertical: 1,
102-
}));
91+
let percentiles_area = histogram_area[0];
92+
let sparkline_area = histogram_area[1];
10393

10494
let fields_area = chunks[3];
105-
let sparkline_area = histogram_area[1];
10695

10796
let controls = Spans::from(vec![
10897
Span::raw("controls: "),
@@ -191,21 +180,18 @@ impl TaskView {
191180
let task_widget = Paragraph::new(metrics).block(block_for("Task"));
192181
let wakers_widget = Paragraph::new(vec![wakers, wakeups]).block(block_for("Waker"));
193182
let fields_widget = Paragraph::new(fields).block(block_for("Fields"));
194-
195-
let percentiles_widget = block_for("Poll Times Percentiles");
196-
let (percentiles_1, percentiles_2) = details
197-
.map(|d| d.make_percentiles_widgets(5))
198-
.unwrap_or_default();
199-
let percentiles_widget_1 = Paragraph::new(percentiles_1);
200-
let percentiles_widget_2 = Paragraph::new(percentiles_2);
183+
let percentiles_widget = Paragraph::new(
184+
details
185+
.map(Details::make_percentiles_widget)
186+
.unwrap_or_default(),
187+
)
188+
.block(block_for("Poll Times Percentiles"));
201189

202190
frame.render_widget(Block::default().title(controls), controls_area);
203191
frame.render_widget(task_widget, stats_area[0]);
204192
frame.render_widget(wakers_widget, stats_area[1]);
205193
frame.render_widget(fields_widget, fields_area);
206-
frame.render_widget(percentiles_widget, histogram_area[0]);
207-
frame.render_widget(percentiles_widget_1, percentiles_columns[0]);
208-
frame.render_widget(percentiles_widget_2, percentiles_columns[1]);
194+
frame.render_widget(percentiles_widget, percentiles_area);
209195
frame.render_widget(histogram_sparkline, sparkline_area);
210196
}
211197
}
@@ -255,39 +241,26 @@ impl Details {
255241
.unwrap_or_default()
256242
}
257243

258-
/// Get the important percentile values from the histogram and make two paragraphs listing them
259-
fn make_percentiles_widgets(&self, column_height: usize) -> (Text<'static>, Text<'static>) {
260-
let percentiles_iter = self
261-
.poll_times_histogram()
262-
.map(|histogram| {
263-
[10f64, 25f64, 50f64, 75f64, 90f64, 95f64, 99f64]
264-
.iter()
265-
.map(move |i| (*i, histogram.value_at_percentile(*i)))
244+
/// Get the important percentile values from the histogram
245+
fn make_percentiles_widget(&self) -> Text<'static> {
246+
let mut text = Text::default();
247+
let histogram = self.poll_times_histogram();
248+
let percentiles = histogram.iter().flat_map(|histogram| {
249+
let pairs = [10f64, 25f64, 50f64, 75f64, 90f64, 95f64, 99f64]
250+
.iter()
251+
.map(move |i| (*i, histogram.value_at_percentile(*i)));
252+
pairs.map(|pair| {
253+
Spans::from(vec![
254+
bold(format!("p{:>2}: ", pair.0)),
255+
Span::from(format!(
256+
"{:.prec$?}",
257+
Duration::from_nanos(pair.1),
258+
prec = DUR_PRECISION,
259+
)),
260+
])
266261
})
267-
.map(|pairs| {
268-
pairs.map(|pair| {
269-
Spans::from(vec![
270-
bold(format!("p{:>2}: ", pair.0)),
271-
Span::from(format!(
272-
"{:.prec$?}",
273-
Duration::from_nanos(pair.1),
274-
prec = DUR_PRECISION,
275-
)),
276-
])
277-
})
278-
});
279-
280-
let mut percentiles_1 = Text::default();
281-
let mut percentiles_2 = Text::default();
282-
if let Some(mut percentiles_iter) = percentiles_iter {
283-
percentiles_1.extend(
284-
percentiles_iter
285-
.by_ref()
286-
.take(column_height)
287-
.map(Spans::from),
288-
);
289-
percentiles_2.extend(percentiles_iter.map(Spans::from));
290-
}
291-
(percentiles_1, percentiles_2)
262+
});
263+
text.extend(percentiles);
264+
text
292265
}
293266
}

0 commit comments

Comments
 (0)