Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e160ce

Browse files
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.
1 parent 6c94d10 commit 7e160ce

7 files changed

Lines changed: 50 additions & 1 deletion

File tree

Doc/using/cmdline.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ Miscellaneous options
397397
stored in a traceback of a trace. Use ``-X tracemalloc=NFRAME`` to start
398398
tracing with a traceback limit of *NFRAME* frames. See the
399399
:func:`tracemalloc.start` for more information.
400+
* ``-X showalloccount`` to enable the output of the total count of allocated
401+
objects for each type (only works when built with ``COUNT_ALLOCS`` defined);
400402

401403
It also allows passing arbitrary values and retrieving them through the
402404
:data:`sys._xoptions` dictionary.
@@ -410,6 +412,9 @@ Miscellaneous options
410412
.. versionadded:: 3.4
411413
The ``-X showrefcount`` and ``-X tracemalloc`` options.
412414

415+
.. versionadded:: 3.6
416+
The ``-X showalloccount`` option.
417+
413418

414419
Options you shouldn't use
415420
~~~~~~~~~~~~~~~~~~~~~~~~~

Doc/whatsnew/3.6.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,16 @@ Porting to Python 3.6
646646
This section lists previously described changes and other bugfixes
647647
that may require changes to your code.
648648

649+
Changes in 'python' Command Behavior
650+
------------------------------------
651+
652+
* The output of a special Python build with defined ``COUNT_ALLOCS``,
653+
``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by
654+
default. It can be re-enabled using the ``-X showalloccount`` option.
655+
It now outputs to ``stderr`` instead of ``stdout``.
656+
(Contributed by Serhiy Storchaka in :issue:`23034`.)
657+
658+
649659
Changes in the Python API
650660
-------------------------
651661

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 3
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #23034: The output of a special Python build with defined COUNT_ALLOCS,
14+
SHOW_ALLOC_COUNT or SHOW_TRACK_COUNT macros is now off by default. It can
15+
be re-enabled using the "-X showalloccount" option. It now outputs to stderr
16+
instead of stdout.
17+
1318
- Issue #27443: __length_hint__() of bytearray itearator no longer return
1419
negative integer for resized bytearray.
1520

Objects/listobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ static size_t count_reuse = 0;
8282
static void
8383
show_alloc(void)
8484
{
85+
PyObject *xoptions, *value;
86+
_Py_IDENTIFIER(showalloccount);
87+
88+
xoptions = PySys_GetXOptions();
89+
if (xoptions == NULL)
90+
return;
91+
value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
92+
if (value != Py_True)
93+
return;
94+
8595
fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n",
8696
count_alloc);
8797
fprintf(stderr, "List reuse through freelist: %" PY_FORMAT_SIZE_T

Objects/object.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ void
109109
dump_counts(FILE* f)
110110
{
111111
PyTypeObject *tp;
112+
PyObject *xoptions, *value;
113+
_Py_IDENTIFIER(showalloccount);
114+
115+
xoptions = PySys_GetXOptions();
116+
if (xoptions == NULL)
117+
return;
118+
value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
119+
if (value != Py_True)
120+
return;
112121

113122
for (tp = type_list; tp; tp = tp->tp_next)
114123
fprintf(f, "%s alloc'd: %" PY_FORMAT_SIZE_T "d, "

Objects/tupleobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ static Py_ssize_t count_tracked = 0;
3636
static void
3737
show_track(void)
3838
{
39+
PyObject *xoptions, *value;
40+
_Py_IDENTIFIER(showalloccount);
41+
42+
xoptions = PySys_GetXOptions();
43+
if (xoptions == NULL)
44+
return;
45+
value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
46+
if (value != Py_True)
47+
return;
48+
3949
fprintf(stderr, "Tuples created: %" PY_FORMAT_SIZE_T "d\n",
4050
count_tracked + count_untracked);
4151
fprintf(stderr, "Tuples tracked by the GC: %" PY_FORMAT_SIZE_T

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ Py_FinalizeEx(void)
626626

627627
/* Debugging stuff */
628628
#ifdef COUNT_ALLOCS
629-
dump_counts(stdout);
629+
dump_counts(stderr);
630630
#endif
631631
/* dump hash stats */
632632
_PyHash_Fini();

0 commit comments

Comments
 (0)