From 34c695359ea2ef79bd60954315b8415cd5dee007 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 16 Jul 2001 21:41:52 +0000 Subject: [PATCH] don't ask for the time unless stats are running --- panda/src/pstatclient/pStatClient.cxx | 61 +++++++++++++++++++++++++- panda/src/pstatclient/pStatClient.h | 2 + panda/src/pstatclient/pStatCollector.I | 8 ++-- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 2d6e749582..0cb89ab855 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -549,7 +549,31 @@ is_active(int collector_index, int thread_index) const { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::start_collector +// Function: PStatClient::start +// Access: Private +// Description: Marks the indicated collector index as started. +// Normally you would not use this interface directly; +// instead, call PStatCollector::start(). +//////////////////////////////////////////////////////////////////// +void PStatClient:: +start(int collector_index, int thread_index) { + nassertv(collector_index >= 0 && collector_index < (int)_collectors.size()); + nassertv(thread_index >= 0 && thread_index < (int)_threads.size()); + + if (_collectors[collector_index]._def->_is_active && + _threads[thread_index]._is_active) { + if (_collectors[collector_index]._per_thread[thread_index]._nested_count == 0) { + // This collector wasn't already started in this thread; record + // a new data point. + _threads[thread_index]._frame_data.add_start(collector_index, + _clock.get_real_time()); + } + _collectors[collector_index]._per_thread[thread_index]._nested_count++; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::start // Access: Private // Description: Marks the indicated collector index as started. // Normally you would not use this interface directly; @@ -572,7 +596,40 @@ start(int collector_index, int thread_index, float as_of) { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::start_collector +// Function: PStatClient::stop +// Access: Private +// Description: Marks the indicated collector index as stopped. +// Normally you would not use this interface directly; +// instead, call PStatCollector::stop(). +//////////////////////////////////////////////////////////////////// +void PStatClient:: +stop(int collector_index, int thread_index) { + nassertv(collector_index >= 0 && collector_index < (int)_collectors.size()); + nassertv(thread_index >= 0 && thread_index < (int)_threads.size()); + + if (_collectors[collector_index]._def->_is_active && + _threads[thread_index]._is_active) { + if (_collectors[collector_index]._per_thread[thread_index]._nested_count == 0) { + pstats_cat.warning() + << "Collector " << get_collector_fullname(collector_index) + << " was already stopped in thread " << get_thread_name(thread_index) + << "!\n"; + return; + } + + _collectors[collector_index]._per_thread[thread_index]._nested_count--; + + if (_collectors[collector_index]._per_thread[thread_index]._nested_count == 0) { + // This collector has now been completely stopped; record a new + // data point. + _threads[thread_index]._frame_data.add_stop(collector_index, + _clock.get_real_time()); + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::stop // Access: Private // Description: Marks the indicated collector index as stopped. // Normally you would not use this interface directly; diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index eddd750053..5446272bc2 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -105,7 +105,9 @@ private: bool is_active(int collector_index, int thread_index) const; + void start(int collector_index, int thread_index); void start(int collector_index, int thread_index, float as_of); + void stop(int collector_index, int thread_index); void stop(int collector_index, int thread_index, float as_of); void clear_level(int collector_index, int thread_index); diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index cca3485f8d..b781887534 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -145,7 +145,7 @@ is_active() { //////////////////////////////////////////////////////////////////// INLINE void PStatCollector:: start() { - _client->start(_index, 0, _client->_clock.get_real_time()); + _client->start(_index, 0); } //////////////////////////////////////////////////////////////////// @@ -156,7 +156,7 @@ start() { //////////////////////////////////////////////////////////////////// INLINE void PStatCollector:: stop() { - _client->stop(_index, 0, _client->_clock.get_real_time()); + _client->stop(_index, 0); } //////////////////////////////////////////////////////////////////// @@ -241,7 +241,7 @@ is_active(const PStatThread &thread) { //////////////////////////////////////////////////////////////////// INLINE void PStatCollector:: start(const PStatThread &thread) { - _client->start(_index, thread._index, _client->_clock.get_real_time()); + _client->start(_index, thread._index); } //////////////////////////////////////////////////////////////////// @@ -265,7 +265,7 @@ start(const PStatThread &thread, float as_of) { //////////////////////////////////////////////////////////////////// INLINE void PStatCollector:: stop(const PStatThread &thread) { - _client->stop(_index, thread._index, _client->_clock.get_real_time()); + _client->stop(_index, thread._index); } ////////////////////////////////////////////////////////////////////