Browse Source

added *base.profileNextFrame

Darren Ranalli 19 years ago
parent
commit
0341696500
3 changed files with 24 additions and 2 deletions
  1. 7 1
      direct/src/showbase/PythonUtil.py
  2. 3 0
      direct/src/showbase/ShowBase.py
  3. 14 1
      direct/src/task/Task.py

+ 7 - 1
direct/src/showbase/PythonUtil.py

@@ -761,9 +761,15 @@ def profiled(category, terse=False):
     def loadParticles():
     def loadParticles():
         ...
         ...
 
 
+    want-profile-particles 1
     """
     """
     assert type(category) is types.StringType, "must provide a category name for @profiled"
     assert type(category) is types.StringType, "must provide a category name for @profiled"
-    if not __dev__:
+
+    try:
+        null = not __dev__
+    except:
+        null = not __debug__
+    if null:
         # if we're not in __dev__, just return the function itself. This
         # if we're not in __dev__, just return the function itself. This
         # results in zero runtime overhead, since decorators are evaluated
         # results in zero runtime overhead, since decorators are evaluated
         # at module-load.
         # at module-load.

+ 3 - 0
direct/src/showbase/ShowBase.py

@@ -2027,6 +2027,9 @@ class ShowBase(DirectObject.DirectObject):
         else:
         else:
             __builtins__["direct"] = self.direct = None
             __builtins__["direct"] = self.direct = None
 
 
+    def profileNextFrame(self):
+        self.taskMgr.profileNextFrame()
+
     def run(self):
     def run(self):
         self.taskMgr.run()
         self.taskMgr.run()
 
 

+ 14 - 1
direct/src/task/Task.py

@@ -333,6 +333,8 @@ class TaskManager:
         # List of tasks scheduled to execute in the future
         # List of tasks scheduled to execute in the future
         self.__doLaterList = []
         self.__doLaterList = []
 
 
+        self._profileNextFrame = False
+
         # We copy this value in from __builtins__ when it gets set.
         # We copy this value in from __builtins__ when it gets set.
         # But since the TaskManager might have to run before it gets
         # But since the TaskManager might have to run before it gets
         # set--before it can even be available--we also have to have
         # set--before it can even be available--we also have to have
@@ -767,6 +769,13 @@ class TaskManager:
                     self.__addNewTask(task)
                     self.__addNewTask(task)
         self.pendingTaskDict.clear()
         self.pendingTaskDict.clear()
 
 
+    def profileNextFrame(self):
+        self._profileNextFrame = True
+
+    @profiled('frame')
+    def _profiledFrame(self, *args, **kArgs):
+        return self.step(*args, **kArgs)
+
     def step(self):
     def step(self):
         # assert TaskManager.notify.debug('step: begin')
         # assert TaskManager.notify.debug('step: begin')
         self.currentTime, self.currentFrame = self.__getTimeFrame()
         self.currentTime, self.currentFrame = self.__getTimeFrame()
@@ -837,7 +846,11 @@ class TaskManager:
             self.running = 1
             self.running = 1
             while self.running:
             while self.running:
                 try:
                 try:
-                    self.step()
+                    if self._profileNextFrame:
+                        self._profiledFrame()
+                        self._profileNextFrame = False
+                    else:
+                        self.step()
                 except KeyboardInterrupt:
                 except KeyboardInterrupt:
                     self.stop()
                     self.stop()
                 except IOError, (errno, strerror):
                 except IOError, (errno, strerror):