Expose tracemalloc hook into `_Py_NewReference` for other tracers
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
When new objects are created, the allocation code ends calling into _Py_NewReference (with some exceptions). tracemalloc has a hook into this function to correlate allocations and traces (that do not know anything about objects or references) with newly created objects. This happens here:
This allows tracemalloc to be able to return the traceback where objects where allocated, which is great. Unfortunately other debuggers and profilers do not have this capability as there is no way to leverage trace malloc functionality or to hook into object creation.
I propose to expose an API (unclear what layer of the C-API this should be in) where callbacks can be registered to be called in _Py_NewReference and switch tracemalloc to use this API.
Linked PRs
- gh-115945
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Objects/object.c 中 _Py_NewReference 调用附近开始,检查 tracemalloc 目前如何在此处进行 hook。在确定适当的 API 层之前,阅读链接的 PR gh-115945 以及周边的 C-API 讨论。完成的标准是其他 tracer 可以注册 callback,并且 tracemalloc 使用该 API 时不会丢失 allocation trace 关联关系。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend, devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100