summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2003-02-05 23:13:00 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2003-02-05 23:13:00 (GMT)
commit985eba53f5d1ac45037fbf19b6955c74823c1ded (patch)
treef847567e9468a46df6f0a55b7d437a3697e7f248 /Python/sysmodule.c
parentf3f4af55214370e5c6df928e8c8242d14060e204 (diff)
downloadcpython-985eba53f5d1ac45037fbf19b6955c74823c1ded.zip
cpython-985eba53f5d1ac45037fbf19b6955c74823c1ded.tar.gz
cpython-985eba53f5d1ac45037fbf19b6955c74823c1ded.tar.bz2
Small function call optimization and special build option for call stats.
-DCALL_PROFILE: Count the number of function calls executed. When this symbol is defined, the ceval mainloop and helper functions count the number of function calls made. It keeps detailed statistics about what kind of object was called and whether the call hit any of the special fast paths in the code. Optimization: When we take the fast_function() path, which seems to be taken for most function calls, and there is minimal frame setup to do, avoid call PyEval_EvalCodeEx(). The eval code ex function does a lot of work to handle keywords args and star args, free variables, generators, etc. The inlined version simply allocates the frame and copies the arguments values into the frame. The optimization gets a little help from compile.c which adds a CO_NOFREE flag to code objects that don't have free variables or cell variables. This change allows fast_function() to get into the fast path with fewer tests. I measure a couple of percent speedup in pystone with this change, but there's surely more that can be done.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 2b4c6b4..765621e 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -562,6 +562,28 @@ sys_getframe(PyObject *self, PyObject *args)
return (PyObject*)f;
}
+PyDoc_STRVAR(callstats_doc,
+"callstats() -> tuple of integers\n\
+\n\
+Return a tuple of function call statistics, if CALL_PROFILE was defined\n\
+when Python was built. Otherwise, return None.\n\
+\n\
+When enabled, this function returns detailed, implementation-specific\n\
+details about the number of function calls executed. The return value is\n\
+a 11-tuple where the entries in the tuple are counts of:\n\
+0. all function calls\n\
+1. calls to PyFunction_Type objects\n\
+2. PyFunction calls that do not create an argument tuple\n\
+3. PyFunction calls that do not create an argument tuple\n\
+ and bypass PyEval_EvalCodeEx()\n\
+4. PyMethod calls\n\
+5. PyMethod calls on bound methods\n\
+6. PyType calls\n\
+7. PyCFunction calls\n\
+8. generator calls\n\
+9. All other calls\n\
+10. Number of stack pops performed by call_function()"
+);
#ifdef Py_TRACE_REFS
/* Defined in objects.c because it uses static globals if that file */
@@ -575,13 +597,15 @@ extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
+ {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
+ callstats_doc},
{"displayhook", sys_displayhook, METH_O, displayhook_doc},
{"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc},
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
{"exit", sys_exit, METH_VARARGS, exit_doc},
#ifdef Py_USING_UNICODE
- {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS,
- getdefaultencoding_doc},
+ {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
+ METH_NOARGS, getdefaultencoding_doc},
#endif
#ifdef HAVE_DLOPEN
{"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,