From 04a5308b570ec973632f45ae23ea1cdd3141937a Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 1 Jul 2007 18:48:50 +0000 Subject: [PATCH] make thread block time explicit in pstats --- panda/src/gobj/vertexDataPage.cxx | 2 +- panda/src/pstatclient/pStatClient.cxx | 45 +++++---------------------- panda/src/pstatclient/pStatClient.h | 3 +- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/panda/src/gobj/vertexDataPage.cxx b/panda/src/gobj/vertexDataPage.cxx index c783bab92f..907b037b80 100644 --- a/panda/src/gobj/vertexDataPage.cxx +++ b/panda/src/gobj/vertexDataPage.cxx @@ -80,7 +80,7 @@ PStatCollector VertexDataPage::_vdata_compress_pcollector("*:Vertex Data:Compres PStatCollector VertexDataPage::_vdata_decompress_pcollector("*:Vertex Data:Decompress"); PStatCollector VertexDataPage::_vdata_save_pcollector("*:Vertex Data:Save"); PStatCollector VertexDataPage::_vdata_restore_pcollector("*:Vertex Data:Restore"); -PStatCollector VertexDataPage::_thread_wait_pcollector("*:Wait:Idle"); +PStatCollector VertexDataPage::_thread_wait_pcollector("Wait:Idle"); PStatCollector VertexDataPage::_alloc_pages_pcollector("System memory:MMap:Vertex data"); TypeHandle VertexDataPage::_type_handle; diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 7780eaafda..b0ec9eb5be 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -49,6 +49,7 @@ PStatCollector PStatClient::_mmap_dc_inactive_other_size_pcollector("System memo PStatCollector PStatClient::_pstats_pcollector("*:PStats"); PStatCollector PStatClient::_clock_wait_pcollector("Wait:Clock Wait:Sleep"); PStatCollector PStatClient::_clock_busy_wait_pcollector("Wait:Clock Wait:Spin"); +PStatCollector PStatClient::_thread_block_pcollector("Wait:Thread block"); PStatClient *PStatClient::_global_pstats = NULL; @@ -721,7 +722,6 @@ start(int collector_index, int thread_index) { if (thread->_thread_active) { thread->_frame_data.add_start(collector_index, get_real_time()); } - thread->_active_collectors.set_bit(collector_index); } collector->_per_thread[thread_index]._nested_count++; } @@ -752,7 +752,6 @@ start(int collector_index, int thread_index, float as_of) { if (thread->_thread_active) { thread->_frame_data.add_start(collector_index, as_of); } - thread->_active_collectors.set_bit(collector_index); } collector->_per_thread[thread_index]._nested_count++; } @@ -795,7 +794,6 @@ stop(int collector_index, int thread_index) { if (thread->_thread_active) { thread->_frame_data.add_stop(collector_index, get_real_time()); } - thread->_active_collectors.clear_bit(collector_index); } } } @@ -1091,27 +1089,14 @@ deactivate_hook(Thread *thread) { if (_impl == NULL) { return; } - InternalThread *ithread = get_thread_ptr(thread->get_pstats_index()); + int thread_index = thread->get_pstats_index(); + InternalThread *ithread = get_thread_ptr(thread_index); if (ithread->_thread_active) { - // Stop all of the active collectors for this thread. + // Start _thread_block_pcollector, by hand, being careful not to + // grab any mutexes while we do it. double now = _impl->get_real_time(); - int off_bit = -1; - int on_bit = ithread->_active_collectors.get_lowest_on_bit(); - while (off_bit != on_bit) { - off_bit = ithread->_active_collectors.get_next_higher_different_bit(on_bit); - nassertd(off_bit != on_bit) { - cerr << "Oops! off_bit = " << off_bit - << ", collectors = " << ithread->_active_collectors << "\n"; - } - while (on_bit < off_bit) { - // Here's an active collector. Record a data point indicating - // it stops here. - ithread->_frame_data.add_stop(on_bit, now); - ++on_bit; - } - on_bit = ithread->_active_collectors.get_next_higher_different_bit(off_bit); - } + ithread->_frame_data.add_start(_thread_block_pcollector.get_index(), now); ithread->_thread_active = false; } } @@ -1137,24 +1122,8 @@ activate_hook(Thread *thread) { InternalThread *ithread = get_thread_ptr(thread->get_pstats_index()); if (!ithread->_thread_active) { - // Resume all of the active collectors for this thread. double now = _impl->get_real_time(); - int off_bit = -1; - int on_bit = ithread->_active_collectors.get_lowest_on_bit(); - while (off_bit != on_bit) { - off_bit = ithread->_active_collectors.get_next_higher_different_bit(on_bit); - nassertd(off_bit != on_bit) { - cerr << "Oops! off_bit = " << off_bit - << ", collectors = " << ithread->_active_collectors << "\n"; - } - while (on_bit < off_bit) { - // Here's an active collector. Record a data point indicating - // it resumes here. - ithread->_frame_data.add_start(on_bit, now); - ++on_bit; - } - on_bit = ithread->_active_collectors.get_next_higher_different_bit(off_bit); - } + ithread->_frame_data.add_stop(_thread_block_pcollector.get_index(), now); ithread->_thread_active = true; } } diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 8eacbd1c91..fcc44582e6 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -213,7 +213,7 @@ private: float _next_packet; bool _thread_active; - BitArray _active_collectors; + BitArray _active_collectors; // no longer used. // This mutex is used to protect writes to _frame_data for this // particular thread, as well as writes to the _per_thread data @@ -243,6 +243,7 @@ private: static PStatCollector _pstats_pcollector; static PStatCollector _clock_wait_pcollector; static PStatCollector _clock_busy_wait_pcollector; + static PStatCollector _thread_block_pcollector; static PStatClient *_global_pstats;