[Cython] line tracing/profiling code objects
Syam Gadde
syam.gadde at duke.edu
Thu Feb 27 16:22:10 CET 2014
Hi all,
I tried using line tracing in conjunction with line_profiler/kernprof to
attempt to see if line-based profiling works in Cython. I think it's
pretty close. But I think the problem is that line_profiler is getting
a different PyCodeObject when it wraps the function and when it actually
gets the trace call. It adds the initial code object to a map, and
later when it gets the trace call, decides that the trace call is not
something it needs to pay attention to because the new code object that
it gets is not the same as the original one.
The first code object is created at function declaration by
__Pyx_PyCode_New (called in__Pyx_InitCachedConstants) and is assigned to
a variable __pyx_k_codeobj_NNN. The second code object is created,
essentially, during the first entry into the function (in
__Pyx_TraceCall, via __Pyx_TraceSetupAndCall). It seems that setting
__pyx_frame_code to the initial code object before calling TraceCall()
would fix this.
Is this easy to do? I'd do it myself, but I'd need help figuring out
how to get the name of the appropriate __pyx_k_codeobj_NNN variable from
within FuncDefNode.generate_function_definitions(), which calls
put_trace_call().
Thanks for your help...
-syam
More information about the cython-devel
mailing list