python / python/cpython

Tachyon sample dump/replay crashes

未关闭
#144,336 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-profiling type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先复现 python -m profiling.sampling replay prof.bin --heatmap,然后阅读 profiling/sampling/cli.py_handle_replay 附近的代码,以及 profiling/sampling/heatmap_collector.pyexport_generate_file_html 附近的代码。追踪 dump 如何产生值为 \x00stat.filename;完成的标准是 replay 受影响的 profile 时,在生成 heatmap 的过程中不再崩溃。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
performance
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。