Skip to content

[Bug] ps 输出解析对带空格 command/path 不稳,可能漏掉真实进程 #29

@ShadyUnderLight

Description

@ShadyUnderLight

问题描述

当前进程采样使用 ps -axo pid=,comm=,%cpu=,rss=,随后在 parsePSOutput() 中按空格 split 解析。这个做法对带空格的 command/path 不稳:一旦字段错位,该行就会被丢弃,最终导致 top apps 列表缺少真实高负载进程。

macOS 上这不是纯理论问题,尤其是 app bundle 内可执行文件路径、辅助进程、某些自定义启动方式下,command/path 含空格并不少见。

影响

  • Top CPU / Top Memory 结果可能不完整
  • 用户看到的是“监控结果缺失”,但 UI 不会提示是解析失败
  • 问题具有隐蔽性,不容易靠肉眼发现

建议方案

优先方案

改用更稳的输出/解析协议,避免依赖普通空格 split:

  • 使用 tab 或明确分隔符
  • 将最可能含空格的字段放在最后
  • 或改为两阶段采样:先取 pid / cpu / rss,再单独补 command/path

配套回归测试

补一条 parser regression test,显式覆盖:

  • command/path 含空格
  • 多余空白
  • 非法行不应污染合法结果

影响模块

performance
parsing
reliability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions