class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile
+ expected_max_output = "{built-in method max}"
def get_expected_output(self):
return _ProfileOutput
profilerclass = profile.Profile
methodnames = ['print_stats', 'print_callers', 'print_callees']
+ expected_max_output = ':0(max)'
def get_expected_output(self):
return _ProfileOutput
results[i+1].split('\n'),
expected[method].split('\n'))))
+ def test_calling_conventions(self):
+ # Issue #5330: profile and cProfile wouldn't report C functions called
+ # with keyword arguments. We test all calling conventions.
+ stmts = [
+ "max([0])",
+ "max([0], key=int)",
+ "max([0], **dict(key=int))",
+ "max(*([0],))",
+ "max(*([0],), key=int)",
+ "max(*([0],), **dict(key=int))",
+ ]
+ for stmt in stmts:
+ s = StringIO()
+ prof = self.profilerclass(timer, 0.001)
+ prof.runctx(stmt, globals(), locals())
+ stats = pstats.Stats(prof, stream=s)
+ stats.print_stats()
+ res = s.getvalue()
+ self.assertTrue(self.expected_max_output in res,
+ "Profiling {0!r} didn't report max:\n{1}".format(stmt, res))
+
def regenerate_expected_output(filename, cls):
filename = filename.rstrip('co')
Core and Builtins
-----------------
+- Issue #5330: C functions called with keyword arguments were not reported by
+ the various profiling modules (profile, cProfile). Patch by Hagen Fürstenau.
+
Library
-------
PCALL(PCALL_METHOD);
else if (PyType_Check(func))
PCALL(PCALL_TYPE);
+ else if (PyCFunction_Check(func))
+ PCALL(PCALL_CFUNCTION);
else
PCALL(PCALL_OTHER);
#endif
- result = PyObject_Call(func, callargs, kwdict);
+ if (PyCFunction_Check(func)) {
+ PyThreadState *tstate = PyThreadState_GET();
+ C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
+ }
+ else
+ result = PyObject_Call(func, callargs, kwdict);
call_fail:
Py_XDECREF(callargs);
Py_XDECREF(kwdict);
PCALL(PCALL_METHOD);
else if (PyType_Check(func))
PCALL(PCALL_TYPE);
+ else if (PyCFunction_Check(func))
+ PCALL(PCALL_CFUNCTION);
else
PCALL(PCALL_OTHER);
#endif
- result = PyObject_Call(func, callargs, kwdict);
+ if (PyCFunction_Check(func)) {
+ PyThreadState *tstate = PyThreadState_GET();
+ C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
+ }
+ else
+ result = PyObject_Call(func, callargs, kwdict);
ext_call_fail:
Py_XDECREF(callargs);
Py_XDECREF(kwdict);