feat(menubar): 拆分紧凑双页面板并按页采样
This commit is contained in:
@@ -35,6 +35,18 @@ nonisolated struct ProcessEnergySnapshot: Sendable {
|
||||
let candidates: Int
|
||||
let readable: Int
|
||||
let measured: Int
|
||||
let rows: [ProcessEnergyUsage] // Only the top three; no CPU prefilter.
|
||||
let rows: [ProcessEnergyUsage] // All valid measurements; no CPU prefilter.
|
||||
let state: State
|
||||
}
|
||||
|
||||
nonisolated extension ProcessSnapshot {
|
||||
func withEnergy(_ energy: ProcessEnergySnapshot?) -> ProcessSnapshot {
|
||||
let values = Dictionary((energy?.rows ?? []).map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
|
||||
return ProcessSnapshot(date: date, enumerated: enumerated, readable: readable, rows: rows.map { process in
|
||||
var row = process
|
||||
row.cpuPower = values[process.id]?.watts
|
||||
row.powerWindow = values[process.id]?.seconds
|
||||
return row
|
||||
}, failed: failed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ nonisolated struct ProcessMetrics: Identifiable, Sendable {
|
||||
let footprintBytes: UInt64? // Physical footprint; never RSS.
|
||||
let threads: Int?
|
||||
let restricted: Bool
|
||||
var cpuPower: Double? = nil // Average attributed CPU power, watts; not Energy Impact.
|
||||
var powerWindow: TimeInterval? = nil
|
||||
var formattedPower: String {
|
||||
guard let cpuPower, cpuPower.isFinite, cpuPower >= 0 else { return "--" }
|
||||
return cpuPower >= 1 ? String(format: "%.2f W", cpuPower) : String(format: "%.1f mW", cpuPower * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated struct ProcessSnapshot: Sendable {
|
||||
|
||||
Reference in New Issue
Block a user