Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8477f7a

Browse files
committed
Issue #21863: cProfile now displays the module name of C extension functions, in addition to their own name.
1 parent 0882e27 commit 8477f7a

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

Lib/test/test_cprofile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class CProfileTest(ProfileTest):
1212
profilerclass = cProfile.Profile
1313
profilermodule = cProfile
14-
expected_max_output = "{built-in method max}"
14+
expected_max_output = "{built-in method builtins.max}"
1515

1616
def get_expected_output(self):
1717
return _ProfileOutput
@@ -72,9 +72,9 @@ def main():
7272
profilee.py:88(helper2) <- 6 0.234 0.300 profilee.py:55(helper)
7373
2 0.078 0.100 profilee.py:84(helper2_indirect)
7474
profilee.py:98(subhelper) <- 8 0.064 0.080 profilee.py:88(helper2)
75-
{built-in method exc_info} <- 4 0.000 0.000 profilee.py:73(helper1)
76-
{built-in method hasattr} <- 4 0.000 0.004 profilee.py:73(helper1)
75+
{built-in method builtins.hasattr} <- 4 0.000 0.004 profilee.py:73(helper1)
7776
8 0.000 0.008 profilee.py:88(helper2)
77+
{built-in method sys.exc_info} <- 4 0.000 0.000 profilee.py:73(helper1)
7878
{method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)"""
7979
_ProfileOutput['print_callees'] = """\
8080
<string>:1(<module>) -> 1 0.270 1.000 profilee.py:25(testfunc)
@@ -87,12 +87,12 @@ def main():
8787
profilee.py:55(helper) -> 4 0.116 0.120 profilee.py:73(helper1)
8888
2 0.000 0.140 profilee.py:84(helper2_indirect)
8989
6 0.234 0.300 profilee.py:88(helper2)
90-
profilee.py:73(helper1) -> 4 0.000 0.000 {built-in method exc_info}
90+
profilee.py:73(helper1) -> 4 0.000 0.004 {built-in method builtins.hasattr}
9191
profilee.py:84(helper2_indirect) -> 2 0.006 0.040 profilee.py:35(factorial)
9292
2 0.078 0.100 profilee.py:88(helper2)
9393
profilee.py:88(helper2) -> 8 0.064 0.080 profilee.py:98(subhelper)
9494
profilee.py:98(subhelper) -> 16 0.016 0.016 profilee.py:110(__getattr__)
95-
{built-in method hasattr} -> 12 0.012 0.012 profilee.py:110(__getattr__)"""
95+
{built-in method builtins.hasattr} -> 12 0.012 0.012 profilee.py:110(__getattr__)"""
9696

9797
if __name__ == "__main__":
9898
main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Core and Builtins
103103
Library
104104
-------
105105

106+
- Issue #21863: cProfile now displays the module name of C extension functions,
107+
in addition to their own name.
108+
106109
- Issue #11453: asyncore: emit a ResourceWarning when an unclosed file_wrapper
107110
object is destroyed. The destructor now closes the file if needed. The
108111
close() method can now be called twice: the second call does nothing.

Modules/_lsprof.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ normalizeUserObj(PyObject *obj)
202202
*/
203203
PyObject *self = fn->m_self;
204204
PyObject *name = PyUnicode_FromString(fn->m_ml->ml_name);
205+
PyObject *modname = fn->m_module;
206+
205207
if (name != NULL) {
206208
PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
207209
Py_XINCREF(mo);
@@ -213,9 +215,14 @@ normalizeUserObj(PyObject *obj)
213215
return res;
214216
}
215217
}
218+
/* Otherwise, use __module__ */
216219
PyErr_Clear();
217-
return PyUnicode_FromFormat("<built-in method %s>",
218-
fn->m_ml->ml_name);
220+
if (modname != NULL && PyUnicode_Check(modname))
221+
return PyUnicode_FromFormat("<built-in method %S.%s>",
222+
modname, fn->m_ml->ml_name);
223+
else
224+
return PyUnicode_FromFormat("<built-in method %s>",
225+
fn->m_ml->ml_name);
219226
}
220227
}
221228

0 commit comments

Comments
 (0)