diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-30 21:27:00 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-30 21:27:00 (GMT) |
commit | 46dbe27f7e7a053c9b44155664dc02aa12b0717e (patch) | |
tree | bd0ae24121dc36127136a4885b6b50f4778bef08 | |
parent | 2152ca390b80f9443997039bbbc55e19e9a2c6d8 (diff) | |
download | cpython-46dbe27f7e7a053c9b44155664dc02aa12b0717e.zip cpython-46dbe27f7e7a053c9b44155664dc02aa12b0717e.tar.gz cpython-46dbe27f7e7a053c9b44155664dc02aa12b0717e.tar.bz2 |
Issue #5330: C functions called with keyword arguments were not reported by
the various profiling modules (profile, cProfile). Patch by Hagen Fürstenau.
-rwxr-xr-x | Lib/test/test_cprofile.py | 1 | ||||
-rwxr-xr-x | Lib/test/test_profile.py | 20 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/ceval.c | 18 |
4 files changed, 40 insertions, 2 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index 13c1060..831895c 100755 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -9,6 +9,7 @@ from test.test_profile import ProfileTest, regenerate_expected_output class CProfileTest(ProfileTest): profilerclass = cProfile.Profile + expected_list_sort_output = "{method 'sort' of 'list' objects}" # Issue 3895. def test_bad_counter_during_dealloc(self): diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py index 0bd2530..421aa1b 100755 --- a/Lib/test/test_profile.py +++ b/Lib/test/test_profile.py @@ -16,6 +16,7 @@ class ProfileTest(unittest.TestCase): profilerclass = profile.Profile methodnames = ['print_stats', 'print_callers', 'print_callees'] expected_output = {} + expected_list_sort_output = ':0(sort)' @classmethod def do_profiling(cls): @@ -40,6 +41,25 @@ class ProfileTest(unittest.TestCase): "Stats.%s output for %s doesn't fit expectation!" % (method, self.profilerclass.__name__)) + def test_calling_conventions(self): + # Issue #5330: profile and cProfile wouldn't report C functions called + # with keyword arguments. We test all calling conventions. + prof = self.profilerclass(timer, 0.001) + stmts = [ + "[].sort()", + "[].sort(reverse=True)", + "[].sort(*(None, None, True))", + "[].sort(**dict(reverse=True))", + ] + for stmt in stmts: + s = StringIO() + prof.runctx(stmt, globals(), locals()) + stats = pstats.Stats(prof, stream=s) + stats.print_stats() + res = s.getvalue() + self.assertTrue(self.expected_list_sort_output in res, + "Profiling {0!r} didn't report list.sort:\n{1}".format(stmt, res)) + def regenerate_expected_output(filename, cls): filename = filename.rstrip('co') @@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1 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. + - Issue #5982: staticmethod and classmethod now expose the wrapped function with __func__. diff --git a/Python/ceval.c b/Python/ceval.c index 92021e6..dd91f5d 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4160,10 +4160,17 @@ do_call(PyObject *func, PyObject ***pp_stack, int na, int nk) 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); @@ -4248,10 +4255,17 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk) 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); |