summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2012-06-22 14:55:41 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2012-06-22 14:55:41 -0400
commitc66679874d42ebaddde9958928171a8bb318b116 (patch)
tree1b3fa840264d3c74665678ee7e8735fafe44125d /Python/sysmodule.c
parentec1b06d577d16cf06f2789b8e556781a276d54b1 (diff)
downloadcpython-c66679874d42ebaddde9958928171a8bb318b116.tar.gz
Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 096e51e9f9..ce5e8258d1 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -997,6 +997,27 @@ a 11-tuple where the entries in the tuple are counts of:\n\
extern "C" {
#endif
+static PyObject *
+sys_debugmallocstats(PyObject *self, PyObject *args)
+{
+#ifdef WITH_PYMALLOC
+ _PyObject_DebugMallocStats(stderr);
+ fputc('\n', stderr);
+#endif
+ _PyObject_DebugTypeStats(stderr);
+
+ Py_RETURN_NONE;
+}
+PyDoc_STRVAR(debugmallocstats_doc,
+"_debugmallocstats()\n\
+\n\
+Print summary info to stderr about the state of\n\
+pymalloc's structures.\n\
+\n\
+In Py_DEBUG mode, also perform some expensive internal consistency\n\
+checks.\n\
+");
+
#ifdef Py_TRACE_REFS
/* Defined in objects.c because it uses static globals if that file */
extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
@@ -1093,6 +1114,8 @@ static PyMethodDef sys_methods[] = {
{"settrace", sys_settrace, METH_O, settrace_doc},
{"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
+ {"_debugmallocstats", sys_debugmallocstats, METH_VARARGS,
+ debugmallocstats_doc},
{NULL, NULL} /* sentinel */
};