fix(processes): 对齐活动监视器内存口径与显示单位
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum ProcessMemoryServiceClient {
|
||||
static func read(_ identities: [ProcessIdentity]) async -> [ProcessIdentity: UInt64] {
|
||||
var values: [ProcessIdentity: UInt64] = [:]
|
||||
let deadline = ProcessInfo.processInfo.systemUptime + 3
|
||||
for start in stride(from: 0, to: identities.count, by: ProcessMemoryRequest.limit) {
|
||||
let remaining = deadline - ProcessInfo.processInfo.systemUptime
|
||||
guard !Task.isCancelled, remaining > 0 else { break }
|
||||
let chunk = Array(identities[start..<min(start + ProcessMemoryRequest.limit, identities.count)])
|
||||
let request = ProcessMemoryRequest(token: UUID(), identities: chunk)
|
||||
guard let data = try? JSONEncoder().encode(request), data.count <= ProcessMemoryRequest.byteLimit else { continue }
|
||||
let reply: ProcessMemoryReply? = await ServiceRequest.perform(timeout: min(1.5, remaining)) { proxy, finish in
|
||||
proxy.readProcessMemory(data) { data in
|
||||
guard let data, data.count <= 262_144,
|
||||
let reply = try? JSONDecoder().decode(ProcessMemoryReply.self, from: data),
|
||||
reply.token == request.token, reply.readings.count == chunk.count,
|
||||
Set(reply.readings.map(\.id)) == Set(chunk) else { finish(nil); return }
|
||||
finish(reply)
|
||||
}
|
||||
}
|
||||
guard let reply else { continue }
|
||||
for reading in reply.readings { values[reading.id] = reading.footprintBytes }
|
||||
}
|
||||
return values
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import Foundation
|
||||
|
||||
/// Fixed read-only operation: no caller-supplied paths or commands.
|
||||
@objc protocol SMARTServiceProtocol {
|
||||
nonisolated func readProcessMemory(_ request: Data, withReply reply: @escaping (Data?) -> Void)
|
||||
nonisolated func readProcessEnergy(_ request: Data, withReply reply: @escaping (Data?) -> Void)
|
||||
nonisolated func readSensors(cpu: Bool, gpu: Bool, fans: Bool,
|
||||
withReply reply: @escaping (NSNumber?, NSNumber?, [NSNumber]?) -> Void)
|
||||
|
||||
Reference in New Issue
Block a user