refactor(project): 清理闲置展示链路与重复采样状态
This commit is contained in:
@@ -24,8 +24,6 @@ actor SystemSampler {
|
||||
private var batteryTask: Task<Void, Never>?
|
||||
private var diskCache: DiskHealthMetrics?
|
||||
private var batteryCache: Double?
|
||||
private var diskDate: Date?
|
||||
private var batteryDate: Date?
|
||||
private var nextDisk: TimeInterval = 0
|
||||
private var nextBattery: TimeInterval = 0
|
||||
private let processRead: @Sendable (inout ProcessMonitor) -> ProcessSnapshot
|
||||
@@ -67,7 +65,7 @@ actor SystemSampler {
|
||||
// A synchronous OS read may outlive cancellation. Keep the in-flight slot occupied.
|
||||
}
|
||||
|
||||
func sample(includeProcesses: Bool? = nil, includeSlowMetrics: Bool = true, maximumEnergyInterval: TimeInterval = 30, includeEnergy: Bool = true, demandRevision: Int? = nil,
|
||||
func sample(includeProcesses: Bool? = nil, includeSlowMetrics: Bool = true, maximumEnergyInterval: TimeInterval = 30, demandRevision: Int? = nil,
|
||||
processUpdate: (@Sendable (ProcessSnapshot) -> Void)? = nil,
|
||||
energyUpdate: (@Sendable (ProcessEnergySnapshot) -> Void)? = nil) -> MetricsSnapshot {
|
||||
guard !Task.isCancelled else { return MetricsSnapshot() }
|
||||
@@ -75,7 +73,7 @@ actor SystemSampler {
|
||||
setProcessVisible(includeProcesses ?? processVisible, revision: demandRevision)
|
||||
self.maximumEnergyInterval = min(3600, max(30, maximumEnergyInterval))
|
||||
self.processUpdate = processUpdate
|
||||
self.energyUpdate = includeEnergy ? energyUpdate : nil
|
||||
self.energyUpdate = energyUpdate
|
||||
if !didProbe {
|
||||
didProbe = true
|
||||
if ProcessInfo.processInfo.environment["KYMO_PANEL_PROBE"] == "1" { PanelCapabilityProbe.run() }
|
||||
@@ -104,7 +102,6 @@ actor SystemSampler {
|
||||
result.battery = BatteryMonitor.sample()
|
||||
result.batteryState = result.battery == nil ? BatteryMonitor.availability() : .present
|
||||
result.gpu = GPUMonitor.sample()
|
||||
result.gpuUsage = result.gpu?.usage
|
||||
if includeSlowMetrics && volumeTask == nil && start - volumeSampleTime >= 30 {
|
||||
volumeTask = Task.detached(priority: .utility) { [self] in
|
||||
let value = DiskMonitor.volumes()
|
||||
@@ -120,13 +117,9 @@ actor SystemSampler {
|
||||
startProcessesIfNeeded()
|
||||
result.processes = processVisible ? processCache : nil
|
||||
result.diskHealth = diskCache
|
||||
result.diskHealthDate = diskDate
|
||||
result.battery?.health = batteryCache
|
||||
result.batteryHealthDate = batteryDate
|
||||
result.volumes = volumes
|
||||
result.uptime = ProcessInfo.processInfo.systemUptime
|
||||
var load = [Double](repeating: 0, count: 3)
|
||||
if getloadavg(&load, 3) == 3 { result.load = load }
|
||||
if ProcessInfo.processInfo.environment["KYMO_PANEL_PROBE"] == "1" {
|
||||
let line = "{\"event\":\"sampleDuration\",\"milliseconds\":\((ProcessInfo.processInfo.systemUptime - start) * 1000)}\n"
|
||||
try? FileHandle.standardOutput.write(contentsOf: Data(line.utf8))
|
||||
@@ -146,11 +139,11 @@ actor SystemSampler {
|
||||
volumes = value; volumeSampleTime = ProcessInfo.processInfo.systemUptime; volumeTask = nil
|
||||
}
|
||||
private func finishDisk(_ value: DiskHealthMetrics?) {
|
||||
diskCache = value; diskDate = value == nil ? nil : Date()
|
||||
diskCache = value
|
||||
nextDisk = ProcessInfo.processInfo.systemUptime + (value == nil ? 600 : 3600); diskTask = nil
|
||||
}
|
||||
private func finishBattery(_ value: Double?) {
|
||||
batteryCache = value; batteryDate = value == nil ? nil : Date()
|
||||
batteryCache = value
|
||||
nextBattery = ProcessInfo.processInfo.systemUptime + (value == nil ? 600 : 3600); batteryTask = nil
|
||||
}
|
||||
private func startProcessesIfNeeded() {
|
||||
|
||||
Reference in New Issue
Block a user