Issue 16351: Add a function to get GC statistics (original) (raw)

Created on 2012-10-28 17:30 by pitrou, last changed 2022-04-11 14:57 by admin. 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) (Python triager) 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) (Python triager) 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
2022-04-11 14:57:37 admin set github: 60555
2013-12-26 20:12:54 python-dev set messages: +
2012-10-30 22:56:01 serhiy.storchaka set messages: +
2012-10-30 21:47:16 pitrou set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2012-10-30 21:46:56 python-dev set nosy: + python-devmessages: +
2012-10-29 01:52:34 jcea set nosy: + jcea
2012-10-28 18:39:28 pitrou set messages: +
2012-10-28 18:32:55 serhiy.storchaka set messages: +
2012-10-28 18:30:53 serhiy.storchaka set messages: +
2012-10-28 18🔞06 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2012-10-28 17:44:44 pitrou set messages: +
2012-10-28 17:42:43 christian.heimes set nosy: + christian.heimesmessages: +
2012-10-28 17:30:20 pitrou create