refactor(project): 清理闲置展示链路与重复采样状态
This commit is contained in:
@@ -14,7 +14,6 @@ final class MetricsStore {
|
||||
private(set) var processUpdatesRequested = false
|
||||
private(set) var slowMetricsRequested = true
|
||||
let sampling: SamplingPreferences
|
||||
private let energyEnabled: Bool
|
||||
private var panelDemand: Bool { isPanelVisible && !isDisplaySleeping }
|
||||
private var processDemand: Bool { panelDemand && processUpdatesRequested }
|
||||
var effectiveMilliseconds: Int { panelDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
@@ -31,9 +30,8 @@ final class MetricsStore {
|
||||
@ObservationIgnored private var needsHistoryBoundary = true
|
||||
@ObservationIgnored private var lastPublishedAt: ContinuousClock.Instant?
|
||||
|
||||
init(sampling: SamplingPreferences? = nil, sampler: SystemSampler = SystemSampler(), energyEnabled: Bool = true) {
|
||||
init(sampling: SamplingPreferences? = nil, sampler: SystemSampler = SystemSampler()) {
|
||||
self.sampler = sampler
|
||||
self.energyEnabled = energyEnabled
|
||||
self.sampling = sampling ?? SamplingPreferences()
|
||||
self.sampling.onChange = { [weak self] in
|
||||
guard let self, !self.isPaused,
|
||||
@@ -78,7 +76,7 @@ final class MetricsStore {
|
||||
var next = await sampler.sample(includeProcesses: self?.processDemand == true,
|
||||
includeSlowMetrics: self?.panelDemand == true && self?.slowMetricsRequested == true,
|
||||
maximumEnergyInterval: max(30, Double(self?.effectiveMilliseconds ?? 2000) / 500),
|
||||
includeEnergy: self?.energyEnabled == true, demandRevision: visibleGeneration, processUpdate: { [weak self] processes in
|
||||
demandRevision: visibleGeneration, processUpdate: { [weak self] processes in
|
||||
Task { @MainActor [weak self] in
|
||||
guard let self, self.visibilityGeneration == visibleGeneration,
|
||||
self.processDemand, !self.isPaused, !self.isSystemSleeping else { return }
|
||||
|
||||
@@ -5,12 +5,6 @@ import Darwin
|
||||
nonisolated enum SamplingDiagnostics {
|
||||
static let enabled = ProcessInfo.processInfo.environment["KYMO_DIAGNOSTICS"] == "1"
|
||||
|
||||
static func recordTextPresentation(processes: Int, cells: Int) {
|
||||
guard enabled else { return }
|
||||
let line = "{\"event\":\"textPresentation\",\"processes\":\(processes),\"createdCells\":\(cells)}\n"
|
||||
try? FileHandle.standardOutput.write(contentsOf: Data(line.utf8))
|
||||
}
|
||||
|
||||
static func recordEnergy(_ snapshot: ProcessEnergySnapshot) {
|
||||
guard enabled else { return }
|
||||
let payload: [String: Any] = ["event": "energy", "recordedAt": Date().timeIntervalSince1970,
|
||||
@@ -21,14 +15,13 @@ nonisolated enum SamplingDiagnostics {
|
||||
try? FileHandle.standardOutput.write(contentsOf: data + Data([10]))
|
||||
}
|
||||
|
||||
static func record(_ snapshot: MetricsSnapshot, event: String = "sample", hiddenHostAlive: Bool? = nil, windowNumber: Int? = nil, hoveredPlots: Int? = nil, nativePlots: Int? = nil, pointerInsidePanel: Bool? = nil, plotBounds: [[Double]]? = nil, animatedPlots: Int? = nil) {
|
||||
static func record(_ snapshot: MetricsSnapshot, event: String = "sample", hiddenHostAlive: Bool? = nil, windowNumber: Int? = nil, hoveredPlots: Int? = nil, nativePlots: Int? = nil, pointerInsidePanel: Bool? = nil, plotBounds: [[Double]]? = nil) {
|
||||
guard enabled else { return }
|
||||
var payload: [String: Any] = [
|
||||
"event": event, "timestamp": snapshot.date.timeIntervalSince1970,
|
||||
"recordedAt": Date().timeIntervalSince1970,
|
||||
"uptime": ProcessInfo.processInfo.systemUptime,
|
||||
"pid": ProcessInfo.processInfo.processIdentifier,
|
||||
"load": snapshot.load
|
||||
"pid": ProcessInfo.processInfo.processIdentifier
|
||||
]
|
||||
payload["hiddenHostAlive"] = hiddenHostAlive
|
||||
payload["windowNumber"] = windowNumber
|
||||
@@ -36,7 +29,6 @@ nonisolated enum SamplingDiagnostics {
|
||||
payload["nativePlots"] = nativePlots
|
||||
payload["pointerInsidePanel"] = pointerInsidePanel
|
||||
payload["plotBounds"] = plotBounds
|
||||
payload["animatedPlots"] = animatedPlots
|
||||
payload["cpu"] = snapshot.cpu?.usage
|
||||
payload["cores"] = snapshot.cpu?.cores.count
|
||||
payload["cpuTemperature"] = snapshot.cpuTemperature
|
||||
|
||||
Reference in New Issue
Block a user