changeset: 102250:cd911e06bf6c user: Serhiy Storchaka date: Sun Jul 03 21:03:53 2016 +0300 files: Doc/using/cmdline.rst Doc/whatsnew/3.6.rst Misc/NEWS Objects/listobject.c Objects/object.c Objects/tupleobject.c Python/pylifecycle.c description: Issue #23034: The output of a special Python build with defined COUNT_ALLOCS, SHOW_ALLOC_COUNT or SHOW_TRACK_COUNT macros is now off by default. It can be re-enabled using the "-X showalloccount" option. It now outputs to stderr instead of stdout. diff -r 03192909160d -r cd911e06bf6c Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst Sun Jul 03 14:42:17 2016 +0300 +++ b/Doc/using/cmdline.rst Sun Jul 03 21:03:53 2016 +0300 @@ -397,6 +397,8 @@ 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 passing arbitrary values and retrieving them through the :data:`sys._xoptions` dictionary. @@ -410,6 +412,9 @@ .. versionadded:: 3.4 The ``-X showrefcount`` and ``-X tracemalloc`` options. + .. versionadded:: 3.6 + The ``-X showalloccount`` option. + Options you shouldn't use ~~~~~~~~~~~~~~~~~~~~~~~~~ diff -r 03192909160d -r cd911e06bf6c Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst Sun Jul 03 14:42:17 2016 +0300 +++ b/Doc/whatsnew/3.6.rst Sun Jul 03 21:03:53 2016 +0300 @@ -646,6 +646,16 @@ This section lists previously described changes and other bugfixes that may require changes to your code. +Changes in 'python' Command Behavior +------------------------------------ + +* The output of a special Python build with defined ``COUNT_ALLOCS``, + ``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by + default. It can be re-enabled using the ``-X showalloccount`` option. + It now outputs to ``stderr`` instead of ``stdout``. + (Contributed by Serhiy Storchaka in :issue:`23034`.) + + Changes in the Python API ------------------------- diff -r 03192909160d -r cd911e06bf6c Misc/NEWS --- a/Misc/NEWS Sun Jul 03 14:42:17 2016 +0300 +++ b/Misc/NEWS Sun Jul 03 21:03:53 2016 +0300 @@ -10,6 +10,11 @@ Core and Builtins ----------------- +- Issue #23034: The output of a special Python build with defined COUNT_ALLOCS, + SHOW_ALLOC_COUNT or SHOW_TRACK_COUNT macros is now off by default. It can + be re-enabled using the "-X showalloccount" option. It now outputs to stderr + instead of stdout. + - Issue #27443: __length_hint__() of bytearray itearator no longer return negative integer for resized bytearray. diff -r 03192909160d -r cd911e06bf6c Objects/listobject.c --- a/Objects/listobject.c Sun Jul 03 14:42:17 2016 +0300 +++ b/Objects/listobject.c Sun Jul 03 21:03:53 2016 +0300 @@ -82,6 +82,16 @@ 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 03192909160d -r cd911e06bf6c Objects/object.c --- a/Objects/object.c Sun Jul 03 14:42:17 2016 +0300 +++ b/Objects/object.c Sun Jul 03 21:03:53 2016 +0300 @@ -109,6 +109,15 @@ 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 03192909160d -r cd911e06bf6c Objects/tupleobject.c --- a/Objects/tupleobject.c Sun Jul 03 14:42:17 2016 +0300 +++ b/Objects/tupleobject.c Sun Jul 03 21:03:53 2016 +0300 @@ -36,6 +36,16 @@ 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 03192909160d -r cd911e06bf6c Python/pylifecycle.c --- a/Python/pylifecycle.c Sun Jul 03 14:42:17 2016 +0300 +++ b/Python/pylifecycle.c Sun Jul 03 21:03:53 2016 +0300 @@ -626,7 +626,7 @@ /* Debugging stuff */ #ifdef COUNT_ALLOCS - dump_counts(stdout); + dump_counts(stderr); #endif /* dump hash stats */ _PyHash_Fini();