我一直在尝试开始分析我的 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.graft
all 似乎运行良好(我可以正常向服务器发出请求)
但是,上面的代码生成了一个cp_0001.prof
文件/home/ken/tmp/cprofile
,我不知道如何解释它。我曾尝试使用pyprof2calltree
将数据读入 KCacheGrind,但出现解析错误。我在做什么似乎正确,如果是,我该如何解释输出文件?