python / python/cpython

Tachyon sample dump/replay crashes

Open
#144,336 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-profiling type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug description:

I'm running python -m profiling.sampling replay prof.bin --heatmap after having captured some profile and it crashes.

When I dropped a breakpoint in I saw the dump somehow has ended up with one instance where stat.filename == '\x00'

Error: Failed to export heatmap: embedded null byte
Traceback (most recent call last):
  File "<frozen runpy>", line 196, in _run_module_as_main
  File "<frozen runpy>", line 87, in _run_code
  File "/.../lib/python3.15/profiling/sampling/__main__.py", line 65, in <module>
    main()
    ~~~~^^
  File "/.../lib/python3.15/profiling/sampling/cli.py", line 788, in main
    _main()
    ~~~~~^^
  File "/.../lib/python3.15/profiling/sampling/cli.py", line 922, in _main
    handler(args)
    ~~~~~~~^^^^^^
  File "/.../lib/python3.15/profiling/sampling/cli.py", line 1206, in _handle_replay
    collector.export(filename)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/.../lib/python3.15/profiling/sampling/heatmap_collector.py", line 725, in export
    self._generate_file_reports(output_dir, file_stats)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.15/profiling/sampling/heatmap_collector.py", line 766, in _generate_file_reports
    self._generate_file_html(
    ~~~~~~~~~~~~~~~~~~~~~~~~^
        file_path,
        ^^^^^^^^^^
    ...<3 lines>...
        stat
        ^^^^
    )
    ^
  File "/.../lib/python3.15/profiling/sampling/heatmap_collector.py", line 905, in _generate_file_html
    source_lines = Path(filename).read_text(encoding='utf-8', errors='replace').splitlines()
                   ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.15/pathlib/__init__.py", line 985, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
         ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../lib/python3.15/pathlib/__init__.py", line 969, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: embedded null byte

Don't yet have a minimal repro, but maybe the issue is apparent to you

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing python -m profiling.sampling replay prof.bin --heatmap, then read profiling/sampling/cli.py around _handle_replay and profiling/sampling/heatmap_collector.py around export and _generate_file_html. Trace how a dump can produce a stat.filename of \x00; done means replaying the affected profile no longer crashes while generating the heatmap.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.