Title: Add a module for monitoring GC statistics · Issue #146527 · python/cpython · GitHub
Open Graph Title: Add a module for monitoring GC statistics · Issue #146527 · python/cpython
X Title: Add a module for monitoring GC statistics · Issue #146527 · python/cpython
Description: Feature or enhancement Proposal: I propose adding a new internal module to read the gathered statistics from GC. It is supposed to work out-of-process, so we can read and show statistics in non-intrusive way and without any pauses of the...
Open Graph Description: Feature or enhancement Proposal: I propose adding a new internal module to read the gathered statistics from GC. It is supposed to work out-of-process, so we can read and show statistics in non-int...
X Description: Feature or enhancement Proposal: I propose adding a new internal module to read the gathered statistics from GC. It is supposed to work out-of-process, so we can read and show statistics in non-int...
Opengraph URL: https://github.com/python/cpython/issues/146527
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a module for monitoring GC statistics","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nI propose adding a new internal module to read the gathered statistics from GC.\nIt is supposed to work out-of-process, so we can read and show statistics in non-intrusive way and without any pauses of the monitored process.\n\nTo achieve this goal, we need to follow these steps:\n1. Extend `_PyDebugOffset` with a pointer and size to the GC stats from `_gc_runtime_state`.\n2. Add more data to the GC stats(see below).\n3. Add a small module that connects to the process you're monitoring and displays statistics.\n\nI have a working prototype.\n\nI have added the following extra data to GC stats:\n- ts_start - the timestamp of the GC collect start\n- ts_stop - the timestamp of the GC collect stop\n- heap_size - the number of live objects.\n- work_to_do - an internal value from incremental GC. It controls the number of objects that are processed by one increment.\n- object_visits - the number of objects that were visited during GC work.\n- objects_transitively_reachable - the number of objects that were reachable from the global and local roots when incremental GC is called.\n- objects_not_transitively_reachable - the number of objects that were reachable while increment was constructed.\n\nWith this module we can build tools, that gathers stats in the \"real-time\" and output it to various formats. For example, we can format data to use in [Perfetto UI](https://ui.perfetto.dev/) (image from dpo post):\n\n\u003cimg width=\"2014\" height=\"735\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/2c8265cb-e5b8-48dd-88cb-9dff140db6eb\" /\u003e\n\nI want to create two PRs, one for `_PyDebugOffset` and GC stats changes, and one for new module. \n\nI want to start from GIL-enabled build. \n\ncc @pablogsal @markshannon @nascheme @colesbury \n\nAlso link to the issue https://github.com/python/cpython/issues/131253\n\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\nhttps://discuss.python.org/t/add-a-module-for-monitoring-gc-statistics/106695\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146532\n* gh-148057\n* gh-148071\n* gh-149284\n* gh-150969\n* gh-150970\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/sergey-miryanov","@type":"Person","name":"sergey-miryanov"},"datePublished":"2026-03-27T16:25:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/146527/cpython/issues/146527"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1dee7af3-6c53-230a-96c9-752c6b6306f8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E28E:C257A:954A99:D38BAE:6A510947 |
| html-safe-nonce | 9c6901afec84af13aedc153e93b45e3d788c52efd9f91b06d7f2277d02d5bcfa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjhFOkMyNTdBOjk1NEE5OTpEMzhCQUU6NkE1MTA5NDciLCJ2aXNpdG9yX2lkIjoiMTM2NTM1ODkwODIwMjM1NTAxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bb67d6c5729d2c24e2ee311bf58fc474b886455bdafad2e4df24b20f41b4f647 |
| hovercard-subject-tag | issue:4154168719 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/146527/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ef78f633bf57a8e5c585fb21e2e6d218adc6e4c7bdd85fb012a6102f4f22ef3/python/cpython/issues/146527 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ef78f633bf57a8e5c585fb21e2e6d218adc6e4c7bdd85fb012a6102f4f22ef3/python/cpython/issues/146527 |
| og:image:alt | Feature or enhancement Proposal: I propose adding a new internal module to read the gathered statistics from GC. It is supposed to work out-of-process, so we can read and show statistics in non-int... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sergey-miryanov |
| hostname | github.com |
| expected-hostname | github.com |
| None | b076e100febaa00374cd89239f915d00dd3187f7c68b12bc2b7688181305344d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d129404fc45ea64edb1b98567c53e55b395536f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width