fix(processes): 对齐活动监视器内存口径与显示单位

This commit is contained in:
2026-11-04 14:28:56 +08:00
parent 44f0415ab7
commit bbec1325a1
23 changed files with 195 additions and 26 deletions
@@ -147,7 +147,7 @@ import SwiftUI
case "name": text = process.name
case "path": text = process.path ?? "--"
case "cpu": text = process.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--"
case "memory": text = process.residentBytes.map { String(format: "%.1f MB", Double($0) / 1_000_000) } ?? "--"
case "memory": text = process.footprintBytes.map { String(format: "%.1f MB", Double($0) / 1_048_576) } ?? "--"
default: text = process.threads.map(String.init) ?? "--"
}
if cell.textField?.stringValue != text { cell.textField?.stringValue = text }
@@ -45,7 +45,7 @@ nonisolated struct ProcessSort: SortComparator, Equatable {
case .name: return directed(lhs.name.localizedStandardCompare(rhs.name))
case .path: return directed((lhs.path ?? "").localizedStandardCompare(rhs.path ?? ""))
case .cpu: return metric(lhs.cpu, rhs.cpu)
case .memory: return metric(lhs.residentBytes.map { Double($0) }, rhs.residentBytes.map { Double($0) })
case .memory: return metric(lhs.footprintBytes.map { Double($0) }, rhs.footprintBytes.map { Double($0) })
case .threads: return metric(lhs.threads.map { Double($0) }, rhs.threads.map { Double($0) })
}
}
@@ -54,7 +54,7 @@ private struct TextReportHost: NSViewRepresentable {
c.rows = ProcessTableProjection.rows(processes?.rows ?? [], query: "", sorting: [ProcessSort(key: .cpu)], order: [])
}
let heading = Self.resourceText(snapshot) + "\nHistory points retained: \(historyPoints)\nPublic IP: \(publicAddress ?? "--")\n\n" + Self.energyText(energy)
+ "\nProcesses: \(processes?.readable ?? 0)/\(processes?.enumerated ?? 0), failed=\(processes?.failed ?? false)\nPID\tCPU %\tRSS bytes\tThreads\tRestricted\tName\tPath"
+ "\nProcesses: \(processes?.readable ?? 0)/\(processes?.enumerated ?? 0), failed=\(processes?.failed ?? false)\nPID\tCPU %\tFootprint bytes\tThreads\tRestricted\tName\tPath"
c.lines = heading.components(separatedBy: "\n")
let origin = scroll.contentView.bounds.origin
let oldCount = table.numberOfRows
@@ -150,7 +150,7 @@ private struct TextReportHost: NSViewRepresentable {
return "CPU energy: \(energy.state), measured/readable/enumerated=\(energy.measured)/\(energy.readable)/\(energy.candidates)\n" + energy.rows.map { "\($0.id.pid) \($0.process.name): \($0.formattedPower), interval \(number($0.seconds)) s" }.joined(separator: "\n") + "\n"
}
private static func processLine(_ process: ProcessMetrics) -> String {
"\(process.id.pid)\t\(number(process.cpu.map { $0 * 100 }))\t\(bytes(process.residentBytes))\t\(process.threads.map(String.init) ?? "--")\t\(process.restricted)\t\(process.name)\t\(process.path ?? "--")"
"\(process.id.pid)\t\(number(process.cpu.map { $0 * 100 }))\t\(bytes(process.footprintBytes))\t\(process.threads.map(String.init) ?? "--")\t\(process.restricted)\t\(process.name)\t\(process.path ?? "--")"
}
}