Commit a961ab0c authored by Robert Bradshaw's avatar Robert Bradshaw

Fix profiling through cpdef methods.

The cPython profiler would get confused when the wrapper and
underlying cdef function shared a name.
parent e379d27d
......@@ -1896,7 +1896,12 @@ class FuncDefNode(StatNode, BlockNode):
if profile or linetrace:
# this looks a bit late, but if we don't get here due to a
# fatal error before hand, it's not really worth tracing
code.put_trace_call(self.entry.name, self.pos, nogil=not code.funcstate.gil_owned)
if isinstance(self, DefNode) and self.is_wrapper:
trace_name = self.entry.name + " (wrapper)"
else:
trace_name = self.entry.name
code.put_trace_call(
trace_name, self.pos, nogil=not code.funcstate.gil_owned)
code.funcstate.can_trace = True
# ----- Fetch arguments
self.generate_argument_parsing_code(env, code)
......@@ -2099,9 +2104,11 @@ class FuncDefNode(StatNode, BlockNode):
if profile or linetrace:
code.funcstate.can_trace = False
if self.return_type.is_pyobject:
code.put_trace_return(Naming.retval_cname, nogil=not code.funcstate.gil_owned)
code.put_trace_return(
Naming.retval_cname, nogil=not code.funcstate.gil_owned)
else:
code.put_trace_return("Py_None", nogil=not code.funcstate.gil_owned)
code.put_trace_return(
"Py_None", nogil=not code.funcstate.gil_owned)
if not lenv.nogil:
# GIL holding function
......
......@@ -11,6 +11,10 @@ __doc__ = u"""
100
>>> short_stats['f_cdef']
100
>>> short_stats['f_cpdef']
200
>>> short_stats['f_cpdef (wrapper)']
100
>>> short_stats['f_inline']
100
>>> short_stats['f_inline_prof']
......@@ -51,6 +55,8 @@ def test_profile(long N):
for i from 0 <= i < N:
n += f_def(i)
n += f_cdef(i)
n += f_cpdef(i)
n += (<object>f_cpdef)(i)
n += f_inline(i)
n += f_inline_prof(i)
n += f_noprof(i)
......@@ -70,6 +76,9 @@ def f_def(long a):
cdef long f_cdef(long a):
return a
cpdef long f_cpdef(long a):
return a
cdef inline long f_inline(long a):
return a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment