您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

分析python C扩展

分析python C扩展

我已经找到了使用google-perftools的方式。诀窍是将函数StartProfiler和StopProfiler包装在python中(在我的情况下为cython)。

要分析C扩展名,就足以将python代码包装在StartProfiler和StopProfiler调用内。

from google_perftools_wrapped import StartProfiler, StopProfiler
import c_extension # extension to profile c_extension.so

StartProfiler("output.prof")
... calling the interesting functions from the C extension module ...
StopProfiler()

然后进行分析,例如您可以以callgrind格式导出并在kcachegrind中查看结果:

pprof --callgrind c_extension.so output.prof > output.callgrind 
kcachegrind output.callgrind
python 2022/1/1 18:53:06 有335人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶