From 892b4465dacdf7dc02204293434c689df79b0266 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 31 May 2001 00:03:44 +0000 Subject: [PATCH] Add tasks to pstats --- direct/src/showbase/ShowBase.py | 1 + direct/src/task/Task.py | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 8bcd3a1afd..caa196639b 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -47,6 +47,7 @@ class ShowBase: self.wantStats = self.config.GetBool('want-stats', 0) taskMgr.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0) + taskMgr.pStatsTasks = self.config.GetBool('pstats-tasks', 0) fsmRedefine = self.config.GetBool('fsm-redefine', 0) State.FsmRedefine = fsmRedefine diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 893c06a05a..819c63b288 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -37,6 +37,7 @@ class Task: self.maxDt = 0.0 self.avgDt = 0.0 self.runningTotal = 0.0 + self.pstats = None def getPriority(self): return self._priority @@ -53,16 +54,17 @@ class Task: self.time = currentTime - self.starttime self.frame = currentFrame - self.startframe + def setupPStats(self, name): + if __debug__: + import PStatCollector + self.pstats = PStatCollector.PStatCollector("App:Show code:" + name) + def doLater(delayTime, task, taskName): task.name = taskName # make a sequence out of the delay and the task seq = sequence(pause(delayTime), task) return seq -def spawnMethodNamed(self, func, name): - task = Task(func) - self.spawnTaskNamed(task, name) - def pause(delayTime): def func(self): if (self.time < self.delayTime): @@ -261,6 +263,7 @@ class TaskManager: if (TaskManager.notify == None): TaskManager.notify = directNotify.newCategory("TaskManager") self.taskTimerVerbose = 0 + self.pStatsTasks = 0 def stepping(value): self.stepping = value @@ -284,6 +287,19 @@ class TaskManager: index = index - 1 index = index + 1 self.taskList.insert(index, task) + + if __debug__: + if self.pStatsTasks and name != "igloop": + # Get the PStats name for the task. By convention, + # this is everything until the first hyphen; the part + # of the task name following the hyphen is generally + # used to differentiate particular tasks that do the + # same thing to different objects. + hyphen = name.find('-') + if hyphen >= 0: + name = name[0:hyphen] + task.setupPStats(name) + return task def doMethodLater(self, delayTime, func, taskName): @@ -361,9 +377,13 @@ class TaskManager: ret = task(task) else: # Run the task and check the return value + if task.pstats: + task.pstats.start() startTime = time.clock() ret = task(task) endTime = time.clock() + if task.pstats: + task.pstats.stop() # Record the dt dt = endTime - startTime