From 543b7283b9a031f18cd853515b869cdffe9bc30a Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 15 Jun 2001 22:18:51 +0000 Subject: [PATCH] stop pstats when stopped at prompt --- direct/src/showbase/ShowBase.py | 12 +++++++++ direct/src/task/Task.py | 5 ++++ panda/src/pstatclient/pStatClient.I | 13 +++++++++ panda/src/pstatclient/pStatClient.cxx | 38 +++++++++++++++++++++++++-- panda/src/pstatclient/pStatClient.h | 8 +++++- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 481e99ff4d..4a7088aab6 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -49,6 +49,18 @@ class ShowBase: taskMgr.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0) taskMgr.pStatsTasks = self.config.GetBool('pstats-tasks', 0) + # Set up the TaskManager to reset the PStats clock back + # whenever we resume from a pause. This callback function is + # a little hacky, but we can't call it directly from within + # the TaskManager because he doesn't know about PStats (and + # has to run before libpanda is even loaded). + + # Temporary try..except for old Pandas. + try: + taskMgr.resumeFunc = PStatClient.resumeAfterPause + except: + pass + fsmRedefine = self.config.GetBool('fsm-redefine', 0) State.FsmRedefine = fsmRedefine diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 2ac9a5410c..455524d495 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -42,6 +42,7 @@ class Task: self.avgDt = 0.0 self.runningTotal = 0.0 self.pstats = None + self.resumeFunc = None def getPriority(self): return self._priority @@ -438,6 +439,10 @@ class TaskManager: # Paused at the prompt for a long time t = globalClock.getFrameTime() globalClock.setRealTime(t) + + if self.resumeFunc != None: + self.resumeFunc() + if self.stepping: self.step() else: diff --git a/panda/src/pstatclient/pStatClient.I b/panda/src/pstatclient/pStatClient.I index 40c313329a..4ce5ac4701 100644 --- a/panda/src/pstatclient/pStatClient.I +++ b/panda/src/pstatclient/pStatClient.I @@ -103,3 +103,16 @@ INLINE bool PStatClient:: is_connected() { return get_global_pstats()->client_is_connected(); } + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::resume_after_pause +// Access: Published +// Description: Resumes the PStatClient after the simulation has been +// paused for a while. This allows the stats to +// continue exactly where it left off, instead of +// leaving a big gap that would represent a chug. +//////////////////////////////////////////////////////////////////// +INLINE void PStatClient:: +resume_after_pause() { + get_global_pstats()->client_resume_after_pause(); +} diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 1c18d2cc5f..2d6e749582 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -209,6 +209,10 @@ get_thread_name(int index) const { // global clock object, so the stats won't get mucked up // if you put the global clock in non-real-time mode or // something. +// +// On second thought, it works better to use the global +// clock, so we don't lose a lot of time in the stats +// while we're waiting at the prompt. //////////////////////////////////////////////////////////////////// const ClockObject &PStatClient:: get_clock() const { @@ -383,7 +387,19 @@ main_tick() { _interpreter_size_pcollector.set_level(MemoryUsage::get_interpreter_size()); } - get_global_pstats()->get_main_thread().new_frame(); + get_global_pstats()->client_main_tick(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::main_tick +// Access: Public, Static +// Description: A convenience function to call new_frame() on the +// the given client's main thread. +//////////////////////////////////////////////////////////////////// +void PStatClient:: +client_main_tick() { + _clock.tick(); + get_main_thread().new_frame(); } //////////////////////////////////////////////////////////////////// @@ -494,6 +510,24 @@ client_is_connected() const { return _is_connected; } +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::client_resume_after_pause +// Access: Published +// Description: Resumes the PStatClient after the simulation has been +// paused for a while. This allows the stats to +// continue exactly where it left off, instead of +// leaving a big gap that would represent a chug. +//////////////////////////////////////////////////////////////////// +void PStatClient:: +client_resume_after_pause() { + // Simply reset the clock to the beginning of the last frame. This + // may lose a frame, but on the other hand we won't skip a whole + // slew of frames either. + + double frame_time = _clock.get_frame_time(); + _clock.set_real_time(frame_time); +} + //////////////////////////////////////////////////////////////////// // Function: PStatClient::is_active // Access: Private @@ -705,7 +739,7 @@ transmit_frame_data(int thread_index) { // We don't want to send too many packets in a hurry and flood the // server. Check that enough time has elapsed for us to send a - // new packet. If not, we'll drop this packet into the void and + // new packet. If not, we'll drop this packet on the floor and // send a new one next time around. float now = _clock.get_real_time(); if (now >= _threads[thread_index]._next_packet) { diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 3bd0991485..eddd750053 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -85,14 +85,19 @@ PUBLISHED: INLINE static void disconnect(); INLINE static bool is_connected(); + INLINE static void resume_after_pause(); + public: - static void main_tick(); static PStatClient *get_global_pstats(); + static void main_tick(); + void client_main_tick(); bool client_connect(string hostname, int port); void client_disconnect(); bool client_is_connected() const; + void client_resume_after_pause(); + private: PStatCollector make_collector_with_relname(int parent_index, string relname); PStatCollector make_collector_with_name(int parent_index, const string &name); @@ -203,6 +208,7 @@ PUBLISHED: INLINE static bool connect(const string & = string(), int = -1) { return false; } INLINE static void disconnect() { } INLINE static bool is_connected() { return false; } + INLINE static void resume_after_pause() { } public: static void main_tick() { }