pstats: Fix hovering strip chart labels being excessively slow

Now properly uses the cached data rather than computing it on every mouseover
This commit is contained in:
rdb 2022-11-26 21:43:41 +01:00
parent f02a3156ca
commit 21cae91890
2 changed files with 27 additions and 29 deletions

View File

@ -333,20 +333,20 @@ get_label_tooltip(int collector_index) const {
double now = _time_width + _start_time; double now = _time_width + _start_time;
double then = now - pstats_average_time; double then = now - pstats_average_time;
double net_value = 0.0f; double net_value = 0.0;
double net_time = 0.0f; double net_time = 0.0;
// We start with just the portion of frame then_i that actually does fall // We start with just the portion of frame then_i that actually does fall
// within our "then to now" window (usually some portion of it will). // within our "then to now" window (usually some portion of it will).
const PStatFrameData &frame_data = thread_data->get_frame(then_i); const PStatFrameData &frame_data = thread_data->get_frame(then_i);
if (frame_data.get_end() > then) { if (frame_data.get_end() > then) {
double this_time = (frame_data.get_end() - then); double this_time = (frame_data.get_end() - then);
_view.set_to_frame(frame_data); for (const ColorData &cd : get_frame_data(then_i)) {
if (cd._collector_index == collector_index) {
const PStatViewLevel *level = _view.get_level(collector_index); net_value += cd._net_value * this_time;
if (level != nullptr) { net_time += this_time;
net_value += level->get_net_value() * this_time; break;
net_time += this_time; }
} }
} }
// Then we get all of each of the remaining frames. // Then we get all of each of the remaining frames.
@ -354,13 +354,13 @@ get_label_tooltip(int collector_index) const {
frame_number <= now_i; frame_number <= now_i;
frame_number++) { frame_number++) {
const PStatFrameData &frame_data = thread_data->get_frame(frame_number); const PStatFrameData &frame_data = thread_data->get_frame(frame_number);
double this_time = frame_data.get_net_time(); for (const ColorData &cd : get_frame_data(frame_number)) {
_view.set_to_frame(frame_data); if (cd._collector_index == collector_index) {
double this_time = frame_data.get_net_time();
const PStatViewLevel *level = _view.get_level(collector_index); net_value += cd._net_value * this_time;
if (level != nullptr) { net_time += this_time;
net_value += level->get_net_value() * this_time; break;
net_time += this_time; }
} }
} }
@ -543,7 +543,7 @@ scale_frame_data(FrameData &fdata, double factor) {
* the chart. * the chart.
*/ */
const PStatStripChart::FrameData &PStatStripChart:: const PStatStripChart::FrameData &PStatStripChart::
get_frame_data(int frame_number) { get_frame_data(int frame_number) const {
Data::const_iterator di; Data::const_iterator di;
di = _data.find(frame_number); di = _data.find(frame_number);
if (di != _data.end()) { if (di != _data.end()) {
@ -578,7 +578,7 @@ get_frame_data(int frame_number) {
fdata.push_back(cd); fdata.push_back(cd);
} }
inc_label_usage(fdata); ((PStatStripChart *)this)->inc_label_usage(fdata);
return fdata; return fdata;
} }
@ -649,13 +649,10 @@ compute_average_pixel_data(PStatStripChart::FrameData &result,
*/ */
double PStatStripChart:: double PStatStripChart::
get_net_value(int frame_number) const { get_net_value(int frame_number) const {
const FrameData &frame = const FrameData &frame = get_frame_data(frame_number);
((PStatStripChart *)this)->get_frame_data(frame_number);
double net_value = 0.0; double net_value = 0.0;
FrameData::const_iterator fi; for (const ColorData &cd : frame) {
for (fi = frame.begin(); fi != frame.end(); ++fi) {
const ColorData &cd = (*fi);
net_value += cd._net_value; net_value += cd._net_value;
} }
@ -671,7 +668,7 @@ get_average_net_value() const {
const PStatThreadData *thread_data = _view.get_thread_data(); const PStatThreadData *thread_data = _view.get_thread_data();
int now_i, then_i; int now_i, then_i;
if (!thread_data->get_elapsed_frames(then_i, now_i)) { if (!thread_data->get_elapsed_frames(then_i, now_i)) {
return 0.0f; return 0.0;
} }
double now = _time_width + _start_time; double now = _time_width + _start_time;
double then = now - pstats_average_time; double then = now - pstats_average_time;
@ -698,13 +695,14 @@ get_average_net_value() const {
const PStatThreadData *thread_data = _view.get_thread_data(); const PStatThreadData *thread_data = _view.get_thread_data();
double net_value = 0.0f; double net_value = 0.0;
double net_time = 0.0f; double net_time = 0.0;
// We start with just the portion of frame then_i that actually does fall // We start with just the portion of frame then_i that actually does fall
// within our "then to now" window (usually some portion of it will). // within our "then to now" window (usually some portion of it will).
if (thread_data->get_frame(then_i).get_end() > then) { const PStatFrameData &frame_data = thread_data->get_frame(then_i);
double this_time = (thread_data->get_frame(then_i).get_end() - then); if (frame_data.get_end() > then) {
double this_time = (frame_data.get_end() - then);
net_value += get_net_value(then_i) * this_time; net_value += get_net_value(then_i) * this_time;
net_time += this_time; net_time += this_time;
} }

View File

@ -91,7 +91,7 @@ protected:
const FrameData &additional, double weight); const FrameData &additional, double weight);
static void scale_frame_data(FrameData &fdata, double factor); static void scale_frame_data(FrameData &fdata, double factor);
const FrameData &get_frame_data(int frame_number); const FrameData &get_frame_data(int frame_number) const;
void compute_average_pixel_data(PStatStripChart::FrameData &result, void compute_average_pixel_data(PStatStripChart::FrameData &result,
int &then_i, int &now_i, double now); int &then_i, int &now_i, double now);
double get_net_value(int frame_number) const; double get_net_value(int frame_number) const;
@ -132,7 +132,7 @@ private:
bool _scroll_mode; bool _scroll_mode;
bool _average_mode; bool _average_mode;
Data _data; mutable Data _data;
int _next_frame; int _next_frame;
bool _first_data; bool _first_data;