profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Lib/profiling/sampling/stack_collector.py and compare CollapsedStackCollector.export with the other exporters that specify UTF-8 output. Check linked PRs gh-156811 and gh-156814 first; done means collapsed export succeeds for non-ASCII and surrogate-escaped frame names without UnicodeEncodeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100