From 36aec8b0147f8afbd99729af40c94eeb90d29e0d Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 29 Nov 2022 18:26:51 +0100 Subject: [PATCH] pstats: Show collector start count in mouse-over tooltips --- pandatool/src/pstatserver/pStatFlameGraph.cxx | 9 ++++++- pandatool/src/pstatserver/pStatFlameGraph.h | 1 + pandatool/src/pstatserver/pStatStripChart.cxx | 25 +++++++++++++++++-- pandatool/src/pstatserver/pStatStripChart.h | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pandatool/src/pstatserver/pStatFlameGraph.cxx b/pandatool/src/pstatserver/pStatFlameGraph.cxx index 14274f28dc..c57d257286 100644 --- a/pandatool/src/pstatserver/pStatFlameGraph.cxx +++ b/pandatool/src/pstatserver/pStatFlameGraph.cxx @@ -166,7 +166,11 @@ get_bar_tooltip(int depth, int x) const { if (client_data != nullptr && client_data->has_collector(level->_collector_index)) { std::ostringstream text; text << client_data->get_collector_fullname(level->_collector_index); - text << " (" << format_number(level->get_net_value(_average_mode), GBU_show_units | GBU_ms) << ")"; + text << " (" << format_number(level->get_net_value(_average_mode), GBU_show_units | GBU_ms); + if (level->_count > 1) { + text << " / " << level->_count << "x"; + } + text << ")"; return text.str(); } } @@ -399,6 +403,7 @@ void PStatFlameGraph::StackLevel:: reset() { _start_time = 0.0; _net_value = 0.0; + _count = 0; _started = false; for (auto &item : _children) { @@ -416,6 +421,7 @@ start(int collector_index, double time) { child._parent = this; child._collector_index = collector_index; child._start_time = std::max(_start_time, time); + child._count++; child._started = true; return &child; } @@ -529,6 +535,7 @@ locate(int depth, double time, bool average) const { void PStatFlameGraph::StackLevel:: clear() { _children.clear(); + _count = 0; _net_value = 0.0; } diff --git a/pandatool/src/pstatserver/pStatFlameGraph.h b/pandatool/src/pstatserver/pStatFlameGraph.h index f1efd96e11..721651e43d 100644 --- a/pandatool/src/pstatserver/pStatFlameGraph.h +++ b/pandatool/src/pstatserver/pStatFlameGraph.h @@ -107,6 +107,7 @@ private: double _values[_num_average_frames] = {0.0}; double _start_time = 0.0; + int _count = 0; bool _started = false; int _collector_index = -1; diff --git a/pandatool/src/pstatserver/pStatStripChart.cxx b/pandatool/src/pstatserver/pStatStripChart.cxx index 530916cd97..82df337bd9 100644 --- a/pandatool/src/pstatserver/pStatStripChart.cxx +++ b/pandatool/src/pstatserver/pStatStripChart.cxx @@ -332,6 +332,8 @@ get_label_tooltip(int collector_index) const { return std::string(); } + const PStatThreadData *thread_data = _view.get_thread_data(); + std::ostringstream text; text << client_data->get_collector_fullname(collector_index); @@ -340,7 +342,6 @@ get_label_tooltip(int collector_index) const { value = get_average_net_value(); } else { - const PStatThreadData *thread_data = _view.get_thread_data(); int now_i, then_i; if (!thread_data->get_elapsed_frames(then_i, now_i)) { return text.str(); @@ -385,7 +386,22 @@ get_label_tooltip(int collector_index) const { value = net_value / net_time; } - text << " (" << format_number(value, get_guide_bar_units(), get_guide_bar_unit_name()) << ")"; + text << " (" << format_number(value, get_guide_bar_units(), get_guide_bar_unit_name()); + + if (collector_index != 0) { + const FrameData &frame = get_frame_data(thread_data->get_latest_frame_number()); + + for (const ColorData &cd : frame) { + if (cd._collector_index == collector_index) { + if (cd._count > 0) { + text << " / " << cd._count << "x"; + } + break; + } + } + } + + text << ")"; return text.str(); } @@ -505,6 +521,7 @@ accumulate_frame_data(FrameData &fdata, const FrameData &additional, ColorData scaled; scaled._collector_index = (*bi)._collector_index; scaled._i = (*bi)._i; + scaled._count = 0; scaled._net_value = (*bi)._net_value * weight; result.push_back(scaled); ++bi; @@ -514,6 +531,7 @@ accumulate_frame_data(FrameData &fdata, const FrameData &additional, ColorData combined; combined._collector_index = (*ai)._collector_index; combined._i = (*bi)._i; + combined._count = 0; combined._net_value = (*ai)._net_value + (*bi)._net_value * weight; result.push_back(combined); ++ai; @@ -532,6 +550,7 @@ accumulate_frame_data(FrameData &fdata, const FrameData &additional, ColorData scaled; scaled._collector_index = (*bi)._collector_index; scaled._i = (*bi)._i; + scaled._count = 0; scaled._net_value = (*bi)._net_value * weight; result.push_back(scaled); ++bi; @@ -577,6 +596,7 @@ get_frame_data(int frame_number) const { ColorData cd; cd._collector_index = (unsigned short)child->get_collector(); cd._i = (unsigned short)i; + cd._count = child->get_count(); cd._net_value = child->get_net_value(); if (cd._net_value != 0.0) { fdata.push_back(cd); @@ -588,6 +608,7 @@ get_frame_data(int frame_number) const { ColorData cd; cd._collector_index = (unsigned short)level->get_collector(); cd._i = (unsigned short)num_children; + cd._count = level->get_count(); cd._net_value = level->get_value_alone(); if (cd._net_value > 0.0) { fdata.push_back(cd); diff --git a/pandatool/src/pstatserver/pStatStripChart.h b/pandatool/src/pstatserver/pStatStripChart.h index 7a6a4924ca..e8bd39f84d 100644 --- a/pandatool/src/pstatserver/pStatStripChart.h +++ b/pandatool/src/pstatserver/pStatStripChart.h @@ -83,6 +83,7 @@ protected: public: unsigned short _collector_index; unsigned short _i; + int _count; double _net_value; }; typedef pvector FrameData;