首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分析CherryPy

分析CherryPy
EN

Stack Overflow用户
提问于 2013-05-19 08:05:15
回答 2查看 1.3K关注 0票数 3

我一直在尝试分析我的CherryPy set服务器,但文档中缺少如何设置的详细信息。我知道我应该能够使用cherrypy.lib.profiler作为中间件来挂载我的初始服务器。现在,我有如下代码:

代码语言:javascript
复制
server_app = ServerClass()
cherrypy.tree.mount(server_app, '/', '/path/to/config/file.cfg')
cherrypy.engine.start()
cherrypy.engine.block()

我想挂载性能分析中间件,似乎需要如下内容:

代码语言:javascript
复制
from cherrypy.lib import profiler

server_app = ServerClass()
server_cpapp = cherrypy.Application(server_app, '/', '/path/to/config/file.cfg')
server_profile_cpapp = profiler.make_app(server_cpapp, '/home/ken/tmp/cprofile', True)
#cherrypy.tree.mount(server_profile_cpapp)
cherrypy.tree.graft(server_profile_cpapp)

cherrypy.engine.start()
cherrypy.engine.block()

由于某种原因,cherrypy.tree.mount无法工作,但如果我使用cherrypy.tree.graft,似乎一切正常(我可以像往常一样向服务器发出请求)

但是,上面的代码在/home/ken/tmp/cprofile下生成了一个cp_0001.prof文件,我不确定如何解释它。我曾尝试使用pyprof2calltree将数据读入KCacheGrind,但得到一个解析错误。我所做的看起来是否正确,如果正确,我该如何解释输出文件?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-19 22:34:10

事实证明,CherryPy生成的配置文件可以使用CherryPy附带的profiler.py脚本进行解释。只需运行<site-packages>/cherrypy/lib目录中的profiler.py,如下所示:

代码语言:javascript
复制
python profiler.py /directory/containing/prof/files 8080

然后在浏览器中导航到localhost:8080,目标目录中所有.prof文件的分析结果将显示在一个简单的文本界面中。

我仍然希望能够使用KCacheGrind将结果导出到调用树中进行分析,但这似乎适用于基本的分析。

在引入profiler时,change log for v2.1 of CherryPy中记录了这一点(尽管该页面上描述如何设置profiler的其他详细信息已被弃用)

票数 5
EN

Stack Overflow用户

发布于 2013-05-29 23:00:05

我还在尝试为一个cherrypy实例启动并运行性能分析。我在最初的问题中使用了相同的代码,这似乎是可行的,因为它会在文件夹中生成一个cp_0001.prof文件。

为了回答您的问题,我可以在runsnakerun中打开此文件,在树视图中查看性能分析输出。

我遇到的问题是,我向服务器发出的每个请求现在都会失败,在日志中会出现以下输出:

代码语言:javascript
复制
[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>)

我使用的是python 2.6.6和cherrypy 3.2.2

有什么建议吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16630208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档