feat(menubar): 完善首排监控卡片与温度风扇采样

补充 GPU 渲染分块、内存与利用率统计,增加只读 SMC 温度及风扇信息和旋转动效。完善电池功率与耗电进程列表,统一首排布局并固定异步加载区域高度。同步验证用例、架构说明和 GPU 能力调研工具。
This commit is contained in:
2026-11-03 16:42:09 +08:00
parent 45a6e16bb8
commit cc38066de2
43 changed files with 2658 additions and 536 deletions
+92
View File
@@ -0,0 +1,92 @@
"""Read-only GPU discovery; run manually with python3, outside the app sandbox.
Enumerates names, not private counter semantics. A matching name is a research
candidate, never proof of per-core utilization. Does not create subscriptions,
submit GPU work, request root, or collect process/application information.
"""
import ctypes as C
import json
import plistlib
import subprocess
from collections import Counter
def command(*args):
return subprocess.check_output(args, timeout=60)
def registry_devices():
roots = plistlib.loads(command("ioreg", "-a", "-r", "-c", "IOAccelerator", "-d", "0"))
if isinstance(roots, dict):
roots = [roots]
keys = ("model", "gpu-core-count", "GPUConfigurationVariable", "PerformanceStatistics",
"GPURawCounterBundleName", "GPURawCounterPluginClassName")
return [{k: n[k] for k in keys if k in n} for n in roots]
def ioreport_channels():
cf = C.CDLL("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")
io = C.CDLL("/usr/lib/libIOReport.dylib")
io.IOReportCopyAllChannels.argtypes = [C.c_uint64, C.c_uint64]
io.IOReportCopyAllChannels.restype = C.c_void_p
cf.CFPropertyListCreateData.argtypes = [C.c_void_p, C.c_void_p, C.c_long, C.c_ulong, C.c_void_p]
cf.CFPropertyListCreateData.restype = C.c_void_p
cf.CFDataGetLength.argtypes = [C.c_void_p]
cf.CFDataGetLength.restype = C.c_long
cf.CFDataGetBytePtr.argtypes = [C.c_void_p]
cf.CFDataGetBytePtr.restype = C.c_void_p
cf.CFRelease.argtypes = [C.c_void_p]
channels = io.IOReportCopyAllChannels(0, 0)
if not channels:
raise RuntimeError("IOReportCopyAllChannels returned nil")
data = None
try:
data = cf.CFPropertyListCreateData(None, channels, 100, 0, None)
if not data:
raise RuntimeError("IOReport channel serialization failed")
report = plistlib.loads(C.string_at(cf.CFDataGetBytePtr(data), cf.CFDataGetLength(data)))
all_channels = report.get("IOReportChannels", [])
selected = []
for channel in all_channels:
driver = channel.get("DriverName", "").split(" <id ")[0]
group = channel.get("IOReportGroupName", "")
subgroup = channel.get("IOReportSubGroupName", "")
legend = channel.get("LegendChannel", [])
name = str(legend[2]) if len(legend) > 2 else ""
if any(term in " ".join((driver, group, subgroup, name)).lower()
for term in ("gpu", "agx", "gfx")):
selected.append(dict(driver=driver, group=group, subgroup=subgroup, name=name))
counts = Counter((x["driver"], x["group"], x["subgroup"]) for x in selected)
return dict(totalChannels=len(all_channels), gpuRelatedChannels=len(selected),
groups=[dict(driver=d, group=g, subgroup=s, count=n)
for (d, g, s), n in sorted(counts.items())], channels=selected)
finally:
if data:
cf.CFRelease(data)
cf.CFRelease(channels)
def metal_counters():
source = '''import Foundation
import Metal
let devices: [[String: Any]] = MTLCopyAllDevices().map { device in
["name": device.name, "counterSets": (device.counterSets ?? []).map { set in
["name": set.name, "counters": set.counters.map { $0.name }] as [String: Any]
}]
}
let data = try JSONSerialization.data(withJSONObject: devices, options: [.sortedKeys])
print(String(decoding: data, as: UTF8.self))
'''
return json.loads(command("xcrun", "swift", "-e", source))
if __name__ == "__main__":
result = {"os": command("sw_vers").decode().strip(), "scope": "unsandboxed discovery only"}
for key, probe in (("registry", registry_devices), ("ioreport", ioreport_channels),
("metal", metal_counters)):
try:
result[key] = probe()
except (AttributeError, OSError, RuntimeError, ValueError, subprocess.SubprocessError) as error:
result[key] = {"error": str(error)}
print(json.dumps(result, ensure_ascii=False, indent=2))