Skip to content

[Bug] commandTemperature 每次调用都 fork 新 shell,istats/osx-cpu-temp 不存在时白跑进程 #8

@ShadyUnderLight

Description

@ShadyUnderLight

问题描述

SystemMetricsProvider.bestEffortCPUTemperature 在 Apple Silicon 温度读取失败后 fallback 到 shell 命令时,每次调用都执行:

"/bin/zsh", ["-lc", "if command -v istats >/dev/null 2>&1; then ...; elif command -v osx-cpu-temp >/dev/null 2>&1; then ...; else exit 1; fi"]

即使用了 5 秒 cache,但每次 cache 失效后(切换温度模式 / 超过 5 秒),都会 fork/exec 一个 zsh + 两条 command -v 检测 + 实际命令。工具不存在时 exit 127,用户白等。

预期结果

工具不存在时立即返回 nil,不跑任何 shell 命令。

实际结果

每次温度刷新都跑完整的 shell 链,存在无意义的进程创建开销。

建议方案

  1. 引入 availableCommandCache: String? 在 actor 内部缓存已确认可用的命令路径
  2. 首次检测时并行检测两个工具是否存在,确认后再执行实际命令
  3. 如果两个都不存在,直接返回 nil,后续每次也跳过不再检测

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions