feat(memory): 重设计内存卡片并统一二进制容量单位

This commit is contained in:
2026-11-03 16:51:14 +08:00
parent cc38066de2
commit 90ed18e6ac
11 changed files with 186 additions and 17 deletions
+6 -16
View File
@@ -231,25 +231,15 @@ struct MenuPanelView: View {
}.font(.system(size: 10)).help(Text("gpu.pipelineHelp"))
}
private var memoryCard: some View {
ResourceCard(title: "metric.memory", symbol: "memorychip", color: Color("MetricMemory"), value: snapshot.memory.map { String(format: "%.1f / %.1f GB", Double($0.used) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--") {
ResourceCard(title: "metric.memory", symbol: "memorychip", color: Color("MetricMemory"),
value: snapshot.memory.map { String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824) } ?? "--") {
PanelTrendChart(dates: samples.map(\.date),
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
color: Color("MetricMemory"), fixedScale: Double(snapshot.memory?.total ?? 1),
scaleLabel: MetricFormat.bytes(snapshot.memory?.total), expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
if let m = snapshot.memory {
GeometryReader { geometry in
HStack(spacing: 0) {
ForEach(Array([m.used - min(m.used, m.wired + m.compressed), m.wired, m.compressed, m.total - min(m.total, m.used)].enumerated()), id: \.offset) { i, bytes in
Rectangle().fill(Color("MetricMemory").opacity([1, 0.75, 0.5, 0.15][i]))
.frame(width: Double(bytes) / Double(max(1, m.total)) * geometry.size.width)
}
}
}.frame(height: 6).clipped().accessibilityHidden(true)
line("memory.app", MetricFormat.bytes(m.used - min(m.used, m.wired + m.compressed)))
HStack { line("memory.wired", MetricFormat.bytes(m.wired)); line("memory.compressed", MetricFormat.bytes(m.compressed)) }
HStack { line("memory.available", MetricFormat.bytes(m.total - min(m.total, m.used))); line("memory.swap", MetricFormat.bytes(m.swapUsed)) }
HStack { Text("memory.pressure").foregroundStyle(.secondary); Spacer(); pressure(m.pressure); AnimatedMetricText(value: MetricFormat.percent(m.usage)).foregroundStyle(Color("MetricMemory")) }
scaleLabel: MetricFormat.memory(snapshot.memory?.total), firstValueFormat: .memory,
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
if let memory = snapshot.memory {
MemoryDetailsView(memory: memory)
} else { Text("metric.waiting") }
}
}