classification
Title: Add a function to get GC statistics
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, christian.heimes, gregory.p.smith, jcea, pitrou, python-dev, serhiy.storchaka
Priority: low Keywords: patch

Created on 2012-10-28 17:30 by pitrou, last changed 2013-12-26 20:12 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
gc_get_stats.patch pitrou, 2012-10-28 17:30 review
Messages (11)
msg174060 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-28 17:30
This patch adds a function named gc.get_stats() which returns a list of dictionaries containing per-generation statistics:

>>> import pprint, gc
>>> pprint.pprint(gc.get_stats())
[{'collected': 0, 'collections': 12, 'uncollectable': 0},
 {'collected': 0, 'collections': 1, 'uncollectable': 0},
 {'collected': 0, 'collections': 0, 'uncollectable': 0}]
msg174062 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-10-28 17:42
What are the possible performance implications of the statistics?
msg174063 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-28 17:44
You mean negative implications? None :-)
msg174067 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-28 18:18
Why dictionaries and not struct sequences?
msg174068 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-28 18:30
Oh, I understand. GC callbacks receive a dict.

For avoid confusion with gc.DEBUG_STATS and to conform with callbacks argument name, may be better to name this function as gc.get_infos([generation])?
msg174069 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-28 18:32
I.e. gc.get_info([generation]).  Returns the info for specified generation or total if the parameter omitted.
msg174070 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-28 18:39
> Why dictionaries and not struct sequences?

Because it's much simpler like that.

> For avoid confusion with gc.DEBUG_STATS and to conform with callbacks
> argument name, may be better to name this function as
> gc.get_infos([generation])?

Well, this is really about statistics, not general information.
Furthermore, it is not related to the callbacks functionality.
As for the generation parameter, I don't think it's useful: the result
list is only 3 elements long.
msg174230 - (view) Author: Roundup Robot (python-dev) Date: 2012-10-30 21:46
New changeset 43d87cdf9457 by Antoine Pitrou in branch 'default':
Issue #16351: New function gc.get_stats() returns per-generation collection statistics.
http://hg.python.org/cpython/rev/43d87cdf9457
msg174231 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-30 21:47
Now committed.
msg174236 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-30 22:56
> Because it's much simpler like that.

Well, I wrote a patch with structure sequences, it is really much more expansive.

I have some comments.

1. You can allocate list of NUM_GENERATIONS elements and then use PyList_SET_ITEM(result, i, stat). This is 4 lines shorter.

2. And may be return the tuple? get_count() and get_threshold() return tuples.

3. You forgot to add get_stats() to the module docstring.
msg206958 - (view) Author: Roundup Robot (python-dev) Date: 2013-12-26 20:12
New changeset 17bd04fbf3d3 by R David Murray in branch 'default':
whatsnew for gc.get_stats, plus doc tweaks.
http://hg.python.org/cpython/rev/17bd04fbf3d3
History
Date User Action Args
2013-12-26 20:12:54python-devsetmessages: + msg206958
2012-10-30 22:56:01serhiy.storchakasetmessages: + msg174236
2012-10-30 21:47:16pitrousetstatus: open -> closed
resolution: fixed
messages: + msg174231

stage: patch review -> resolved
2012-10-30 21:46:56python-devsetnosy: + python-dev
messages: + msg174230
2012-10-29 01:52:34jceasetnosy: + jcea
2012-10-28 18:39:28pitrousetmessages: + msg174070
2012-10-28 18:32:55serhiy.storchakasetmessages: + msg174069
2012-10-28 18:30:53serhiy.storchakasetmessages: + msg174068
2012-10-28 18:18:06serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg174067
2012-10-28 17:44:44pitrousetmessages: + msg174063
2012-10-28 17:42:43christian.heimessetnosy: + christian.heimes
messages: + msg174062
2012-10-28 17:30:20pitroucreate