3

我一直在尝试开始分析我的 CherryPy 网络服务器,但是文档没有详细说明应该如何设置它。我知道我应该能够cherrypy.lib.profiler用作中间件来安装我的初始服务器。现在,我有如下代码:

server_app = ServerClass()
cherrypy.tree.mount(server_app, '/', '/path/to/config/file.cfg')
cherrypy.engine.start()
cherrypy.engine.block()

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

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.graftall 似乎运行良好(我可以正常向服务器发出请求)

但是,上面的代码生成了一个cp_0001.prof文件/home/ken/tmp/cprofile,我不知道如何解释它。我曾尝试使用pyprof2calltree将数据读入 KCacheGrind,但出现解析错误。我在做什么似乎正确,如果是,我该如何解释输出文件?

4

2 回答 2

5

事实证明,CherryPy 生成的配置文件可以使用profiler.py作为 CherryPy 的一部分提供的脚本来解释。只需profiler.py<site-packages>/cherrypy/lib目录中运行如下:

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

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

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

引入分析器时,CherryPy v2.1的更改日志中记录了这一点(尽管该页面上描述如何设置分析器的其他详细信息已被弃用)

于 2013-05-19T14:34:10.473 回答
1

我也在尝试为一个cherrypy实例启动和运行分析。我在最初的问题中使用了相同的代码,这似乎可以在文件夹中生成一个 cp_0001.prof 文件。

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

我遇到的问题是我对服务器所做的每个请求现在都失败了,日志中的输出如下:

[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

有什么建议么?

于 2013-05-29T15:00:04.920 回答