feat(memory): 重设计内存卡片并统一二进制容量单位
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MemoryDetailsView: View {
|
||||
let memory: MemoryMetrics
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
private var colors: [Color] { [Color("MetricMemory"), Color("SeriesUpload"), Color("MetricDisk"), .secondary.opacity(0.25)] }
|
||||
private var values: [UInt64] { [memory.app, memory.wired, memory.compressed, memory.available] }
|
||||
private let labels: [LocalizedStringKey] = ["memory.app", "memory.wired", "memory.compressed", "memory.available"]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 9) {
|
||||
Divider()
|
||||
HStack {
|
||||
Text("memory.distribution").fontWeight(.semibold)
|
||||
Spacer()
|
||||
Text("panel.total").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.percent(memory.usage)).foregroundStyle(Color("MetricMemory"))
|
||||
}
|
||||
GeometryReader { proxy in
|
||||
HStack(spacing: 0) {
|
||||
ForEach(0..<4) { index in
|
||||
Rectangle().fill(colors[index])
|
||||
.frame(width: CGFloat(values[index]) / CGFloat(max(1, memory.total)) * proxy.size.width)
|
||||
}
|
||||
}
|
||||
// Round the combined shape; tiny segments never receive a minimum width.
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
||||
}.frame(height: 8).accessibilityHidden(true)
|
||||
HStack(spacing: 4) {
|
||||
ForEach(0..<4) { index in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(colors[index]).frame(width: 4, height: 4)
|
||||
Text(labels[index]).foregroundStyle(.secondary)
|
||||
}
|
||||
AnimatedMetricText(value: MetricFormat.memory(values[index]))
|
||||
.fontWeight(.medium).monospacedDigit()
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
Divider()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.pressure").foregroundStyle(.secondary)
|
||||
pressure
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.cached").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.cached))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.help(Text("memory.cachedHelp"))
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.swap").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
}.padding(.top, 4)
|
||||
}
|
||||
|
||||
@ViewBuilder private var pressure: some View {
|
||||
switch memory.pressure {
|
||||
case 1: Label("pressure.normal", systemImage: "circle.fill").foregroundStyle(Color("MetricCPU"))
|
||||
case 2: Label("pressure.warning", systemImage: "circle.fill").foregroundStyle(.orange)
|
||||
case 4: Label("pressure.critical", systemImage: "circle.fill").foregroundStyle(.red)
|
||||
default: Text(verbatim: "--").foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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") }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user