Browse Source

average net value across the top

David Rose 22 years ago
parent
commit
bb2ee7c2b9

+ 45 - 9
pandatool/src/pstatserver/pStatStripChart.cxx

@@ -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 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);
+      float net_value = get_net_value(frame_number);
+      max_value = max(max_value, net_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

+ 2 - 0
pandatool/src/pstatserver/pStatStripChart.h

@@ -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();

+ 41 - 22
pandatool/src/pstatserver/pStatThreadData.cxx

@@ -230,53 +230,72 @@ get_latest_frame() const {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: PStatThreadData::get_frame_rate
+//     Function: PStatThreadData::get_elapsed_frames
 //       Access: Public
 //       Access: Public
-//  Description: Computes the average frame rate over the past number
-//               of seconds, by counting up the number of frames
-//               elapsed in that time interval.
+//  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.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-float PStatThreadData::
-get_frame_rate(float time) const {
+bool PStatThreadData::
+get_elapsed_frames(int &then_i, int &now_i, float time) const {
   if (_frames.empty()) {
   if (_frames.empty()) {
-    // No frames in the data at all; nothing to base the frame rate
-    // on.
-    return 0.0;
+    // No frames in the data at all.
+    return false;
   }
   }
 
 
-  int now_i = _frames.size() - 1;
+  now_i = _frames.size() - 1;
   while (now_i > 0 && _frames[now_i] == (PStatFrameData *)NULL) {
   while (now_i > 0 && _frames[now_i] == (PStatFrameData *)NULL) {
     now_i--;
     now_i--;
   }
   }
   if (now_i < 0) {
   if (now_i < 0) {
     // No frames have any real data.
     // No frames have any real data.
-    return 0.0;
+    return false;
   }
   }
-  nassertr(_frames[now_i] != (PStatFrameData *)NULL, 0.0);
+  nassertr(_frames[now_i] != (PStatFrameData *)NULL, false);
 
 
   float now = _frames[now_i]->get_end();
   float now = _frames[now_i]->get_end();
   float then = now - time;
   float then = now - time;
 
 
-  int then_i = now_i;
-  int last_good_i = now_i;
+  int old_i = now_i;
+  then_i = now_i;
 
 
-  while (then_i >= 0) {
-    const PStatFrameData *frame = _frames[then_i];
+  while (old_i >= 0) {
+    const PStatFrameData *frame = _frames[old_i];
     if (frame != (PStatFrameData *)NULL) {
     if (frame != (PStatFrameData *)NULL) {
       if (frame->get_start() > then) {
       if (frame->get_start() > then) {
-        last_good_i = then_i;
+        then_i = old_i;
       } else {
       } else {
         break;
         break;
       }
       }
     }
     }
-    then_i--;
+    old_i--;
   }
   }
 
 
-  nassertr(last_good_i >= 0, 0.0);
-  nassertr(_frames[last_good_i] != (PStatFrameData *)NULL, 0.0);
+  nassertr(then_i >= 0, false);
+  nassertr(_frames[then_i] != (PStatFrameData *)NULL, false);
+
+  return true;
+}
 
 
-  int num_frames = now_i - last_good_i + 1;
-  return (float)num_frames / (now - _frames[last_good_i]->get_start());
+////////////////////////////////////////////////////////////////////
+//     Function: PStatThreadData::get_frame_rate
+//       Access: Public
+//  Description: Computes the average frame rate over the past number
+//               of seconds, by counting up the number of frames
+//               elapsed in that time interval.
+////////////////////////////////////////////////////////////////////
+float PStatThreadData::
+get_frame_rate(float time) const {
+  int then_i, now_i;
+  if (!get_elapsed_frames(then_i, now_i, time)) {
+    return 0.0f;
+  }
+
+  int num_frames = now_i - then_i + 1;
+  float now = _frames[now_i]->get_end();
+  return (float)num_frames / (now - _frames[then_i]->get_start());
 }
 }
 
 
 
 

+ 1 - 0
pandatool/src/pstatserver/pStatThreadData.h

@@ -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;
 
 
 
 

+ 23 - 3
pandatool/src/win-stats/winStatsStripChart.cxx

@@ -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());
-  draw_guide_label(hdc, x, top_value, last_y);
+  // Now draw the "net value" label at the top.
+  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()); 
+
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
pandatool/src/win-stats/winStatsStripChart.h

@@ -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;