Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to get GC statistics #60555

Closed
pitrou opened this issue Oct 28, 2012 · 11 comments
Closed

Add a function to get GC statistics #60555

pitrou opened this issue Oct 28, 2012 · 11 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Oct 28, 2012

BPO 16351
Nosy @gpshead, @jcea, @pitrou, @tiran, @benjaminp, @serhiy-storchaka
Files
  • gc_get_stats.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-10-30.21:47:16.794>
    created_at = <Date 2012-10-28.17:30:20.783>
    labels = ['type-feature', 'library']
    title = 'Add a function to get GC statistics'
    updated_at = <Date 2013-12-26.20:12:54.178>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2013-12-26.20:12:54.178>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-10-30.21:47:16.794>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2012-10-28.17:30:20.783>
    creator = 'pitrou'
    dependencies = []
    files = ['27768']
    hgrepos = []
    issue_num = 16351
    keywords = ['patch']
    message_count = 11.0
    messages = ['174060', '174062', '174063', '174067', '174068', '174069', '174070', '174230', '174231', '174236', '206958']
    nosy_count = 7.0
    nosy_names = ['gregory.p.smith', 'jcea', 'pitrou', 'christian.heimes', 'benjamin.peterson', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16351'
    versions = ['Python 3.4']

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 28, 2012

    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}]

    @pitrou pitrou added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 28, 2012
    @tiran
    Copy link
    Member

    tiran commented Oct 28, 2012

    What are the possible performance implications of the statistics?

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 28, 2012

    You mean negative implications? None :-)

    @serhiy-storchaka
    Copy link
    Member

    Why dictionaries and not struct sequences?

    @serhiy-storchaka
    Copy link
    Member

    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])?

    @serhiy-storchaka
    Copy link
    Member

    I.e. gc.get_info([generation]). Returns the info for specified generation or total if the parameter omitted.

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 28, 2012

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 30, 2012

    New changeset 43d87cdf9457 by Antoine Pitrou in branch 'default':
    Issue bpo-16351: New function gc.get_stats() returns per-generation collection statistics.
    http://hg.python.org/cpython/rev/43d87cdf9457

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 30, 2012

    Now committed.

    @pitrou pitrou closed this as completed Oct 30, 2012
    @serhiy-storchaka
    Copy link
    Member

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 26, 2013

    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants