python - 使用 line_profiler 分析 Cython 时出错
问题描述
我正在尝试对包含在 .pyx 中并通过 distutils.setup 编译的函数运行线分析器。函数及其调用可以使用 cProfile 进行分析;但是,我正试图找到一个瓶颈,并且线路分析会有所帮助。
我试图设置 Cython 以在我的 pyx 的标题中使用以下内容。
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE_NOGIL=1
我还尝试将 disutils 传递给编译器指令和定义的宏。
compiler_directives={'linetrace': True, 'bindings': True},
define_macros=[('CYTHON_TRACE_NOGIL', '1')])
无论我做什么,线轮廓仪都看不到该功能。我收到以下错误消息:
UserWarning: Could not extract a code object for the object <built-in function x>
# contains convenience functions, global variable definitions, and visualization functions
运行命令行函数“kernprof”具有相同的效果,但错误消息略有不同(但显然相关)。
'builtin_function_or_method' object has no attribute '__code__'
我能够毫无问题地在 .py 文件中对非 cython 函数进行 line_profile 。
解决方案
推荐阅读
- json - jq- 在一个值上合并两个 json 文件
- javascript - iron-ajax bind and write JSON to file
- javascript - Does not change value when I change a date
- c - Array output difficulties
- python - Jupyter Notebook has problem to execute code in cell and it says ' UserWarning: Parent poll failed. '
- javascript - Button with onclick
- java - Getting NotAMockException instead of assertion failure when changing verification mode or expected arguments PowerMock verifyStatic calls
- java - How to handle authentication window in chrome with selenium
- google-colaboratory - /bin/bash:找不到命令 Google Colab
- php - "Header already sent" error in Wordpress site