feat(cpu): 区分核心类型并标注运行时间
This commit is contained in:
@@ -102,6 +102,26 @@ struct MenuPanelView: View {
|
||||
HStack(alignment: .firstTextBaseline) { Text(key).foregroundStyle(.secondary); Spacer(minLength: 6); AnimatedMetricText(value: value) }
|
||||
}
|
||||
|
||||
private func coreColor(_ kind: CPUCoreTopology.Kind?) -> Color {
|
||||
switch kind {
|
||||
case .efficiency: Color("MetricCPU")
|
||||
case .middle: Color("MetricMemory")
|
||||
case .performance: Color("MetricGPU")
|
||||
case nil: .secondary
|
||||
}
|
||||
}
|
||||
|
||||
private func coreLabel(_ kind: CPUCoreTopology.Kind) -> Text {
|
||||
switch kind {
|
||||
case .efficiency: Text("cpu.kind.efficiency", tableName: "CPUDetails")
|
||||
case .middle: Text("cpu.kind.performance", tableName: "CPUDetails")
|
||||
case .performance:
|
||||
CPUCoreTopology.cores.values.contains(.middle)
|
||||
? Text("cpu.kind.super", tableName: "CPUDetails")
|
||||
: Text("cpu.kind.performance", tableName: "CPUDetails")
|
||||
}
|
||||
}
|
||||
|
||||
private var cpuCard: some View {
|
||||
ResourceCard(title: "metric.cpu", symbol: "cpu", color: Color("MetricCPU"), value: MetricFormat.percent(snapshot.cpu?.usage)) {
|
||||
PanelTrendChart(dates: samples.map(\.date), first: samples.map(\.cpu),
|
||||
@@ -110,19 +130,29 @@ struct MenuPanelView: View {
|
||||
firstLabel: "panel.total", secondLabel: "cpu.user", thirdLabel: "cpu.system", expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
if let cpu = snapshot.cpu {
|
||||
HStack { line("cpu.user", MetricFormat.percent(cpu.user)); line("cpu.system", MetricFormat.percent(cpu.system)) }
|
||||
let kinds = [CPUCoreTopology.Kind.efficiency, .middle, .performance].filter { CPUCoreTopology.cores.values.contains($0) }
|
||||
if !kinds.isEmpty {
|
||||
HStack(spacing: 10) {
|
||||
ForEach(kinds, id: \.rawValue) { kind in
|
||||
HStack(spacing: 3) { Circle().fill(coreColor(kind)).frame(width: 6, height: 6); coreLabel(kind) }
|
||||
}
|
||||
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 7), spacing: 5) {
|
||||
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in
|
||||
let kind = CPUCoreTopology.cores[index]
|
||||
HStack(spacing: 3) {
|
||||
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
|
||||
MetricProgressBar(value: value, color: Color("MetricCPU")).frame(height: 7)
|
||||
}.help("\(index + 1): \(MetricFormat.percent(value))")
|
||||
.accessibilityLabel(Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
MetricProgressBar(value: value, color: coreColor(kind)).frame(height: 7)
|
||||
}.help((kind.map { coreLabel($0) + Text(verbatim: " · ") } ?? Text("cpu.core")) + Text(verbatim: "\(index + 1): \(MetricFormat.percent(value))"))
|
||||
.accessibilityLabel(kind.map { coreLabel($0) } ?? Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
}
|
||||
}.padding(.vertical, 3)
|
||||
|
||||
} else { Text("metric.waiting").foregroundStyle(.secondary) }
|
||||
Spacer(minLength: 0)
|
||||
HStack { line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / ")); Spacer(minLength: 8); AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600)) }
|
||||
HStack { line("system.load", snapshot.load.map(MetricFormat.decimal).joined(separator: " / ")).help(Text("cpu.load.help", tableName: "CPUDetails")); Spacer(minLength: 8); Text("panel.uptime").foregroundStyle(.secondary); AnimatedMetricText(value: String(format: "%.1f h", snapshot.uptime / 3600)) }
|
||||
.lineLimit(1).minimumScaleFactor(0.7)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user