소스 검색

added warnings for tasks that run longer than expected, to track down chugs

Darren Ranalli 18 년 전
부모
커밋
98efaf0f62
1개의 변경된 파일27개의 추가작업 그리고 1개의 파일을 삭제
  1. 27 1
      direct/src/task/Task.py

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

@@ -329,6 +329,8 @@ class TaskManager:
 
 
     OsdPrefix = 'task.'
     OsdPrefix = 'task.'
 
 
+    DefTaskDurationWarningThreshold = 3.
+
     def __init__(self):
     def __init__(self):
         self.running = 0
         self.running = 0
         self.stepping = 0
         self.stepping = 0
@@ -354,6 +356,16 @@ class TaskManager:
         # small intervals.
         # small intervals.
         self.trueClock = TrueClock.getGlobalPtr()
         self.trueClock = TrueClock.getGlobalPtr()
 
 
+        """
+        base = getBase()
+        self.warnTaskDuration = base.config.GetBool('task-duration-warnings', 1)
+        self.taskDurationWarningThreshold = base.config.GetFloat('task-duration-warning-threshold', 2)
+        """
+        # we don't have a base object at this point, so set some defaults and read the real values
+        # every frame
+        self.warnTaskDuration = 0
+        self.taskDurationWarningThreshold = 2
+
         self.currentTime, self.currentFrame = self.__getTimeFrame()
         self.currentTime, self.currentFrame = self.__getTimeFrame()
         if (TaskManager.notify == None):
         if (TaskManager.notify == None):
             TaskManager.notify = directNotify.newCategory("TaskManager")
             TaskManager.notify = directNotify.newCategory("TaskManager")
@@ -676,7 +688,7 @@ class TaskManager:
             # Record the dt
             # Record the dt
             dt = endTime - startTime
             dt = endTime - startTime
             task.dt = dt
             task.dt = dt
-            
+
         else:
         else:
             # Run the task and check the return value
             # Run the task and check the return value
             if task.pstats:
             if task.pstats:
@@ -701,6 +713,13 @@ class TaskManager:
                 task.avgDt = (task.runningTotal / task.frame)
                 task.avgDt = (task.runningTotal / task.frame)
             else:
             else:
                 task.avgDt = 0
                 task.avgDt = 0
+
+        # warn if the task took too long
+        if self.warnTaskDuration:
+            if dt >= self.taskDurationWarningThreshold:
+                TaskManager.notify.warning('task %s ran for %s seconds' % (
+                    task.name, dt))
+            
         return ret
         return ret
 
 
     def __repeatDoMethod(self, task):
     def __repeatDoMethod(self, task):
@@ -881,6 +900,13 @@ class TaskManager:
 
 
 
 
     def run(self):
     def run(self):
+        base = getBase()
+        self.warnTaskDuration = base.config.GetBool('task-duration-warnings',
+                                                    1)
+        self.taskDurationWarningThreshold = base.config.GetFloat(
+            'task-duration-warning-threshold',
+            TaskManager.DefTaskDurationWarningThreshold)
+
         # Set the clock to have last frame's time in case we were
         # Set the clock to have last frame's time in case we were
         # Paused at the prompt for a long time
         # Paused at the prompt for a long time
         if self.globalClock:
         if self.globalClock: