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
+17 -1
View File
@@ -4,6 +4,11 @@ import IOKit
nonisolated struct GPUMetrics: Sendable {
let usage: Double?
let coreCount: Int?
var renderer: Double? = nil
var tiler: Double? = nil
// Driver accounting, not dedicated VRAM or a capacity denominator.
var inUseMemory: UInt64? = nil
var allocatedMemory: UInt64? = nil
// Independent per-core counters have not been obtained. Never split total usage.
}
@@ -20,12 +25,23 @@ nonisolated enum GPUMonitor {
let stats = IORegistryEntryCreateCFProperty(service, "PerformanceStatistics" as CFString, kCFAllocatorDefault, 0)?.takeRetainedValue() as? [String: Any]
let raw = (stats?["Device Utilization %"] as? NSNumber)?.doubleValue
let cores = (IORegistryEntryCreateCFProperty(service, "gpu-core-count" as CFString, kCFAllocatorDefault, 0)?.takeRetainedValue() as? NSNumber)?.intValue
devices.append(GPUMetrics(usage: normalized(raw), coreCount: cores.flatMap { $0 > 0 ? $0 : nil }))
devices.append(GPUMetrics(usage: normalized(raw), coreCount: cores.flatMap { $0 > 0 ? $0 : nil },
renderer: normalized((stats?["Renderer Utilization %"] as? NSNumber)?.doubleValue),
tiler: normalized((stats?["Tiler Utilization %"] as? NSNumber)?.doubleValue),
inUseMemory: memoryBytes(stats?["In use system memory"]),
allocatedMemory: memoryBytes(stats?["Alloc system memory"])))
}
// Do not average incompatible utilization counters on multi-GPU machines.
return devices.count == 1 ? devices[0] : nil
}
static func memoryBytes(_ raw: Any?) -> UInt64? {
guard let number = raw as? NSNumber else { return nil }
let value = number.doubleValue
guard value.isFinite, value >= 0, value < Double(UInt64.max) else { return nil }
return UInt64(value)
}
static func normalized(_ value: Double?) -> Double? {
value.flatMap { $0.isFinite && (0...100).contains($0) ? $0 / 100 : nil }
}