From 9784d46e95ad6a43da7c178a04f9428100b122f1 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 7 Dec 2022 14:42:29 +0100 Subject: [PATCH] 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 --- panda/src/pstatclient/pStatClient.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 906cd87e6b..1d8e7570ea 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -414,8 +414,9 @@ client_main_tick() { for (vector_int::const_iterator vi = indices.begin(); vi != indices.end(); ++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); nassertr(index >= 0 && index < get_num_threads(), PStatThread()); 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. - threads[index]->_thread = thread; + pthread->_thread = thread; thread->set_pstats_index(index); 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); } } @@ -695,6 +701,10 @@ do_make_thread(Thread *thread) { thread->set_pstats_callback(this); 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); return PStatThread(this, new_index);