FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add `duration` and `visited` to the `gc.callbacks` and `gc.get_stats()` dicts · Issue #140638 · python/cpython · GitHub

/ cpython Public

Add duration and visited to the gc.callbacks and gc.get_stats() dicts #140638

Description

Feature or enhancement

The documentation for gc.callbacks states that its primary use cases are:

Gathering statistics about garbage collection, such as how often various generations are collected, and how long the collection takes.

We can be doing a bit more to serve users of gc.callbacks (and gc.get_stats() too). In particular:

  • duration: Collection time, which is mentioned above, is something we already have a low-overhead mechanism to measure for use with the gc.DEBUG_STATS flag. It's a bit finnicky to get right in a callback, since they're called in two phases (so the start time has to be stashed away somewhere between calls).
  • visited: The number of visited objects is also extremely useful (collected/visited gives you the efficiency of your collection). Getting this information from Python is very expensive (sum(len(gc.get_objects(g)) for g in range(gen + 1))), but it's cheap for us to provide from the GC itself.

With these changes, many users can probably get away with just handling stop events, or ditching callbacks entirely and just periodically checking gc.get_stats() instead for aggregates.

I already ran this idea by @nascheme and @markshannon this week. They were supportive of the idea, so I plan on working on this soon.

(Supersedes #140515.)

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.15pre-release feature fixes, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL