perf(efficiency): 接入真实CPU能量并隔离展示与采样需求

This commit is contained in:
2026-11-04 01:11:24 +08:00
parent a96d188abe
commit 1c26fc18f3
37 changed files with 1249 additions and 179 deletions
+40
View File
@@ -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
}
+1 -1
View File
@@ -1,6 +1,6 @@
import Foundation
nonisolated struct ProcessIdentity: Hashable, Sendable {
nonisolated struct ProcessIdentity: Hashable, Codable, Sendable {
let pid: Int32
let seconds: UInt64
let microseconds: UInt64