File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
414419Options you shouldn't use
415420~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -646,6 +646,16 @@ Porting to Python 3.6
646646This section lists previously described changes and other bugfixes
647647that 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+
649659Changes in the Python API
650660-------------------------
651661
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 3
1010Core 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
Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ static size_t count_reuse = 0;
8282static void
8383show_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
Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ void
109109dump_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, "
Original file line number Diff line number Diff line change @@ -36,6 +36,16 @@ static Py_ssize_t count_tracked = 0;
3636static void
3737show_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
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments