26 lines
915 B
Swift
26 lines
915 B
Swift
import Foundation
|
|
|
|
nonisolated struct TrendSample: Sendable {
|
|
let date: Date
|
|
let cpu: Double?
|
|
let gpu: Double?
|
|
let memory: Double?
|
|
var download: Double?
|
|
var disk: Double?
|
|
var battery: Double?
|
|
}
|
|
|
|
/// Bounded sampling history; no timer or UI visibility dependence.
|
|
nonisolated struct MetricHistory: Sendable {
|
|
static let capacity = 60
|
|
private(set) var samples: [TrendSample] = []
|
|
|
|
mutating func append(_ snapshot: MetricsSnapshot) {
|
|
samples.append(TrendSample(date: snapshot.date, cpu: snapshot.cpu?.usage,
|
|
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage,
|
|
download: snapshot.downloadRate, disk: snapshot.disk?.usage,
|
|
battery: snapshot.battery?.charge))
|
|
if samples.count > Self.capacity { samples.removeFirst(samples.count - Self.capacity) }
|
|
}
|
|
}
|