profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
CollapsedStackCollector.export (Lib/profiling/sampling/stack_collector.py) opens its output with open(filename, "w") — no encoding=. It is the only exporter in that module missing it; FlamegraphCollector.export, the JSONL exporter and the heatmap exporter all pass encoding="utf-8". Because the collapsed format writes frame names verbatim (the JSON exporters escape non-ASCII via ensure_ascii), --collapsed export raises UnicodeEncodeError when a sampled frame's function or file name contains non-ASCII characters under a non-UTF-8 locale, or surrogate-escaped characters (from an undecodable path) on any locale:
UnicodeEncodeError: 'ascii' codec can't encode characters ...
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' ... surrogates not allowed
Non-English identifiers are common and non-UTF-8 locales are supported, so profiling such a program with --collapsed produces no output and an uncaught error.
CPython versions tested on:
CPython main
Operating systems tested on:
Linux, macOS
Linked PRs
- gh-156811
- gh-156814
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lib/profiling/sampling/stack_collector.py 开始,将 CollapsedStackCollector.export 与其他指定 UTF-8 输出的 exporter 进行比较。先检查链接的 PR gh-156811 和 gh-156814;完成的标准是:对于非 ASCII 和 surrogate-escaped 的 frame 名称,collapsed export 能够成功,且不会出现 UnicodeEncodeError。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- performance
- Issue 类型
- 缺陷
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100