fix(charts): 修复浮窗层级并平滑切频与曲线移出

This commit is contained in:
2026-11-03 12:07:01 +08:00
parent 36b8e32af3
commit 7ef92d9c21
17 changed files with 271 additions and 59 deletions
+18 -1
View File
@@ -33,6 +33,8 @@ import Foundation
precondition(store.snapshot.date == hiddenDate && store.snapshot.processes == nil)
preferences.backgroundMilliseconds = 500
try await until { store.snapshot.date > hiddenDate }
precondition(store.history.samples.last?.breakBefore == false)
precondition(store.history.samples.last?.expectedInterval == 0.5)
let first = store.snapshot.date
try await until { store.snapshot.date > first }
precondition(store.snapshot.date.timeIntervalSince(first) >= 0.45)
@@ -62,6 +64,19 @@ import Foundation
precondition(didDeliver, "Reopened process request must complete without another sample")
precondition(probe.count >= 2 && probe.peak == 1)
await deferred.setProcessVisible(false)
let slowRead = DelayedProcessRead(delay: 0.5)
let changing = SamplingPreferences(defaults: defaults)
changing.panelMilliseconds = 500
changing.backgroundMilliseconds = 1_800_000
let changingStore = MetricsStore(sampling: changing, sampler: SystemSampler(processRead: { slowRead.read(&$0) }))
changingStore.setPanelVisible(true)
try await until { !changingStore.history.samples.isEmpty }
precondition(changingStore.snapshot.processes == nil)
let countBeforeChange = changingStore.history.samples.count
changing.panelMilliseconds = 1_800_000
try await until { changingStore.snapshot.processes != nil }
precondition(changingStore.history.samples.count == countBeforeChange, "Rate changes must preserve in-flight process delivery without an extra quick sample")
changingStore.togglePause()
print("PASS: defaults, 100ms quantization/clamping, independent persistence, invalid defaults, active/background wake, pause precedence, slow-interval initial processes and history boundary")
}
@MainActor private static func until(_ predicate: () -> Bool) async throws {
@@ -78,6 +93,8 @@ private actor ProcessDelivery {
private final class DelayedProcessRead: @unchecked Sendable {
private let lock = NSLock()
private let delay: TimeInterval
init(delay: TimeInterval = 0.2) { self.delay = delay }
private var active = 0
private var reads = 0
private var maximum = 0
@@ -86,7 +103,7 @@ private final class DelayedProcessRead: @unchecked Sendable {
func read(_ monitor: inout ProcessMonitor) -> ProcessSnapshot {
lock.lock(); active += 1; reads += 1; maximum = max(maximum, active); lock.unlock()
defer { lock.lock(); active -= 1; lock.unlock() }
Thread.sleep(forTimeInterval: 0.2)
Thread.sleep(forTimeInterval: delay)
return monitor.sample()
}
}