From 284ffe9e835d4e432f43f723938706ca3580dcb6 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 22 Feb 2022 15:25:52 +0100 Subject: [PATCH] pstats: Fix status bar when collector has level data on multiple threads Status bar now shows total across all threads, and double-clicking it opens strip charts for all the threads that have data for it --- pandatool/src/gtk-stats/gtkStatsMonitor.cxx | 19 +++++++++++++++++++ pandatool/src/win-stats/winStatsMonitor.cxx | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/pandatool/src/gtk-stats/gtkStatsMonitor.cxx b/pandatool/src/gtk-stats/gtkStatsMonitor.cxx index ff41ed3a3f..9a04cc523a 100644 --- a/pandatool/src/gtk-stats/gtkStatsMonitor.cxx +++ b/pandatool/src/gtk-stats/gtkStatsMonitor.cxx @@ -637,6 +637,7 @@ update_status_bar() { if (thread_data == nullptr || thread_data->is_empty()) { return; } + int frame_number = thread_data->get_latest_frame_number(); const PStatFrameData &frame_data = thread_data->get_latest_frame(); pvector collectors; @@ -666,6 +667,13 @@ update_status_bar() { } } + // Add the value for other threads that have this collector. + for (int thread_index = 1; thread_index < client_data->get_num_threads(); ++thread_index) { + PStatView &view = get_level_view(collector, thread_index); + view.set_to_frame(frame_number); + value += view.get_net_value(); + } + const PStatCollectorDef &def = client_data->get_collector_def(collector); std::string text = def._name; text += ": " + PStatGraph::format_number(value, PStatGraph::GBU_named | PStatGraph::GBU_show_units, def._level_units); @@ -720,6 +728,17 @@ status_bar_button_event(GtkWidget *widget, GdkEventButton *event, gpointer data) if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { monitor->open_strip_chart(0, collector, collector != 0); + + // Also open a strip chart for other threads with data for this + // collector. + if (collector != 0) { + for (int thread_index = 1; thread_index < client_data->get_num_threads(); ++thread_index) { + PStatView &view = monitor->get_level_view(collector, thread_index); + if (view.get_net_value() > 0.0) { + monitor->open_strip_chart(thread_index, collector, true); + } + } + } return TRUE; } else if (event->type == GDK_BUTTON_PRESS && event->button == 3 && index > 0) { diff --git a/pandatool/src/win-stats/winStatsMonitor.cxx b/pandatool/src/win-stats/winStatsMonitor.cxx index b6a80c7151..b8fade17f0 100644 --- a/pandatool/src/win-stats/winStatsMonitor.cxx +++ b/pandatool/src/win-stats/winStatsMonitor.cxx @@ -712,6 +712,7 @@ update_status_bar() { if (thread_data == nullptr || thread_data->is_empty()) { return; } + int frame_number = thread_data->get_latest_frame_number(); const PStatFrameData &frame_data = thread_data->get_latest_frame(); // Gather the top-level collector list. @@ -734,6 +735,13 @@ update_status_bar() { } } + // Add the value for other threads that have this collector. + for (int thread_index = 1; thread_index < client_data->get_num_threads(); ++thread_index) { + PStatView &view = get_level_view(collector, thread_index); + view.set_to_frame(frame_number); + value += view.get_net_value(); + } + const PStatCollectorDef &def = client_data->get_collector_def(collector); std::string text = "\t" + def._name; text += ": " + PStatGraph::format_number(value, PStatGraph::GBU_named | PStatGraph::GBU_show_units, def._level_units); @@ -944,6 +952,16 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { else if (mouse.dwItemSpec >= 1 && mouse.dwItemSpec <= _status_bar_collectors.size()) { int collector = _status_bar_collectors[mouse.dwItemSpec - 1]; open_strip_chart(0, collector, true); + + // Also open a strip chart for other threads with data for this + // collector. + const PStatClientData *client_data = get_client_data(); + for (int thread_index = 1; thread_index < client_data->get_num_threads(); ++thread_index) { + PStatView &view = get_level_view(collector, thread_index); + if (view.get_net_value() > 0.0) { + open_strip_chart(thread_index, collector, true); + } + } } return TRUE; }