pstats: Show collector start/stop pair count in time-based graphs

It can be very useful to know how often a collector was invoked in a frame, not just how long it took.  This adds a number to the upper-right corner showing exactly that (but not aggregated, just for leaf collectors).
This commit is contained in:
rdb 2022-11-29 13:01:55 +01:00
parent 5247446500
commit 3468b95fa9
8 changed files with 42 additions and 8 deletions

View File

@ -15,6 +15,7 @@
#include "gtkStatsMonitor.h"
#include "pStatCollectorDef.h"
#include "numeric_types.h"
#include "string_utils.h"
static const int default_strip_chart_width = 400;
static const int default_strip_chart_height = 100;
@ -120,7 +121,7 @@ new_data(int thread_index, int frame_number) {
if (!_pause) {
update();
std::string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
std::string text = get_total_text();
if (_net_value_text != text) {
_net_value_text = text;
gtk_label_set_text(GTK_LABEL(_total_label), _net_value_text.c_str());

View File

@ -156,6 +156,15 @@ pixel_to_height(int x) const {
return _value_height * (double)(get_ysize() - x) / (double)get_ysize();
}
/**
* Returns true if get_title_text() has never yet returned an answer, false if
* it has.
*/
INLINE bool PStatStripChart::
is_title_unknown() const {
return _title_unknown;
}
/**
* Returns true if the indicated collector appears anywhere on the chart at
* the current time, false otherwise.

View File

@ -284,12 +284,18 @@ get_title_text() {
}
/**
* Returns true if get_title_text() has never yet returned an answer, false if
* it has.
* Returns the text suitable for the total label above the graph.
*/
bool PStatStripChart::
is_title_unknown() const {
return _title_unknown;
std::string PStatStripChart::
get_total_text() {
std::string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
if (get_collector_index() != 0 && !_view.get_show_level()) {
const PStatViewLevel *level = _view.get_level(get_collector_index());
if (level != nullptr && level->get_count() > 0) {
text += " / " + format_string(level->get_count()) + "x";
}
}
return text;
}
/**

View File

@ -68,8 +68,9 @@ public:
INLINE int height_to_pixel(double value) const;
INLINE double pixel_to_height(int y) const;
INLINE bool is_title_unknown() const;
std::string get_title_text();
bool is_title_unknown() const;
std::string get_total_text();
protected:
class ColorData {

View File

@ -109,6 +109,7 @@ public:
bool _is_started = false;
bool _pushed = false;
bool _is_new = false;
int _count = 0;
double _net_time = 0.0;
};
@ -315,6 +316,9 @@ update_time_data(const PStatFrameData &frame_data) {
}
} else {
samples[collector_index].data_point(frame_data.get_time(i), is_start, &started);
if (is_start) {
samples[collector_index]._count++;
}
if (!samples[collector_index]._is_new) {
samples[collector_index]._is_new = true;
++new_collectors;
@ -354,6 +358,7 @@ update_time_data(const PStatFrameData &frame_data) {
int collector_index = level->_collector;
if (samples[collector_index]._is_new) {
level->_value_alone = samples[collector_index]._net_time;
level->_count = samples[collector_index]._count;
samples[collector_index]._is_new = false;
--new_collectors;
}
@ -370,6 +375,7 @@ update_time_data(const PStatFrameData &frame_data) {
if (samples[collector_index]._is_new) {
PStatViewLevel *level = get_level(collector_index);
level->_value_alone = samples[collector_index]._net_time;
level->_count = samples[collector_index]._count;
}
}
}
@ -504,6 +510,7 @@ bool PStatView::
reset_level(PStatViewLevel *level) {
bool any_changed = false;
level->_value_alone = 0.0;
level->_count = 0;
if (level->_collector == _constraint) {
return false;

View File

@ -27,3 +27,11 @@ INLINE double PStatViewLevel::
get_value_alone() const {
return _value_alone;
}
/**
* Returns the number of start/stop pairs for this collector.
*/
INLINE int PStatViewLevel::
get_count() const {
return _count;
}

View File

@ -31,6 +31,7 @@ public:
INLINE int get_collector() const;
INLINE double get_value_alone() const;
double get_net_value() const;
INLINE int get_count() const;
void sort_children(const PStatClientData *client_data);
@ -39,6 +40,7 @@ public:
private:
int _collector;
int _count = 0;
double _value_alone;
PStatViewLevel *_parent;

View File

@ -103,7 +103,7 @@ new_data(int thread_index, int frame_number) {
if (!_pause) {
update();
string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
std::string text = get_total_text();
if (_net_value_text != text) {
_net_value_text = text;
RECT rect;