Skip to content

gh-156810: Write the profiler's collapsed-stack export as UTF-8 - #156811

Merged
pablogsal merged 1 commit into
python:mainfrom
tonghuaroot:gh-156810-collapsed-encoding
Sep 2, 2026
Merged

gh-156810: Write the profiler's collapsed-stack export as UTF-8#156811
pablogsal merged 1 commit into
python:mainfrom
tonghuaroot:gh-156810-collapsed-encoding

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

CollapsedStackCollector.export opened its output file with open(filename, "w") — the only exporter in stack_collector.py without an explicit encoding= (the flamegraph, JSONL and heatmap exporters all pass encoding="utf-8"). Since the collapsed format writes frame names verbatim, it crashed with UnicodeEncodeError on non-ASCII frame names under a non-UTF-8 locale, and on surrogate-escaped filenames on any locale.

Open the file as UTF-8 with errors="surrogatepass": utf-8 matches the sibling exporters, and surrogatepass is needed because — unlike the json-based exporters, which escape via ensure_ascii — collapsed writes names verbatim and frame filenames can be surrogate-escaped (undecodable paths).

The added test fails without the fix; test_profiling passes.

@pablogsal pablogsal added awaiting review needs backport to 3.15 pre-release feature fixes, bugs and security fixes and removed awaiting merge labels Sep 2, 2026
@pablogsal

Copy link
Copy Markdown
Member

Thanks a lot for the fix!

@pablogsal
pablogsal enabled auto-merge (squash) September 2, 2026 09:31
@pablogsal
pablogsal merged commit c3706f4 into python:main Sep 2, 2026
63 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156814 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants