OK, now I found what caused this difference.
lsprof expect `func` is PyCFunction object. But it can be PyMethodDescrObject when LOAD_METHOD is used to call C method.
In Modules/_lsprof.c (line 459):
case PyTrace_C_CALL:
if ((((ProfilerObject *)self)->flags & POF_BUILTINS)
&& PyCFunction_Check(arg)) {
ptrace_enter_call(self,
((PyCFunctionObject *)arg)->m_ml,
arg);
}
Document says just it's "Function object being called."
https://docs.python.org/3.6/c-api/init.html#c.Py_tracefunc
If "function object" means "any C object having tp_call", most easy way to solve this issue is adding PyMethodDescrObject support to lsprof.
PyEval_GetFuncName() and PyEval_GetFuncDesc() should support it too.
As a bonus, `list.append(L, x)` will be profiled like `L.append(x)`. It looks more consistent.
On the other hand, if it means it's PyCFunction, we can't call PyMethodDescrObject directly.
Since PyEval_SetProfile() is old function, I chose later way for now. |