Skip to content

Commit ebca12a

Browse files
committed
Revert "[3.15] gh-156810: Write the profiler's collapsed-stack export as UTF-8 (GH-156811) (#156814)"
This reverts commit fce28da.
1 parent c10f45d commit ebca12a

3 files changed

Lines changed: 1 addition & 28 deletions

File tree

‎Lib/profiling/sampling/stack_collector.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def export(self, filename):
6060

6161
lines.sort(key=lambda x: (-x[1], x[0]))
6262

63-
with open(filename, "w",
64-
encoding="utf-8", errors="surrogatepass") as f:
63+
with open(filename, "w") as f:
6564
for stack, count in lines:
6665
f.write(f"{stack} {count}\n")
6766
print(f"Collapsed stack output written to {filename}")

‎Lib/test/test_profiling/test_sampling_profiler/test_collectors.py‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -466,28 +466,6 @@ def test_collapsed_stack_collector_export(self):
466466
self.assertIn(stack1_expected, lines)
467467
self.assertIn(stack2_expected, lines)
468468

469-
def test_collapsed_stack_collector_export_non_ascii_names(self):
470-
# gh-156810: frame names are written verbatim, so the output must be
471-
# opened with an encoding that can represent non-ASCII and
472-
# surrogate-escaped (undecodable-path) names.
473-
collapsed_out = tempfile.NamedTemporaryFile(delete=False)
474-
self.addCleanup(close_and_unlink, collapsed_out)
475-
476-
collector = CollapsedStackCollector(1000)
477-
frame = MockFrameInfo("/tmp/ba\udc80d.py", 5, "计算")
478-
collector.collect([
479-
MockInterpreterInfo(0, [MockThreadInfo(1, [frame])])
480-
])
481-
482-
with captured_stdout(), captured_stderr():
483-
collector.export(collapsed_out.name)
484-
485-
with open(collapsed_out.name, encoding="utf-8",
486-
errors="surrogatepass") as f:
487-
content = f.read()
488-
self.assertIn("计算", content)
489-
self.assertIn("ba\udc80d.py", content)
490-
491469
def test_flamegraph_collector_basic(self):
492470
"""Test basic FlamegraphCollector functionality."""
493471
collector = FlamegraphCollector(1000)

‎Misc/NEWS.d/next/Library/2026-09-02-17-28-16.gh-issue-156810.cLpEnc.rst‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)