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
分支
36k
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 摘要。