python / python/cpython

profiling: flamegraph export fails with RecursionError on a deeply recursive program

未关闭
#156,545 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-profiling type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

The sampling profiler's flamegraph export (profiling.sampling.stack_collector.FlamegraphCollector.export) builds the flamegraph tree with a recursive walk (convert_children) and then serializes it with json.dumps — both recurse to the depth of the deepest sampled stack. The remote unwinder captures up to MAX_FRAMES (1536) frames, but export runs at the default recursion limit (1000), so profiling a program that recurses deeper than ~1000 makes export() raise RecursionError and write no flamegraph. Both --flamegraph and --diff-flamegraph are affected (the diff collector inherits export).

Reachable when profiling a program that raised its own recursion limit and recurses deeply (recursive-descent parsers, tree/graph walkers, deep serializers).

CPython versions tested on:

CPython main

Operating systems tested on:

Linux, macOS

Linked PRs
  • gh-156546

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 profiling/sampling/stack_collector.py 中的 FlamegraphCollector.export 及其 convert_children 遍历开始。使用递归深度很深且递归限制超过所捕获堆栈深度的程序进行复现,同时使用 --flamegraph 和 --diff-flamegraph。完成的标准是两个导出路径都能生成 flamegraph,且不会出现 RecursionError;查看已链接的 PR gh-156546,了解已经在进行的工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
observability, performance
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。