From d6055cc927dbcb638fb7a14f37f391251c6d6901 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 3 Dec 2022 21:43:33 +0100 Subject: [PATCH] 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 --- pandatool/src/gtk-stats/gtkStatsTimeline.cxx | 17 ++++++++++++++--- pandatool/src/pstatserver/pStatTimeline.cxx | 20 ++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx index 21015080be..81b54319fd 100644 --- a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx +++ b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx @@ -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; if (text_width >= text_right - text_left) { + size_t c = collector_name.rfind(':'); if (text_right - text_left < scale * 6) { // 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_text(layout, collector_name.c_str(), 1); + pango_layout_set_text(layout, ch, 1); } else { - // It's going to be tricky to fit it, let pango figure it out. - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + // Maybe just use everything after the last colon. + 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); cairo_move_to(_cr, text_left, text_top); } diff --git a/pandatool/src/pstatserver/pStatTimeline.cxx b/pandatool/src/pstatserver/pStatTimeline.cxx index dd49584ff0..6ccb603d34 100644 --- a/pandatool/src/pstatserver/pStatTimeline.cxx +++ b/pandatool/src/pstatserver/pStatTimeline.cxx @@ -381,7 +381,11 @@ get_bar_tooltip(int row, int x) const { if (client_data != nullptr && client_data->has_collector(bar._collector_index)) { std::ostringstream text; 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(); } } @@ -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 (bar._collector_index != 0) { - draw_bar(thread_row._row_offset + row_index, from_x, to_x, - bar._collector_index, - client_data->get_collector_name(bar._collector_index)); + const PStatCollectorDef &def = client_data->get_collector_def(bar._collector_index); + if (to_x - from_x >= 32 && def._parent_index > 0) { + // 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 { draw_bar(thread_row._row_offset + row_index, from_x, to_x, bar._collector_index,