average net value across the top

This commit is contained in:
David Rose 2004-01-13 19:12:41 +00:00
parent 92c4dd283b
commit bb2ee7c2b9
6 changed files with 127 additions and 48 deletions

View File

@ -197,15 +197,8 @@ set_auto_vertical_scale() {
thread_data->get_frame_number_at_time(time, frame_number); thread_data->get_frame_number_at_time(time, frame_number);
if (thread_data->has_frame(frame_number)) { if (thread_data->has_frame(frame_number)) {
const FrameData &frame = get_frame_data(frame_number); float net_value = get_net_value(frame_number);
max_value = max(max_value, net_value);
float overall_value = 0.0;
FrameData::const_iterator fi;
for (fi = frame.begin(); fi != frame.end(); ++fi) {
const ColorData &cd = (*fi);
overall_value += cd._net_value;
}
max_value = max(max_value, overall_value);
} }
} }
@ -352,6 +345,49 @@ get_frame_data(int frame_number) {
return data; return data;
} }
////////////////////////////////////////////////////////////////////
// Function: PStatStripChart::get_net_value
// Access: Protected
// Description: Returns the net value of the chart's collector for
// the indicated fraem number.
////////////////////////////////////////////////////////////////////
float PStatStripChart::
get_net_value(int frame_number) const {
const FrameData &frame =
((PStatStripChart *)this)->get_frame_data(frame_number);
float net_value = 0.0;
FrameData::const_iterator fi;
for (fi = frame.begin(); fi != frame.end(); ++fi) {
const ColorData &cd = (*fi);
net_value += cd._net_value;
}
return net_value;
}
////////////////////////////////////////////////////////////////////
// Function: PStatStripChart::get_average_net_value
// Access: Protected
// Description: Computes the average value of the chart's collector
// over the past indicated number of seconds.
////////////////////////////////////////////////////////////////////
float PStatStripChart::
get_average_net_value(float time) const {
const PStatThreadData *thread_data = _view.get_thread_data();
int now_i, then_i;
if (!thread_data->get_elapsed_frames(then_i, now_i, time)) {
return 0.0f;
}
float net_value = 0.0f;
for (int frame_number = then_i; frame_number <= now_i; frame_number++) {
net_value += get_net_value(frame_number);
}
int num_frames = now_i - then_i + 1;
return net_value / (float)num_frames;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PStatStripChart::changed_size // Function: PStatStripChart::changed_size
// Access: Protected // Access: Protected

View File

@ -86,6 +86,8 @@ protected:
typedef pmap<int, FrameData> Data; typedef pmap<int, FrameData> Data;
const FrameData &get_frame_data(int frame_number); const FrameData &get_frame_data(int frame_number);
float get_net_value(int frame_number) const;
float get_average_net_value(float time = 3.0) const;
void changed_size(int xsize, int ysize); void changed_size(int xsize, int ysize);
void force_redraw(); void force_redraw();

View File

@ -229,6 +229,56 @@ get_latest_frame() const {
return *_frames.back(); return *_frames.back();
} }
////////////////////////////////////////////////////////////////////
// Function: PStatThreadData::get_elapsed_frames
// Access: Public
// Description: Computes the oldest frame number not older than time
// seconds, and the newest frame number. Handy for
// computing average frame rate over a time. Returns
// true if there is any data in that range, false
// otherwise.
////////////////////////////////////////////////////////////////////
bool PStatThreadData::
get_elapsed_frames(int &then_i, int &now_i, float time) const {
if (_frames.empty()) {
// No frames in the data at all.
return false;
}
now_i = _frames.size() - 1;
while (now_i > 0 && _frames[now_i] == (PStatFrameData *)NULL) {
now_i--;
}
if (now_i < 0) {
// No frames have any real data.
return false;
}
nassertr(_frames[now_i] != (PStatFrameData *)NULL, false);
float now = _frames[now_i]->get_end();
float then = now - time;
int old_i = now_i;
then_i = now_i;
while (old_i >= 0) {
const PStatFrameData *frame = _frames[old_i];
if (frame != (PStatFrameData *)NULL) {
if (frame->get_start() > then) {
then_i = old_i;
} else {
break;
}
}
old_i--;
}
nassertr(then_i >= 0, false);
nassertr(_frames[then_i] != (PStatFrameData *)NULL, false);
return true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PStatThreadData::get_frame_rate // Function: PStatThreadData::get_frame_rate
// Access: Public // Access: Public
@ -238,45 +288,14 @@ get_latest_frame() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
float PStatThreadData:: float PStatThreadData::
get_frame_rate(float time) const { get_frame_rate(float time) const {
if (_frames.empty()) { int then_i, now_i;
// No frames in the data at all; nothing to base the frame rate if (!get_elapsed_frames(then_i, now_i, time)) {
// on. return 0.0f;
return 0.0;
} }
int now_i = _frames.size() - 1; int num_frames = now_i - then_i + 1;
while (now_i > 0 && _frames[now_i] == (PStatFrameData *)NULL) {
now_i--;
}
if (now_i < 0) {
// No frames have any real data.
return 0.0;
}
nassertr(_frames[now_i] != (PStatFrameData *)NULL, 0.0);
float now = _frames[now_i]->get_end(); float now = _frames[now_i]->get_end();
float then = now - time; return (float)num_frames / (now - _frames[then_i]->get_start());
int then_i = now_i;
int last_good_i = now_i;
while (then_i >= 0) {
const PStatFrameData *frame = _frames[then_i];
if (frame != (PStatFrameData *)NULL) {
if (frame->get_start() > then) {
last_good_i = then_i;
} else {
break;
}
}
then_i--;
}
nassertr(last_good_i >= 0, 0.0);
nassertr(_frames[last_good_i] != (PStatFrameData *)NULL, 0.0);
int num_frames = now_i - last_good_i + 1;
return (float)num_frames / (now - _frames[last_good_i]->get_start());
} }

View File

@ -60,6 +60,7 @@ public:
const PStatFrameData &get_latest_frame() const; const PStatFrameData &get_latest_frame() const;
bool get_elapsed_frames(int &then_i, int &now_i, float time) const;
float get_frame_rate(float time = 3.0) const; float get_frame_rate(float time = 3.0) const;

View File

@ -43,7 +43,7 @@ WinStatsStripChart(WinStatsMonitor *monitor, int thread_index,
_left_margin = 96; _left_margin = 96;
_right_margin = 32; _right_margin = 32;
_top_margin = 8; _top_margin = 16;
_bottom_margin = 8; _bottom_margin = 8;
// Let's show the units on the guide bar labels. There's room. // Let's show the units on the guide bar labels. There's room.
@ -93,6 +93,15 @@ new_data(int thread_index, int frame_number) {
if (!_pause) { if (!_pause) {
update(); update();
string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
if (_net_value_text != text) {
_net_value_text = text;
RECT rect;
GetClientRect(_window, &rect);
rect.bottom = _top_margin;
InvalidateRect(_window, &rect, TRUE);
}
} }
} }
@ -137,6 +146,10 @@ set_time_units(int unit_mask) {
GetClientRect(_window, &rect); GetClientRect(_window, &rect);
rect.left = _right_margin; rect.left = _right_margin;
InvalidateRect(_window, &rect, TRUE); InvalidateRect(_window, &rect, TRUE);
GetClientRect(_window, &rect);
rect.bottom = _top_margin;
InvalidateRect(_window, &rect, TRUE);
} }
} }
@ -503,14 +516,21 @@ additional_window_paint(HDC hdc) {
last_y = draw_guide_label(hdc, x, get_guide_bar(i), last_y); last_y = draw_guide_label(hdc, x, get_guide_bar(i), last_y);
} }
GuideBar top_value = make_guide_bar(get_vertical_scale());
draw_guide_label(hdc, x, top_value, last_y);
last_y = -100; last_y = -100;
int num_user_guide_bars = get_num_user_guide_bars(); int num_user_guide_bars = get_num_user_guide_bars();
for (i = 0; i < num_user_guide_bars; i++) { for (i = 0; i < num_user_guide_bars; i++) {
last_y = draw_guide_label(hdc, x, get_user_guide_bar(i), last_y); last_y = draw_guide_label(hdc, x, get_user_guide_bar(i), last_y);
} }
GuideBar top_value = make_guide_bar(get_vertical_scale()); // Now draw the "net value" label at the top.
draw_guide_label(hdc, x, top_value, last_y); SetTextAlign(hdc, TA_RIGHT | TA_BOTTOM);
SetTextColor(hdc, RGB(0, 0, 0));
TextOut(hdc, rect.right - _right_margin, _top_margin,
_net_value_text.data(), _net_value_text.length());
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -75,6 +75,7 @@ private:
static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
int _brush_origin; int _brush_origin;
string _net_value_text;
static bool _window_class_registered; static bool _window_class_registered;
static const char * const _window_class_name; static const char * const _window_class_name;