Profiling CherryPy

六月ゝ 毕业季﹏ 提交于 2019-12-04 12:01:31

It turns out that the profile files generated by CherryPy can be interpreted using the profiler.py script shipped as part of CherryPy. Simply run profiler.py in the <site-packages>/cherrypy/lib directory as follows:

python profiler.py /directory/containing/prof/files 8080

Then navigate to localhost:8080 in your browser and the profiling results for all .prof files in the target directory will be displayed in a simple text interface.

I would still prefer to be able to export the results into a calltree to profile using KCacheGrind, but this seems to do for basic profiling.

This is documented in the change log for v2.1 of CherryPy when the profiler was introduced (although the other details on that page describing how to set up the profiler has since become deprecated)

I am also trying to get profiling up and running for a cherrypy instance. I used the same code you have in your initial question, which seems to work in that it generates a cp_0001.prof file in the folder.

To answer your question, I am able to open this file in runsnakerun to see the profiling output in a tree view.

The problem I have is that every request I do to the server now fails, with the following output in the log:

[29/May/2013:16:39:32] ENGINE AssertionError('Bad call', ('', 0, 'sleep'), <frame object at 0x08522400>, <frame object at 0x08522030>, <frame object at 0x08156748>, <frame object at 0x06D06F10>)
Traceback (most recent call last):
  File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 1302, in communicate
    req.respond()
  File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 831, in respond
    self.server.gateway(self).respond()
  File "<path>\packages\cherrypy\wsgiserver\wsgiserver2.py", line 2115, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "<path>\packages\cherrypy\_cptree.py", line 290, in __call__
    return app(environ, start_response)
  File "<path>\packages\cherrypy\lib\profiler.py", line 188, in __call__
    return self.profiler.run(gather)
  File "<path>\packages\cherrypy\lib\profiler.py", line 147, in run
    result = self.profiler.runcall(func, *args)
  File "<path>\python\lib\profile.py", line 472, in runcall
    return func(*args, **kw)
  File "<path>\packages\cherrypy\lib\profiler.py", line 183, in gather
    def gather():
  File "<path>\python\lib\profile.py", line 246, in trace_dispatch_i
    if self.dispatch[event](self, frame, t):
  File "<path>\python\lib\profile.py", line 301, in trace_dispatch_call
     frame, frame.f_back)
AssertionError: ('Bad call', ('', 0, 'sleep'), <frame object at 0x08522400>, <frame object at 0x08522030>, <frame object at 0x08156748>, <frame object at 0x06D06F10>)

I am using python 2.6.6 and cherrypy 3.2.2

Any suggestions?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!