PStats question

By default, in PStats I can only see time that was spent to execute my full code. Is there any way to see what time was spent on some parts of my code? I want to know what pieces of code require more optimization.

Yes, it is possible to make pstats tell you how much time each of your tasks is consuming. You just need to enable two configuration variables. Its explained here:
panda3d.org/manual/index.php/Measu … ith_PStats

Thanks for the link but, I must admit, I didn’t understand anything on that page. I have no idea about decorators and how to use the given snippet.
Let’s say, we have a simple test code:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "want-pstats 1")
import direct.directbase.DirectStart
class World():
    def __init__(self):
        self.node = render.attachNewNode("node")
        taskMgr.add(self.update, "update")
    def updateWorld(self, task):
        print "self.update was called"
        return Task.cont
w = World()
run()

What should I add to make PStats collect information about self.update() method?

You just need to define the config variables:

task-timer-verbose 1
pstats-tasks 1

These are mentioned in the top part of the linked page. The rest of the page is all for advanced uses that you don’t necessarily need to be concerned with.

David

If you want to use the decorator, put the function somewhere in your code or import it from an external file and put @pstat before the function you want to measure:

def pstat(func):...
...
...
class World():
    def __init__(self):
        self.node = render.attachNewNode("node")
        taskMgr.add(self.update, "update")
    @pstat
    def updateWorld(self, task):
        print "self.update was called"
        return Task.cont

drwr’s method would be the simplest way though and will also show you the performance of the other tasks.