summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2012-06-22 18:55:41 (GMT)
committerDavid Malcolm <dmalcolm@redhat.com>2012-06-22 18:55:41 (GMT)
commit49526f48fc73d3ccdf09d466ed2d39a30e4df9b9 (patch)
tree51ac80c4d09ca4a537518555710423675a6ac731 /Python
parent69cf913ba110de2eb773c030b1dd606456ac5831 (diff)
downloadcpython-49526f48fc73d3ccdf09d466ed2d39a30e4df9b9.zip
cpython-49526f48fc73d3ccdf09d466ed2d39a30e4df9b9.tar.gz
cpython-49526f48fc73d3ccdf09d466ed2d39a30e4df9b9.tar.bz2
Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c2
-rw-r--r--Python/sysmodule.c23
2 files changed, 24 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index d9d2fdd..465aa7d 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -642,7 +642,7 @@ Py_Finalize(void)
#endif /* Py_TRACE_REFS */
#ifdef PYMALLOC_DEBUG
if (Py_GETENV("PYTHONMALLOCSTATS"))
- _PyObject_DebugMallocStats();
+ _PyObject_DebugMallocStats(stderr);
#endif
call_ll_exitfuncs();
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 096e51e..ce5e825 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 */
};