Skip to content

feat: smctl power status — 热压制 / CPU 降频 / 功耗可见性#1

Merged
harryisfish merged 1 commit into
mainfrom
feat/power-status
Jun 9, 2026
Merged

feat: smctl power status — 热压制 / CPU 降频 / 功耗可见性#1
harryisfish merged 1 commit into
mainfrom
feat/power-status

Conversation

@harryisfish

Copy link
Copy Markdown
Contributor

做了什么

新增 smctl power status —— 把「被压制没有 / 压了多少 / 吃多少电」拼到一屏。纯只读,不要 root、不要 daemon(与 sensors 同类,daemon 没装也能用)。

$ smctl power status
smctl power  2026-06-08T13:34:17Z

  Thermal pressure   nominal
  CPU throttling     none
  Package power      20.55 W
  Input              20.55 W  (12.54 V, 1.64 A)

支持 --json--watch

数据源(三层)

字段 来源 说明
热压制 nominal/fair/serious/critical ProcessInfo.thermalState 系统自评,最稳的语义层
CPU 降频 % pmset -g therm 实测 IOPMCopyCPUPowerStatus 在 Apple Silicon 返回 kIOReturnNotFound(M4 mini 验证),pmset 是唯一公开、非 root 的限速百分比来源
封装 / 输入功率 SMC PDTR / VD0R×ID0R 复用已有键

关键语义:pmset 报 "No CPU power status has been recorded" = 未降频,不是 unknown。

测试

  • PmsetThermParser 抽成纯函数,针对空闲 / 降频 / 异常间距等 fixture 单测。
  • PowerReader 注入三路数据源,确定性单测,不 fork 子进程。
  • 全套 57 tests 通过;M4 mini 实机验证 human / json / 默认子命令均正常。

落地背景

这是「电源管理」线的第一步(只读)。电源策略写入(低功耗模式等)待实测 M4 mini 可控旋钮后再上;降频数据后续可接入温度/事件告警作为触发源。

Read-only power/thermal picture, no root and no daemon (mirrors `sensors`):
- Thermal pressure from ProcessInfo.thermalState (system's own assessment).
- CPU throttling from `pmset -g therm` — Apple Silicon returns kIOReturnNotFound
  for IOPMCopyCPUPowerStatus (verified on M4 mini), so pmset is the only public
  non-root source for the actual speed-limit %. "No status recorded" means not
  throttled, not unknown.
- Package power (PDTR) and input power (VD0R x ID0R) from SMC.

PmsetThermParser is a pure, fixture-tested function; PowerReader injects all
three sources for deterministic unit tests.
@harryisfish harryisfish merged commit afadf54 into main Jun 9, 2026
1 check passed
@leaperone-bot leaperone-bot deleted the feat/power-status branch June 9, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants