Przeglądaj źródła

pstats: Fix off-by-one error in frame number counting

The frame number for CPU frames was one ahead of the real one, which did show up correctly for GPU frames
rdb 3 lat temu
rodzic
commit
9784d46e95
1 zmienionych plików z 15 dodań i 5 usunięć
  1. 15 5
      panda/src/pstatclient/pStatClient.cxx

+ 15 - 5
panda/src/pstatclient/pStatClient.cxx

@@ -414,8 +414,9 @@ client_main_tick() {
       for (vector_int::const_iterator vi = indices.begin();
       for (vector_int::const_iterator vi = indices.begin();
            vi != indices.end();
            vi != indices.end();
            ++vi) {
            ++vi) {
-        int frame_number = clock->get_frame_count(get_thread_object(*vi));
-        _impl->new_frame(*vi, frame_number);
+        InternalThread *thread = get_thread_ptr(*vi);
+        _impl->new_frame(*vi, thread->_frame_number);
+        thread->_frame_number = clock->get_frame_count(get_thread_object(*vi));
       }
       }
     }
     }
   }
   }
@@ -678,12 +679,17 @@ do_make_thread(Thread *thread) {
       int index = (*vi);
       int index = (*vi);
       nassertr(index >= 0 && index < get_num_threads(), PStatThread());
       nassertr(index >= 0 && index < get_num_threads(), PStatThread());
       ThreadPointer *threads = _threads.load(std::memory_order_relaxed);
       ThreadPointer *threads = _threads.load(std::memory_order_relaxed);
-      if (threads[index]->_thread.was_deleted() &&
-          threads[index]->_sync_name == thread->get_sync_name()) {
+      InternalThread *pthread = threads[index];
+      if (pthread->_thread.was_deleted() &&
+          pthread->_sync_name == thread->get_sync_name()) {
         // Yes, re-use this one.
         // Yes, re-use this one.
-        threads[index]->_thread = thread;
+        pthread->_thread = thread;
         thread->set_pstats_index(index);
         thread->set_pstats_index(index);
         thread->set_pstats_callback(this);
         thread->set_pstats_callback(this);
+        if (pthread->_sync_name == "Main") {
+          ClockObject *clock = ClockObject::get_global_clock();
+          pthread->_frame_number = clock->get_frame_count(thread);
+        }
         return PStatThread(this, index);
         return PStatThread(this, index);
       }
       }
     }
     }
@@ -695,6 +701,10 @@ do_make_thread(Thread *thread) {
   thread->set_pstats_callback(this);
   thread->set_pstats_callback(this);
 
 
   InternalThread *pthread = new InternalThread(thread);
   InternalThread *pthread = new InternalThread(thread);
+  if (pthread->_sync_name == "Main") {
+    ClockObject *clock = ClockObject::get_global_clock();
+    pthread->_frame_number = clock->get_frame_count(thread);
+  }
   add_thread(pthread);
   add_thread(pthread);
 
 
   return PStatThread(this, new_index);
   return PStatThread(this, new_index);