我有一个使用许多 nogil cdef 函数的应用程序,我想对它们进行分析 为了找到瓶颈。
我尝试将 profile=True 指令传递给 Cython,但这些函数似乎是免疫的,因此 cProfile.run() 的输出包含函数调用 cdef 函数,但不是 cdef 函数本身。
是否有其他指令或分析器可用于分析 cdef 函数?
编辑:this is link to the application file that I am referring to... .为了配置文件,您必须设置:
#cython: profile=True
在标题处。
请您参考如下方法:
探查器需要gil,因此,借助@Veedrac 的评论,解决方案是:
- 仅使用
cdef函数而不使用nogil指令 - 在
.pyx( or somewhere else ) 的 header 设置#cython: profile=True
这里的缺点是,通过删除 nogil,不能使用 prange 来分析并行执行。另一个问题仍然存在……是否可以分析 nogil 函数?
