classification
Title: Dynamically control debugging output
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: bkabrda, ezio.melotti, haypo, pitrou, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-12-11 21:09 by serhiy.storchaka, last changed 2016-07-04 16:29 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
show_alloc_counts.patch serhiy.storchaka, 2015-05-12 13:49 review
Messages (6)
msg232495 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-11 21:09
When Python is compiled with some defined macros (e.g. COUNT_ALLOCS) it prints additional debugging output at shutdown. This additional output can cause tests failure (see issue19527). It would be good if Python will silent by default and produce debugging output only if special command line option or environment variable is set.

Debugging output switched by Py_REF_DEBUG is now enabled only when "-X showrefcount" is specified (issue17323).
msg232538 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-12-12 12:29
Also this debug output should be printed on stderr, not stdout.
msg232539 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-12-12 12:30
> Debugging output switched by Py_REF_DEBUG is now enabled only when "-X showrefcount" is specified (issue17323).

Yes, I like the idea of doing that for other debug options.
msg232553 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-12 14:56
Here is (conceivably incomplete) list of debugging and tracing output (but not 
error reporting) from C code.

Controlled output.

Import and shutdown details -- controlled by the -v flag.
Parser tracing -- controlled by the -d flag.
If Py_REF_DEBUG is defined -- controlled by the -X showrefcount flag.
If PYMALLOC_DEBUG is defined -- controlled by the PYTHONMALLOCSTATS environment 
variable.
If Py_TRACE_REFS is defined -- controlled by the PYTHONDUMPREFS environment 
variable.
Garbage collecting details -- controlled by gc.set_debug().
If LLTRACE is defined -- controlled by the __ltrace__ global variable.

Uncomtrolled output.

To stderr:

In PyType_ClearCache (Objects/typeobject.c) if MCACHE_STATS is defined.
Lists allocations if SHOW_ALLOC_COUNT is defined.
Tuples allocations if SHOW_TRACK_COUNT is defined.
Interned strings statistics if __INSURE__ is defined.
In Python/ceval.c if WITH_TSC is defined.
In _PyHash_Fini if Py_HASH_STATS is defined.

To stdout:

In Modules/_ctypes/malloc_closure.c if MALLOC_CLOSURE_DEBUG is defined.
Regex matching trace in Modules/_sre.c if VERBOSE is defined.
Statistics in Modules/hashtable.c if Py_DEBUG is defined.
Allocation counts if COUNT_ALLOCS is defined.

There is also dead code in Parser/parsetok.c, Parser/tokenizer.c, 
Python/pyarena.c, Python/compile.c, Python/formatter_unicode.c, 
Modules/_elementtree.c, Modules/_tkinter.c, Objects/unicodeobject.c.
msg242968 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-12 13:49
Proposed patch adds the "-X showalloccount" option, that turn on the output of allocated objects counts if COUNT_ALLOCS, SHOW_ALLOC_COUNT, or SHOW_TRACK_COUNT are defined. The output of COUNT_ALLOCS is now written to stderr.
msg269771 - (view) Author: Roundup Robot (python-dev) Date: 2016-07-03 18:04
New changeset cd911e06bf6c by Serhiy Storchaka in branch 'default':
Issue #23034: The output of a special Python build with defined COUNT_ALLOCS,
https://hg.python.org/cpython/rev/cd911e06bf6c
History
Date User Action Args
2016-07-04 16:29:27serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-07-03 18:04:22python-devsetnosy: + python-dev
messages: + msg269771
2016-06-21 20:01:54serhiy.storchakasetassignee: serhiy.storchaka
versions: + Python 3.6, - Python 3.5
2015-05-12 13:49:57serhiy.storchakasetfiles: + show_alloc_counts.patch
keywords: + patch
messages: + msg242968

stage: patch review
2014-12-13 17:47:36serhiy.storchakalinkissue19527 dependencies
2014-12-12 14:56:25serhiy.storchakasetmessages: + msg232553
2014-12-12 12:30:33hayposetnosy: + haypo
messages: + msg232539
2014-12-12 12:29:32pitrousetnosy: + pitrou
messages: + msg232538
2014-12-11 21:09:33serhiy.storchakacreate