pstats: Timeline: show longer collector name if there's room

Similar to what we're doing on the flame graph now

Also, tweak tooltip message for collectors that overlap frame boundary if it's partially on a dropped frame, so that it isn't misleading
This commit is contained in:
rdb 2022-12-03 21:43:33 +01:00
parent cb0d52b1b5
commit d6055cc927
2 changed files with 30 additions and 7 deletions

View File

@ -228,14 +228,25 @@ draw_bar(int row, int from_x, int to_x, int collector_index,
double text_top = top + (bottom - top - text_height) / 2.0; double text_top = top + (bottom - top - text_height) / 2.0;
if (text_width >= text_right - text_left) { if (text_width >= text_right - text_left) {
size_t c = collector_name.rfind(':');
if (text_right - text_left < scale * 6) { if (text_right - text_left < scale * 6) {
// It's a really tiny space. Draw a single letter. // It's a really tiny space. Draw a single letter.
const char *ch = collector_name.data() + (c != std::string::npos ? c + 1 : 0);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_text(layout, collector_name.c_str(), 1); pango_layout_set_text(layout, ch, 1);
} else { } else {
// It's going to be tricky to fit it, let pango figure it out. // Maybe just use everything after the last colon.
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); if (c != std::string::npos) {
pango_layout_set_text(layout, collector_name.data() + c + 1,
collector_name.size() - c - 1);
pango_layout_get_pixel_size(layout, &text_width, &text_height);
}
} }
}
if (text_width >= text_right - text_left) {
// It's going to be tricky to fit it, let pango figure it out.
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
pango_layout_set_width(layout, (text_right - text_left) * PANGO_SCALE); pango_layout_set_width(layout, (text_right - text_left) * PANGO_SCALE);
cairo_move_to(_cr, text_left, text_top); cairo_move_to(_cr, text_left, text_top);
} }

View File

@ -381,7 +381,11 @@ get_bar_tooltip(int row, int x) const {
if (client_data != nullptr && client_data->has_collector(bar._collector_index)) { if (client_data != nullptr && client_data->has_collector(bar._collector_index)) {
std::ostringstream text; std::ostringstream text;
text << client_data->get_collector_fullname(bar._collector_index); text << client_data->get_collector_fullname(bar._collector_index);
text << " (" << format_number(bar._end - bar._start, GBU_show_units | GBU_ms) << ")"; text << " (";
if (bar._open_begin || bar._open_end) {
text << "at least ";
}
text << format_number(bar._end - bar._start, GBU_show_units | GBU_ms) << ")";
return text.str(); return text.str();
} }
} }
@ -669,9 +673,17 @@ draw_row(int thread_index, int row_index, double start_time, double end_time) {
if (to_x >= 0 && to_x > from_x && from_x < get_xsize()) { if (to_x >= 0 && to_x > from_x && from_x < get_xsize()) {
if (bar._collector_index != 0) { if (bar._collector_index != 0) {
draw_bar(thread_row._row_offset + row_index, from_x, to_x, const PStatCollectorDef &def = client_data->get_collector_def(bar._collector_index);
bar._collector_index, if (to_x - from_x >= 32 && def._parent_index > 0) {
client_data->get_collector_name(bar._collector_index)); // Try including the parent name.
const PStatCollectorDef &parent_def = client_data->get_collector_def(def._parent_index);
std::string long_name = parent_def._name + ":" + def._name;
draw_bar(thread_row._row_offset + row_index, from_x, to_x,
bar._collector_index, long_name);
} else {
draw_bar(thread_row._row_offset + row_index, from_x, to_x,
bar._collector_index, def._name);
}
} else { } else {
draw_bar(thread_row._row_offset + row_index, from_x, to_x, draw_bar(thread_row._row_offset + row_index, from_x, to_x,
bar._collector_index, bar._collector_index,