refactor(project): 清理闲置展示链路与重复采样状态
This commit is contained in:
@@ -6,7 +6,6 @@ nonisolated struct TrendSample: Sendable {
|
||||
let gpu: Double?
|
||||
let memory: Double?
|
||||
var download: Double?
|
||||
var disk: Double?
|
||||
var battery: Double?
|
||||
var batteryPower: Double?
|
||||
var upload: Double?
|
||||
@@ -45,7 +44,7 @@ nonisolated struct MetricHistory: Sendable {
|
||||
mutating func append(_ snapshot: MetricsSnapshot, breakBefore: Bool = false, expectedInterval: TimeInterval = 2) {
|
||||
samples.append(TrendSample(date: snapshot.date, cpu: snapshot.cpu?.usage,
|
||||
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage,
|
||||
download: snapshot.downloadRate, disk: snapshot.disk?.usage,
|
||||
download: snapshot.downloadRate,
|
||||
battery: snapshot.battery?.charge, batteryPower: snapshot.battery?.power,
|
||||
upload: snapshot.uploadRate,
|
||||
read: snapshot.diskIO?.read, write: snapshot.diskIO?.written,
|
||||
@@ -71,30 +70,3 @@ nonisolated struct InterfaceTrendSample: Sendable {
|
||||
/// Scheduled cadence from this point to the next interface sample.
|
||||
var expectedInterval: TimeInterval = 2
|
||||
}
|
||||
|
||||
/// Time-weighted observed utilization; never bridge failures or sleep boundaries.
|
||||
nonisolated struct GPUUtilizationSummary {
|
||||
let average: Double?
|
||||
let peak: Double?
|
||||
let coverage: TimeInterval
|
||||
|
||||
init(samples: [TrendSample], window: TimeInterval = 60) {
|
||||
guard let end = samples.last?.date else { average = nil; peak = nil; coverage = 0; return }
|
||||
let start = end.addingTimeInterval(-window)
|
||||
peak = samples.filter { $0.date >= start }.compactMap(\.gpu).max()
|
||||
var area = 0.0
|
||||
var duration = 0.0
|
||||
for (a, b) in zip(samples, samples.dropFirst()) {
|
||||
let dt = b.date.timeIntervalSince(a.date)
|
||||
guard !b.breakBefore, dt > 0, dt <= a.expectedInterval * 2.5,
|
||||
let av = a.gpu, let bv = b.gpu else { continue }
|
||||
let overlap = b.date.timeIntervalSince(max(a.date, start))
|
||||
guard overlap > 0 else { continue }
|
||||
let left = av + (bv - av) * (1 - overlap / dt)
|
||||
area += (left + bv) * 0.5 * overlap
|
||||
duration += overlap
|
||||
}
|
||||
coverage = duration
|
||||
average = duration > 0 ? area / duration : nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,15 +35,12 @@ nonisolated struct MetricsSnapshot: Sendable {
|
||||
var diskIO: DiskIOMetrics?
|
||||
var volumes: [VolumeMetrics]?
|
||||
var battery: BatteryMetrics?
|
||||
var load: [Double] = []
|
||||
var uptime: TimeInterval = 0
|
||||
var gpu: GPUMetrics?
|
||||
var processes: ProcessSnapshot?
|
||||
var diskHealthDate: Date?
|
||||
var batteryHealthDate: Date?
|
||||
var batteryState: BatteryAvailability = .unknown
|
||||
// GPU total is backed by validated IOAccelerator device statistics.
|
||||
var gpuUsage: Double? = nil
|
||||
var gpuUsage: Double? { gpu?.usage }
|
||||
}
|
||||
|
||||
nonisolated extension MetricsSnapshot {
|
||||
|
||||
@@ -23,19 +23,17 @@ nonisolated struct ProcessEnergyReply: Codable, Sendable {
|
||||
let readings: [ProcessEnergyReading]
|
||||
}
|
||||
nonisolated struct ProcessEnergyUsage: Identifiable, Sendable {
|
||||
let process: ProcessMetrics
|
||||
let id: ProcessIdentity
|
||||
let watts: Double
|
||||
let seconds: TimeInterval
|
||||
var id: ProcessIdentity { process.id }
|
||||
var formattedPower: String { watts >= 1 ? String(format: "%.2f W", watts) : String(format: "%.1f mW", watts * 1000) }
|
||||
}
|
||||
nonisolated struct ProcessEnergySnapshot: Sendable {
|
||||
enum State: Sendable { case waiting, available, partial, unavailable, unsupported }
|
||||
let date: Date
|
||||
let candidates: Int
|
||||
let readable: Int
|
||||
let measured: Int
|
||||
let rows: [ProcessEnergyUsage] // All valid measurements; no CPU prefilter.
|
||||
var measured: Int { rows.count }
|
||||
let state: State
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user