diff -r 39df27d97901 Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst Tue May 12 14:00:22 2015 +0300 +++ b/Doc/using/cmdline.rst Tue May 12 16:46:09 2015 +0300 @@ -397,6 +397,8 @@ Miscellaneous options stored in a traceback of a trace. Use ``-X tracemalloc=NFRAME`` to start tracing with a traceback limit of *NFRAME* frames. See the :func:`tracemalloc.start` for more information. + * ``-X showalloccount`` to enable the output of the total count of allocated + objects for each type (only works when built with ``COUNT_ALLOCS`` defined); It also allows to pass arbitrary values and retrieve them through the :data:`sys._xoptions` dictionary. @@ -410,6 +412,9 @@ Miscellaneous options .. versionadded:: 3.4 The ``-X showrefcount`` and ``-X tracemalloc`` options. + .. versionadded:: 3.5 + The ``-X showalloccount`` option. + Options you shouldn't use ~~~~~~~~~~~~~~~~~~~~~~~~~ diff -r 39df27d97901 Objects/listobject.c --- a/Objects/listobject.c Tue May 12 14:00:22 2015 +0300 +++ b/Objects/listobject.c Tue May 12 16:46:09 2015 +0300 @@ -82,6 +82,16 @@ static size_t count_reuse = 0; static void show_alloc(void) { + PyObject *xoptions, *value; + _Py_IDENTIFIER(showalloccount); + + xoptions = PySys_GetXOptions(); + if (xoptions == NULL) + return; + value = _PyDict_GetItemId(xoptions, &PyId_showalloccount); + if (value != Py_True) + return; + fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n", count_alloc); fprintf(stderr, "List reuse through freelist: %" PY_FORMAT_SIZE_T diff -r 39df27d97901 Objects/object.c --- a/Objects/object.c Tue May 12 14:00:22 2015 +0300 +++ b/Objects/object.c Tue May 12 16:46:09 2015 +0300 @@ -109,6 +109,15 @@ void dump_counts(FILE* f) { PyTypeObject *tp; + PyObject *xoptions, *value; + _Py_IDENTIFIER(showalloccount); + + xoptions = PySys_GetXOptions(); + if (xoptions == NULL) + return; + value = _PyDict_GetItemId(xoptions, &PyId_showalloccount); + if (value != Py_True) + return; for (tp = type_list; tp; tp = tp->tp_next) fprintf(f, "%s alloc'd: %" PY_FORMAT_SIZE_T "d, " diff -r 39df27d97901 Objects/tupleobject.c --- a/Objects/tupleobject.c Tue May 12 14:00:22 2015 +0300 +++ b/Objects/tupleobject.c Tue May 12 16:46:09 2015 +0300 @@ -36,6 +36,16 @@ static Py_ssize_t count_tracked = 0; static void show_track(void) { + PyObject *xoptions, *value; + _Py_IDENTIFIER(showalloccount); + + xoptions = PySys_GetXOptions(); + if (xoptions == NULL) + return; + value = _PyDict_GetItemId(xoptions, &PyId_showalloccount); + if (value != Py_True) + return; + fprintf(stderr, "Tuples created: %" PY_FORMAT_SIZE_T "d\n", count_tracked + count_untracked); fprintf(stderr, "Tuples tracked by the GC: %" PY_FORMAT_SIZE_T diff -r 39df27d97901 Python/pylifecycle.c --- a/Python/pylifecycle.c Tue May 12 14:00:22 2015 +0300 +++ b/Python/pylifecycle.c Tue May 12 16:46:09 2015 +0300 @@ -612,7 +612,7 @@ Py_Finalize(void) /* Debugging stuff */ #ifdef COUNT_ALLOCS - dump_counts(stdout); + dump_counts(stderr); #endif /* dump hash stats */ _PyHash_Fini();