From c9b1445b7c60db75533a1854a21911ee11600c63 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 28 Mar 2007 22:35:03 +0000 Subject: [PATCH] itemize intervals in pstats --- direct/src/interval/Interval.py | 20 ++++++-- direct/src/interval/IntervalManager.py | 63 ++++++-------------------- direct/src/interval/MetaInterval.py | 17 ++++++- direct/src/interval/cInterval.cxx | 19 +++++++- direct/src/interval/cInterval.h | 5 ++ direct/src/interval/cMetaInterval.cxx | 1 + 6 files changed, 70 insertions(+), 55 deletions(-) diff --git a/direct/src/interval/Interval.py b/direct/src/interval/Interval.py index e9f4df3b8e..961137eff6 100644 --- a/direct/src/interval/Interval.py +++ b/direct/src/interval/Interval.py @@ -5,8 +5,9 @@ __all__ = ['Interval'] from direct.directnotify.DirectNotifyGlobal import directNotify from direct.showbase.DirectObject import DirectObject from pandac.PandaModules import * -from direct.task import Task +from direct.task.Task import Task, TaskManager from direct.showbase import PythonUtil +from pandac.PandaModules import * import math class Interval(DirectObject): @@ -33,6 +34,11 @@ class Interval(DirectObject): self.__doLoop = 0 self.__loopCount = 0 + self.pstats = None + if __debug__ and TaskManager.taskTimerVerbose: + self.pname = name.split('-', 1)[0] + self.pstats = PStatCollector("App:Show code:ivalLoop:%s" % (self.pname)) + # Set true if the interval should be invoked if it was # completely skipped over during initialize or finalize, false # if it should be ignored in this case. @@ -171,6 +177,8 @@ class Interval(DirectObject): return self.doneEvent def privDoEvent(self, t, event): + if self.pstats: + self.pstats.start() if event == CInterval.ETStep: self.privStep(t) elif event == CInterval.ETFinalize: @@ -189,6 +197,8 @@ class Interval(DirectObject): self.privReverseInitialize(t) else: self.notify.error('Invalid event type: %s' % (event)) + if self.pstats: + self.pstats.stop() def privInitialize(self, t): @@ -344,17 +354,20 @@ class Interval(DirectObject): def privPostEvent(self): # Call after calling any of the priv* methods to do any required # Python finishing steps. + if self.pstats: + self.pstats.start() t = self.getT() if hasattr(self, "setTHooks"): for func in self.setTHooks: func(t) + if self.pstats: + self.pstats.stop() def __spawnTask(self): # Spawn task - from direct.task import Task self.__removeTask() taskName = self.getName() + '-play' - task = Task.Task(self.__playTask) + task = Task(self.__playTask) task.interval = self taskMgr.add(task, taskName) @@ -369,7 +382,6 @@ class Interval(DirectObject): taskMgr.remove(task) def __playTask(self, task): - from direct.task import Task again = self.stepPlay() self.privPostEvent() if again: diff --git a/direct/src/interval/IntervalManager.py b/direct/src/interval/IntervalManager.py index d20cfa4717..9568e8b3e6 100644 --- a/direct/src/interval/IntervalManager.py +++ b/direct/src/interval/IntervalManager.py @@ -17,50 +17,21 @@ class IntervalManager(CIntervalManager): # the Python extensions is to add support for Python-based # intervals (like MetaIntervals). - if PandaModules.__dict__.has_key("Dtool_PyNavtiveInterface"): - def __init__(self, globalPtr = 0): - # Pass globalPtr == 1 to the constructor to trick it into - # "constructing" a Python wrapper around the global - # CIntervalManager object. - ##self.cObj = CIntervalManager.getGlobalPtr() - ##Dtool_BarrowThisRefrence(self, self.cObj) - ##self.dd = self - if globalPtr: - self.cObj = CIntervalManager.getGlobalPtr() - # Temporary try..except for old Panda. - try: - Dtool_BorrowThisReference(self, self.cObj) - except: - Dtool_BarrowThisRefrence(self, self.cObj) - self.dd = self - else: - CIntervalManager.__init__(self) - self.eventQueue = EventQueue() - self.MyEventmanager = EventManager.EventManager(self.eventQueue) - self.setEventQueue(self.eventQueue) - self.ivals = [] - self.removedIvals = {} - else: ## the old interface - def __init__(self, globalPtr = 0): - # Pass globalPtr == 1 to the constructor to trick it into - # "constructing" a Python wrapper around the global - # CIntervalManager object. - if globalPtr: - #CIntervalManager.__init__(self, None) - cObj = CIntervalManager.getGlobalPtr() - self.this = cObj.this - self.userManagesMemory = 0 - else: - CIntervalManager.__init__(self) - # Set up a custom event queue for handling C++ events from - # intervals. - self.eventQueue = EventQueue() - self.MyEventmanager = EventManager.EventManager(self.eventQueue) - self.setEventQueue(self.eventQueue) - self.ivals = [] - self.removedIvals = {} - - + def __init__(self, globalPtr = 0): + # Pass globalPtr == 1 to the constructor to trick it into + # "constructing" a Python wrapper around the global + # CIntervalManager object. + if globalPtr: + self.cObj = CIntervalManager.getGlobalPtr() + Dtool_BorrowThisReference(self, self.cObj) + self.dd = self + else: + CIntervalManager.__init__(self) + self.eventQueue = EventQueue() + self.MyEventmanager = EventManager.EventManager(self.eventQueue) + self.setEventQueue(self.eventQueue) + self.ivals = [] + self.removedIvals = {} def addInterval(self, interval): index = self.addCInterval(interval, 1) @@ -154,10 +125,6 @@ class IntervalManager(CIntervalManager): assert self.ivals[index] == None or self.ivals[index] == interval self.ivals[index] = interval - - #def __repr__(self): - # return self.__str__() - # The global IntervalManager object. ivalMgr = IntervalManager(1) diff --git a/direct/src/interval/MetaInterval.py b/direct/src/interval/MetaInterval.py index 81ffe459de..420a2966d6 100644 --- a/direct/src/interval/MetaInterval.py +++ b/direct/src/interval/MetaInterval.py @@ -6,7 +6,7 @@ from pandac.PandaModules import * from direct.directnotify.DirectNotifyGlobal import * from IntervalManager import ivalMgr import Interval -from direct.task import Task +from direct.task.Task import Task, TaskManager import types if __debug__: import direct.showbase.PythonUtil as PythonUtil @@ -97,6 +97,11 @@ class MetaInterval(CMetaInterval): self.setAutoPause(autoPause) self.setAutoFinish(autoFinish) + self.pstats = None + if __debug__ and TaskManager.taskTimerVerbose: + self.pname = name.split('-', 1)[0] + self.pstats = PStatCollector("App:Show code:ivalLoop:%s" % (self.pname)) + self.pythonIvals = [] # If we are running in debug mode, we validate the intervals @@ -319,6 +324,8 @@ class MetaInterval(CMetaInterval): # It's a Python-style Interval, so add it as an external. index = len(self.pythonIvals) self.pythonIvals.append(ival) + if self.pstats: + ival.pstats = PStatCollector(self.pstats, ival.pname) self.addExtIndex(index, ival.getName(), ival.getDuration(), ival.getOpenEnded(), relTime, relTo) @@ -482,12 +489,20 @@ class MetaInterval(CMetaInterval): def privDoEvent(self, t, event): # This function overrides the C++ function to initialize the # intervals first if necessary. + if self.pstats: + self.pstats.start() self.__updateIvals() CMetaInterval.privDoEvent(self, t, event) + if self.pstats: + self.pstats.stop() def privPostEvent(self): + if self.pstats: + self.pstats.start() self.__doPythonCallbacks() CMetaInterval.privPostEvent(self) + if self.pstats: + self.pstats.stop() def setIntervalStartTime(self, *args, **kw): # This function overrides from the parent level to force it to diff --git a/direct/src/interval/cInterval.cxx b/direct/src/interval/cInterval.cxx index 19561f895a..72915da4d0 100644 --- a/direct/src/interval/cInterval.cxx +++ b/direct/src/interval/cInterval.cxx @@ -22,10 +22,21 @@ #include "clockObject.h" #include "event.h" #include "eventQueue.h" -#include +#include "pStatTimer.h" +PStatCollector CInterval::_root_pcollector("App:Show code:ivalLoop"); TypeHandle CInterval::_type_handle; +static inline string +get_pstats_name(const string &name) { + string pname = name; + size_t hyphen = pname.find('-'); + if (hyphen != string::npos) { + pname = pname.substr(0, hyphen); + } + return pname; +} + //////////////////////////////////////////////////////////////////// // Function: CInterval::Constructor // Access: Public @@ -36,9 +47,11 @@ CInterval(const string &name, double duration, bool open_ended) : _state(S_initial), _curr_t(0.0), _name(name), + _pname(get_pstats_name(name)), _duration(max(duration, 0.0)), _open_ended(open_ended), - _dirty(false) + _dirty(false), + _ival_pcollector(_root_pcollector, _pname) { _auto_pause = false; _auto_finish = false; @@ -283,6 +296,7 @@ is_playing() const { //////////////////////////////////////////////////////////////////// void CInterval:: priv_do_event(double t, EventType event) { + PStatTimer timer(_ival_pcollector); switch (event) { case ET_initialize: priv_initialize(t); @@ -497,6 +511,7 @@ void CInterval:: setup_play(double start_t, double end_t, double play_rate, bool do_loop) { nassertv(start_t < end_t || end_t < 0.0); nassertv(play_rate != 0.0); + PStatTimer timer(_ival_pcollector); double duration = get_duration(); diff --git a/direct/src/interval/cInterval.h b/direct/src/interval/cInterval.h index 54869c99bc..1d3b0414cb 100644 --- a/direct/src/interval/cInterval.h +++ b/direct/src/interval/cInterval.h @@ -23,6 +23,7 @@ #include "typedReferenceCount.h" #include "pvector.h" #include "config_interval.h" +#include "pStatCollector.h" class CIntervalManager; @@ -139,6 +140,7 @@ protected: State _state; double _curr_t; string _name; + string _pname; string _done_event; double _duration; @@ -168,6 +170,9 @@ private: // dirty. typedef pvector Parents; Parents _parents; + + static PStatCollector _root_pcollector; + PStatCollector _ival_pcollector; public: static TypeHandle get_class_type() { diff --git a/direct/src/interval/cMetaInterval.cxx b/direct/src/interval/cMetaInterval.cxx index ff8b0c85ce..9693998037 100644 --- a/direct/src/interval/cMetaInterval.cxx +++ b/direct/src/interval/cMetaInterval.cxx @@ -144,6 +144,7 @@ add_c_interval(CInterval *c_interval, nassertr(c_interval != (CInterval *)NULL, -1); c_interval->_parents.push_back(this); + c_interval->_ival_pcollector = PStatCollector(_ival_pcollector, c_interval->_pname); _defs.push_back(IntervalDef()); IntervalDef &def = _defs.back(); def._type = DT_c_interval;