I am trying to run a line profiler on a function contained in a .pyx and compiled via distutils.setup. The function and its calls can be profiled with cProfile; however, I am trying to find a bottleneck and line profiling would help.
I have tried to set up Cython to use the below in the header of my pyx.
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE_NOGIL=1
I have also tried passing disutils the compiler directives and defined macros.
compiler_directives={'linetrace': True, 'bindings': True},
define_macros=[('CYTHON_TRACE_NOGIL', '1')])
No matter what I do, the line profiler cannot see the function. I get the following error message:
UserWarning: Could not extract a code object for the object <built-in function x>
# contains convenience functions, global variable definitions, and visualization functions
Running the command line functions "kernprof" has the same effect with a slightly different error message (but obviously related).
'builtin_function_or_method' object has no attribute '__code__'
I am able to line_profile non-cython functions in the .py file without issue.