diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index c9b98a0e3e..672d778420 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -2062,8 +2062,9 @@ class ShowBase(DirectObject.DirectObject): # Set fWantTk to 0 to avoid starting Tk with this call self.startDirect(fWantDirect = fDirect, fWantTk = fTk) - def profileNextFrame(self): - self.taskMgr.profileNextFrame() + def profileFrames(self, num=1): + # profile the next 'num' frames and log the results + self.taskMgr.profileFrames(num) def run(self): self.taskMgr.run() diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 32574220ab..1903d7a450 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -336,7 +336,7 @@ class TaskManager: # List of tasks scheduled to execute in the future self.__doLaterList = [] - self._profileNextFrame = False + self._profileFrames = False # We copy this value in from __builtins__ when it gets set. # But since the TaskManager might have to run before it gets @@ -772,12 +772,18 @@ class TaskManager: self.__addNewTask(task) self.pendingTaskDict.clear() - def profileNextFrame(self): - self._profileNextFrame = True + def profileFrames(self, num=None): + self._profileFrames = True + if num is None: + num = 1 + self._profileFrameCount = num @profiled() - def _profiledFrame(self, *args, **kArgs): - return self.step(*args, **kArgs) + def _doProfiledFrames(self, *args, **kArgs): + print '** profiling %s frames' % self._profileFrameCount + for i in xrange(self._profileFrameCount): + result = self.step(*args, **kArgs) + return result def step(self): # assert TaskManager.notify.debug('step: begin') @@ -849,9 +855,9 @@ class TaskManager: self.running = 1 while self.running: try: - if self._profileNextFrame: - self._profiledFrame() - self._profileNextFrame = False + if self._profileFrames: + self._profileFrames = False + self._doProfiledFrames() else: self.step() except KeyboardInterrupt: