Преглед изворни кода

support for profiling multiple frames

Darren Ranalli пре 19 година
родитељ
комит
a88183a033
2 измењених фајлова са 17 додато и 10 уклоњено
  1. 3 2
      direct/src/showbase/ShowBase.py
  2. 14 8
      direct/src/task/Task.py

+ 3 - 2
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()

+ 14 - 8
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: