feat(memory): 重设计内存卡片并统一二进制容量单位
This commit is contained in:
@@ -11,6 +11,12 @@ nonisolated enum MetricFormat {
|
||||
return String(format: "%.1f GB", Double(value) / 1_000_000_000)
|
||||
}
|
||||
|
||||
static func memory(_ value: UInt64?) -> String {
|
||||
guard let value else { return "--" }
|
||||
if value == 0 { return "0 B" }
|
||||
return String(format: "%.1f GiB", Double(value) / 1_073_741_824)
|
||||
}
|
||||
|
||||
static func rate(_ value: Double?) -> String {
|
||||
guard let value, value.isFinite, value >= 0 else { return "--" }
|
||||
let units = ["B/s", "KB/s", "MB/s", "GB/s", "TB/s"]
|
||||
|
||||
@@ -14,6 +14,9 @@ nonisolated struct MemoryMetrics: Sendable {
|
||||
let compressed: UInt64
|
||||
let swapUsed: UInt64?
|
||||
let pressure: Int?
|
||||
var cached: UInt64? = nil
|
||||
var available: UInt64 { total - min(total, used) }
|
||||
var app: UInt64 { used - min(used, wired + compressed) }
|
||||
var usage: Double { total == 0 ? 0 : Double(used) / Double(total) }
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ nonisolated enum MemoryMonitor {
|
||||
return MemoryMetrics(total: total, used: min(total, app + wired + compressed),
|
||||
wired: wired, compressed: compressed,
|
||||
swapUsed: swapOK ? swap.xsu_used : nil,
|
||||
pressure: pressureOK ? Int(pressure) : nil)
|
||||
pressure: pressureOK ? Int(pressure) : nil,
|
||||
cached: UInt64(info.external_page_count) * page + purgeable)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user