perf(menubar): 减少进程表刷新排序并清理闲置代码

This commit is contained in:
2026-11-16 00:06:14 +08:00
parent 97c1bc3b7f
commit 3ee6b45eb4
7 changed files with 43 additions and 73 deletions
-10
View File
@@ -8,16 +8,6 @@ import Foundation
precondition(ProcessMonitor.cpu(current: 1, previous: 0, elapsed: 0) == nil)
precondition(GPUMonitor.normalized(53) == 0.53)
precondition(GPUMonitor.normalized(101) == nil && GPUMonitor.normalized(.nan) == nil)
let processRows = [
ProcessMetrics(id: ProcessIdentity(pid: 1, seconds: 1, microseconds: 1), name: "unknown", path: nil, cpu: nil, footprintBytes: nil, threads: nil, restricted: true),
ProcessMetrics(id: ProcessIdentity(pid: 2, seconds: 1, microseconds: 2), name: "busy", path: nil, cpu: 2.5, footprintBytes: nil, threads: nil, restricted: false),
ProcessMetrics(id: ProcessIdentity(pid: 3, seconds: 1, microseconds: 3), name: "idle", path: nil, cpu: 0, footprintBytes: nil, threads: nil, restricted: false),
ProcessMetrics(id: ProcessIdentity(pid: 4, seconds: 1, microseconds: 4), name: "invalid", path: nil, cpu: -.infinity, footprintBytes: nil, threads: nil, restricted: false)
]
let processSnapshot = ProcessSnapshot(date: Date(), enumerated: 4, readable: 3, rows: processRows, failed: false)
precondition(processSnapshot.highestCPUProcess?.name == "busy")
precondition(processSnapshot.highestCPUProcesses(limit: 3).map(\.name) == ["busy", "idle"])
precondition(processSnapshot.highestCPUProcesses(limit: 0).isEmpty)
var snapshot = MetricsSnapshot()
snapshot.network = [NetworkInterfaceMetrics(name: "en0", received: 1, sent: 1, download: 12, upload: 8),
NetworkInterfaceMetrics(name: "utun0", received: 1, sent: 1, download: 99, upload: 99)]