Browse Source

add PStatFrameData::sort_time()

David Rose 19 years ago
parent
commit
74f7494e05

+ 11 - 0
panda/src/pstatclient/pStatFrameData.I

@@ -237,3 +237,14 @@ get_level(int n) const {
   nassertr(n >= 0 && n < (int)_level_data.size(), 0);
   return _level_data[n]._value;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: PStatFrameData::DataPoint::operator <
+//       Access: Public
+//  Description: Orders the data points by time.
+////////////////////////////////////////////////////////////////////
+INLINE bool PStatFrameData::DataPoint::
+operator < (const PStatFrameData::DataPoint &other) const {
+  return _value < other._value;
+}
+

+ 13 - 0
panda/src/pstatclient/pStatFrameData.cxx

@@ -22,6 +22,19 @@
 #include "datagram.h"
 #include "datagramIterator.h"
 
+#include <algorithm>
+
+////////////////////////////////////////////////////////////////////
+//     Function: PStatFrameData::sort_time
+//       Access: Public
+//  Description: Ensures the frame data is in monotonically increasing
+//               order by time.
+////////////////////////////////////////////////////////////////////
+void PStatFrameData::
+sort_time() {
+  stable_sort(_time_data.begin(), _time_data.end());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PStatFrameData::write_datagram
 //       Access: Public

+ 4 - 0
panda/src/pstatclient/pStatFrameData.h

@@ -47,6 +47,8 @@ public:
   INLINE void add_stop(int index, float time);
   INLINE void add_level(int index, float level);
 
+  void sort_time();
+
   INLINE float get_start() const;
   INLINE float get_end() const;
   INLINE float get_net_time() const;
@@ -66,6 +68,8 @@ public:
 private:
   class DataPoint {
   public:
+    INLINE bool operator < (const DataPoint &other) const;
+
     int _index;
     float _value;
   };

+ 13 - 7
panda/src/pstatclient/test_client.cxx

@@ -19,6 +19,7 @@
 #include "config_pstats.h"
 #include "pStatClient.h"
 #include "pStatCollector.h"
+#include "thread.h"
 
 #include "queuedConnectionManager.h"
 #include "queuedConnectionReader.h"
@@ -145,10 +146,11 @@ main(int argc, char *argv[]) {
   }
 
   while (!user_interrupted && client->is_connected()) {
-    client->get_main_thread().new_frame();
+    PStatClient::main_tick();
 
     float total_ms = 0.0;
-    float now = client->get_clock().get_real_time();
+    float now = client->get_real_time();
+    float start = now;
 
     typedef pvector<WaitRequest> Wait;
     Wait wait;
@@ -184,22 +186,26 @@ main(int argc, char *argv[]) {
 
     // Put the wait requests in order, to allow for the jitter, and
     // invoke them.
+
+    static const double delay = 1.0;
+    _collectors[0].stop(client->get_main_thread(), start + delay);
+
     sort(wait.begin(), wait.end());
     Wait::const_iterator wi;
     for (wi = wait.begin(); wi != wait.end(); ++wi) {
       const WaitRequest &wr = (*wi);
       if (wr._start) {
-        _collectors[wr._index].start(client->get_main_thread(), wr._time);
+        _collectors[wr._index].start(client->get_main_thread(), wr._time + delay);
       } else {
-        _collectors[wr._index].stop(client->get_main_thread(), wr._time);
+        _collectors[wr._index].stop(client->get_main_thread(), wr._time + delay);
       }
     }
 
+    _collectors[0].start(client->get_main_thread(), now + total_ms / 1000 + delay);
+
     // Now actually wait some approximation of the time we said we
     // did.
-    PRIntervalTime sleep_timeout =
-      PR_MillisecondsToInterval((int)total_ms + 5);
-    PR_Sleep(sleep_timeout);
+    Thread::sleep(total_ms / 1000.0 + delay);
   }
 
   return (0);