perf(efficiency): 接入真实CPU能量并隔离展示与采样需求
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum EnergyReadStatus: String, Codable, Sendable {
|
||||
case available, denied, gone, failed, identityChanged, deadline, unsupported, unverified
|
||||
}
|
||||
nonisolated enum EnergyCapability: String, Codable, Sendable { case verifiedCPU, unverified, unsupported, unavailable }
|
||||
nonisolated struct ProcessEnergyRequest: Codable, Sendable {
|
||||
let token: UUID
|
||||
let identities: [ProcessIdentity]
|
||||
static let limit = 256
|
||||
static let byteLimit = 65_536
|
||||
}
|
||||
nonisolated struct ProcessEnergyReading: Codable, Sendable {
|
||||
let id: ProcessIdentity
|
||||
let birth: UInt64
|
||||
let uptime: TimeInterval
|
||||
let nanojoules: UInt64?
|
||||
let status: EnergyReadStatus
|
||||
}
|
||||
nonisolated struct ProcessEnergyReply: Codable, Sendable {
|
||||
let token: UUID
|
||||
let capability: EnergyCapability
|
||||
let readings: [ProcessEnergyReading]
|
||||
}
|
||||
nonisolated struct ProcessEnergyUsage: Identifiable, Sendable {
|
||||
let process: ProcessMetrics
|
||||
let watts: Double
|
||||
let seconds: TimeInterval
|
||||
var id: ProcessIdentity { process.id }
|
||||
var formattedPower: String { watts >= 1 ? String(format: "%.2f W", watts) : String(format: "%.1f mW", watts * 1000) }
|
||||
}
|
||||
nonisolated struct ProcessEnergySnapshot: Sendable {
|
||||
enum State: Sendable { case waiting, available, partial, unavailable, unsupported }
|
||||
let date: Date
|
||||
let candidates: Int
|
||||
let readable: Int
|
||||
let measured: Int
|
||||
let rows: [ProcessEnergyUsage] // Only the top three; no CPU prefilter.
|
||||
let state: State
|
||||
}
|
||||
Reference in New Issue
Block a user