分析CherryPy [英] Profiling CherryPy

查看:60
本文介绍了分析CherryPy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to start profiling my CherryPy webserver, but the documentation is lacking in detail in how this should be set up. I understand that I should be able to use cherrypy.lib.profiler as middleware to mount my initial server. Right now, I have code like the following:

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

我想安装性能分析中间件,看来需要以下内容:

I want to mount the profiling middleware, and it seems that something like the following is required:

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,一切似乎都可以正常运行(我可以像往常一样向服务器发出请求)

For some reason cherrypy.tree.mount doesn't work, but if I use cherrypy.tree.graft all seems to operate fine (I can make requests to the server as normal)

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

However, the above code generates a cp_0001.prof file under /home/ken/tmp/cprofile and I am not sure how to interpret it. I have tried using pyprof2calltree to read the data into KCacheGrind, but I get a parsing error. Does what I'm doing seem correct, and if so how do I interpret the output file?

推荐答案

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

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

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

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.

我仍然希望能够将结果导出到调用树中,以使用KCacheGrind进行概要分析,但这似乎可以进行基本的分析.

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.

当探查器在 v2.1的更改日志中记录引入了(尽管此页上描述如何设置事件探查器的其他详细信息已被弃用)

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)

这篇关于分析CherryPy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆