]> granicus.if.org Git - python/commitdiff
Issue #23034: The output of a special Python build with defined COUNT_ALLOCS,
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 3 Jul 2016 18:03:53 +0000 (21:03 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 3 Jul 2016 18:03:53 +0000 (21:03 +0300)
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.

Doc/using/cmdline.rst
Doc/whatsnew/3.6.rst
Misc/NEWS
Objects/listobject.c
Objects/object.c
Objects/tupleobject.c
Python/pylifecycle.c

index 49fe3a01bd7281f95f664ab2319c5854db1c90ed..905f14d9925c9953cbfa0b5ac8405fe970243078 100644 (file)
@@ -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 passing arbitrary values and retrieving 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.6
+      The ``-X showalloccount`` option.
+
 
 Options you shouldn't use
 ~~~~~~~~~~~~~~~~~~~~~~~~~
index 21e887f07bb33543e0ee222e05e66f630ece6d7c..1550eef93a1a6fab57a7fe0bfab616922d1c634e 100644 (file)
@@ -646,6 +646,16 @@ Porting to Python 3.6
 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
 -------------------------
 
index 014ac547c14f110f7075891eebddbb5ce51277d5..c9a78d085dcca6e4e390a4f14982fd3b2a1099c0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 3
 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.
 
index 6e2d026e957105ca1243d1ba4e967d5554586615..ddc0fee41ab1b2bd45a4b31abe697fcaa99336c3 100644 (file)
@@ -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
index c83c8ec06f969a8c347a0a7e99301ca4b0eaa9af..559794f5b4c4033ec64848573a8dfbaceec16678 100644 (file)
@@ -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, "
index a7774e2fd1a27a84271aedfcf7163f3c506631bf..1b412580dce111080bf5ad8541d05d743c254280 100644 (file)
@@ -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
index 72a00e671f1799620d598d15da0c423f853d2b87..2d2dcba01631fb0603ef288c4518d1880171e3cb 100644 (file)
@@ -626,7 +626,7 @@ Py_FinalizeEx(void)
 
     /* Debugging stuff */
 #ifdef COUNT_ALLOCS
-    dump_counts(stdout);
+    dump_counts(stderr);
 #endif
     /* dump hash stats */
     _PyHash_Fini();