From 050ee30f56740bc2503779878ca07ad1431de300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Sat, 7 Nov 2026 14:53:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(monitors):=20=E4=BF=AE=E5=A4=8D=E7=9F=AD?= =?UTF-8?q?=E6=9A=82=E9=9A=90=E8=97=8F=E9=87=8D=E5=BC=80=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E8=B6=8B=E5=8A=BF=E8=AF=AF=E6=96=AD=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++- SMARTService/Info.plist | 2 +- docs/README.md | 1 + docs/architecture.md | 2 +- docs/background-trend-continuity-fix.md | 31 ++++++++++++ docs/free-test-distribution.md | 6 +-- docs/testing.md | 2 + kymo.xcodeproj/project.pbxproj | 4 +- kymo/Core/Models/MetricHistory.swift | 16 +++++- kymo/Core/Services/MetricsStore.swift | 3 ++ kymo/UI/Charts/PanelCurveGeometry.swift | 4 +- kymoTests/BackgroundTrendChecks.swift | 62 +++++++++++++++++++++++ kymoTests/GPUStatisticsChecks.swift | 4 +- kymoTests/NativeMetricDrawingChecks.swift | 9 ++++ kymoTests/PanelCurveChecks.swift | 4 ++ kymoTests/SamplingChecks.swift | 15 ++++++ tools/check.py | 1 + 17 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 docs/background-trend-continuity-fix.md create mode 100644 kymoTests/BackgroundTrendChecks.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 95fa3f2..8f3741b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ ## [1.1] - 2026-11-07 +### 修复 + +- 启用后台趋势时,短暂隐藏未到后台采样截止即重开,保留中间经历的慢周期,修复曲线被误判漏采而断线;关闭后台记录、暂停和休眠后的真实断点继续生效。 + ### 性能 - 保留现有彩色卡片和原生自绘图表,数字、曲线、圆环、进度条统一随采样静态更新;移除滚动、插值、渐变填充、模糊材质和装饰阴影。 @@ -20,7 +24,7 @@ ### 验证 - 真实窗口检查覆盖静态文字 / 图表更新、环境继承、状态保留、尺寸、无动画 / 渐变层和卸载;保留连续网络读取与实际采样检查。 -- 本地测试包版本为 1.1(3);移除减弱动画开关,旧偏好不影响静态呈现。改造、资源对照与剩余验收见 `docs/static-presentation-plan.md`。 +- 本地测试包版本为 1.1(4);静态改造与资源对照见 `docs/static-presentation-plan.md`,后台趋势修复与回归见 `docs/background-trend-continuity-fix.md`。旧动效偏好不影响静态呈现。 ## [0.1.0] - 2026-10-29 diff --git a/SMARTService/Info.plist b/SMARTService/Info.plist index 548d98c..7320f52 100644 --- a/SMARTService/Info.plist +++ b/SMARTService/Info.plist @@ -8,6 +8,6 @@ CFBundleName$(PRODUCT_NAME) CFBundlePackageTypeXPC! CFBundleShortVersionString1.1 -CFBundleVersion3 +CFBundleVersion4 XPCServiceServiceTypeApplication diff --git a/docs/README.md b/docs/README.md index f4bce08..a33e087 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,6 +12,7 @@ | [同类开源工具 CPU 与功耗调研](open-source-efficiency-research.md) | Stats、MenuMeters、eul、macmon 的源码机制、与 Kymo 的差异及待验证优化方向 | | [1.1 初版实施记录](v1.1-efficiency-plan.md) | 历史:保留动效的卡片宿主隔离、唤醒合并与缓冲复用 | | [静态呈现与轻量图表](static-presentation-plan.md) | 当前:保留卡片配色,移除动效与特效,原生静态图表与验证 | +| [后台趋势连续性修复](background-trend-continuity-fix.md) | 1.1(4):短暂隐藏未到后台采样截止时,重开曲线仍保持连续 | 首批实施证据见[轻量化实施记录](efficiency-first-batch.md);第二批见[能量列表与纯文字对照记录](efficiency-second-batch.md)。第三批见[原生绘制与进程表记录](efficiency-third-batch.md);第四批见[动效与效率排查](motion-and-efficiency-plan.md);其淡入实现已由[保留原动效的优化](motion-preservation-plan.md)替代。进程内存显示修正见[footprint 口径与单位对齐](process-memory-alignment-plan.md)。包体积已收敛,真实 CPU 能量列表已实现;内存与长期性能预算仍待通过。 diff --git a/docs/architecture.md b/docs/architecture.md index 338886b..4596222 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -50,7 +50,7 @@ SMARTService(XPC)──→ 温度 / 风扇 / SMART 客户端 ──→ 慢 进程只在面板可见且未暂停时读取。进程结果可异步单独发布到 processSnapshot,资源 snapshot 的 processes 保持 nil;能耗独立发布到 energy。进程与能耗区以独立 View 订阅,避免异步进程发布再次使整个资源区失效。可见性代次和调度代次阻止过期结果回写;隐藏时清除已发布进程,重新打开重建基线。同步系统调用即使不能及时取消,也会占用原在途槽,避免重叠读取。路径按完整身份与命令名缓存 30 秒(包含失败结果),每轮复用一个路径缓冲;枚举失败清空缓存,末次身份复核保留。进程退出提示以原始成功快照中的完整身份为准,搜索过滤和枚举失败不作为退出证据。 -暂停取消采样发布、停用进程更新,保留当前快照和历史;已启动慢读取可能自行结束。恢复时重置 CPU / 网络 / IO 基线,历史标记断点。全局及每接口历史各最多 60 点,接口移除时清理其历史;实际覆盖时长由采样间隔决定。图表按真实时间和缺失值处理间断。GPU 平均统计仅累计有效且连续的时间区间。 +暂停取消采样发布、停用进程更新,保留当前快照和历史;已启动慢读取可能自行结束。恢复时重置 CPU / 网络 / IO 基线,历史标记断点。全局及每接口历史各最多 60 点,接口移除时清理其历史;实际覆盖时长由采样间隔决定。每点的 expectedInterval 表示其后等待下一点的计划周期;需求连续的重新调度将最长周期记入最近点,即使短暂隐藏未到后台采样截止也不丢失慢周期。下一点重新使用当前配置。图表和 GPU 平均统计只用左端点周期判断当前段,避免反向放宽旧空档;真实时间、缺失值和显式停采断点继续生效。详见[后台趋势修复](background-trend-continuity-fix.md)。 ## XPC 与系统边界 diff --git a/docs/background-trend-continuity-fix.md b/docs/background-trend-continuity-fix.md new file mode 100644 index 0000000..8093465 --- /dev/null +++ b/docs/background-trend-continuity-fix.md @@ -0,0 +1,31 @@ +# 后台趋势重开断层修复 + +2026-11-07,1.1(4)。用户反馈启用隐藏时记录趋势后,隐藏几秒再打开仍出现曲线断层。开始时工作区干净;已有 `/Applications/kymo.app` 主进程与配套 XPC 保持运行,不退出或替换。只读核对本机安装版为 1.1(3),后台开关已开启,前台 2 秒,后台间隔沿用默认 30 秒。 + +## 原因与范围 + +后台采样需求仍有效,但第一次后台采样按 30 秒截止安排。隐藏约 6 秒再重开时,两个实际点都来自前台;原历史只记录点产生时的 2 秒周期,没有记录中间发生过的后台慢周期。图表按相邻点周期推算 5 秒连续性阈值,把正常等待误判为漏采。 + +本次只调整 `Core/Services/MetricsStore`、`Core/Models/MetricHistory`、`UI/Charts/PanelCurveGeometry` 和相关检查。保持原采样频率、后台默认值、可见时才读取进程 / 能量 / 慢指标、真实时间和缺失值;不补造隐藏期间的采样点。 + +## 修复 + +- 将每个历史点的 `expectedInterval` 明确为该点之后等待下一点的计划周期。连续需求下重新调度时,记录最近点经历的最长周期;前台 → 后台 → 前台即使没有产生后台点,也能保留中间等待。 +- 总历史和每接口历史同时记录。下一次真实采样仍以当时实际配置初始化周期,后续前台段不会继续沿用后台慢周期。 +- 图表的每一段只读取左端点的后续周期,GPU 时间加权统计采用相同方向;新周期不反向放宽此前的漏采间隔。 +- 无消费者、暂停、系统睡眠等真实停采沿用显式断点;无效值、接口缺失和超时仍保留空档。此改动不增加定时任务、补采循环或持久化字段。 + +## 验证记录 + +- 将同一份前台 2 秒 / 后台 30 秒 / 隐藏 6 秒回归分别编译到旧 `80706fa` 核心源码和修复源码:旧版在曲线连续性断言失败,修复后通过。使用隔离偏好域、真实资源 Store 与实际曲线分段函数。 +- 新增 `BackgroundTrendChecks`:前台 2 秒 / 后台 30 秒,隐藏 6 秒未到后台采样时重开;短后台周期确实产生真实样本且进程 / 能量保持停止;关闭后台记录后停采与重开真实断点。 +- 模型检查覆盖每接口周期、空历史、非法周期、周期缩短不丢弃已有等待、下一点恢复前台周期。曲线和 GPU 检查防止把后来的慢周期反向应用到早先漏采;原生图层另查连续段和真实空档像素。 +- Debug 构建通过;普通 ad-hoc Release 打包通过。新 ZIP 解压后运行 `python3 tools/check.py --app <解压后的 kymo.app 绝对路径> --gui --services --network`,37 项 Swift 检查、209 项三语言文案和宿主权限全部通过,包含真实 NSPanel 生命周期、曲线像素、暂停 / 显示器与系统睡眠状态、签名沙盒 XPC 和生产 HTTPS。后台连续性回归测试禁用进程能量读取以聚焦资源历史;实际 XPC 能量 RPC 由 ReleaseServiceChecks 单独覆盖。 + +## 测试包与交付 + +本地测试包 `dist/kymo-1.1-4-arm64-adhoc.zip`,1,063,099 字节,SHA-256 `d3decf56c0187f2fa0a376f485bce3f4b2731a903a4cabd364d7ee5ffd290744`。主应用与服务均为 1.1(4);原包 / 解压包的签名、Hardened Runtime、精确权限及最终 ZIP 校验通过。arm64、最低 macOS 27.0、ad-hoc 签名且未公证,跨机器默认 Gatekeeper 启动未验。 + +保留此前测试包。未安装、未替换或退出用户正在运行的 `/Applications/kymo.app`,未修改其偏好,未推送。临时隔离源码、构建和测试日志在验证后清理;本次失败回归创建的随机测试偏好和诊断报告仅按专用名称及本轮创建时间清理。 + +外部菜单栏鼠标 / 键盘输入、真实系统睡眠和长期能耗按本轮实际验证范围报告,不能由程序内切换和短时检查代替。 diff --git a/docs/free-test-distribution.md b/docs/free-test-distribution.md index e35d045..aa90fcb 100644 --- a/docs/free-test-distribution.md +++ b/docs/free-test-distribution.md @@ -2,7 +2,7 @@ ## 适用范围 -当前产物:Kymo 1.1(build 3),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。 +当前产物:Kymo 1.1(build 4),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。 ## 构建与校验 @@ -10,10 +10,10 @@ python3 tools/package_release.py ``` -默认输出:`dist/kymo-1.1-3-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件: +默认输出:`dist/kymo-1.1-4-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件: ```bash -shasum -a 256 -c kymo-1.1-3-arm64-adhoc.zip.sha256 +shasum -a 256 -c kymo-1.1-4-arm64-adhoc.zip.sha256 ``` SHA-256 用于核对文件是否与发布者给出的文件一致,不等同于 Apple 身份认证;校验值应从可信渠道获取。 diff --git a/docs/testing.md b/docs/testing.md index e79c16c..c71f179 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -305,6 +305,8 @@ Release 配置由各 Target 在签名前 strip,保留包外 dSYM;测量必 ## 静态呈现与后台记录 +`BackgroundTrendChecks` 使用真实 Store 验证前台 2 秒 / 后台 30 秒、隐藏 6 秒未到后台截止即重开的曲线连续性;另验实际后台样本、隐藏进程 / 能量停止、关闭后台后保留真实断点。`SamplingChecks` 覆盖总历史与每接口的后续周期记录,`PanelCurveChecks`、`GPUStatisticsChecks` 和原生图层检查防止周期变化反向连接真正的漏采。修复与验证记录见[后台趋势连续性](background-trend-continuity-fix.md)。 + 界面统一静态刷新,不再提供减弱动画开关,也不再接受该旧偏好改变呈现。`AppearancePreferencesChecks` 检查旧键保持原值、外观与后台记录互不影响;`SamplingIntervalChecks` 继续覆盖暂停、隐藏、睡眠、恢复和历史断点。 此前保留动效和命令行减弱模式的实验属于历史,见[动效排查](motion-and-efficiency-plan.md)与[保留动效记录](motion-preservation-plan.md)。本次以相同采样配置比较旧 1.1 和静态版,不通过同时停采获取虚假动效收益。当前测量与工具能力以[静态呈现计划](static-presentation-plan.md)的本轮记录为准。 diff --git a/kymo.xcodeproj/project.pbxproj b/kymo.xcodeproj/project.pbxproj index 94a0acc..8d5dce4 100644 --- a/kymo.xcodeproj/project.pbxproj +++ b/kymo.xcodeproj/project.pbxproj @@ -425,7 +425,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEAD_CODE_STRIPPING = YES; ENABLE_APP_SANDBOX = YES; ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES; @@ -458,7 +458,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEAD_CODE_STRIPPING = YES; ENABLE_APP_SANDBOX = YES; ENABLE_HARDENED_RUNTIME = YES; diff --git a/kymo/Core/Models/MetricHistory.swift b/kymo/Core/Models/MetricHistory.swift index 68d0a43..bb2e0b4 100644 --- a/kymo/Core/Models/MetricHistory.swift +++ b/kymo/Core/Models/MetricHistory.swift @@ -20,6 +20,7 @@ nonisolated struct TrendSample: Sendable { var memoryWired: Double? var memoryCompressed: Double? var breakBefore = false + /// Scheduled cadence after this point, including changes before the next sample. var expectedInterval: TimeInterval = 2 } @@ -29,6 +30,18 @@ nonisolated struct MetricHistory: Sendable { private(set) var samples: [TrendSample] = [] private(set) var interfaces: [String: [InterfaceTrendSample]] = [:] + /// A slow cadence can begin and end without producing a point (for example a short hide). + /// Preserve that outgoing wait on the existing point without changing earlier segments. + mutating func recordScheduledInterval(_ interval: TimeInterval) { + guard interval.isFinite, interval > 0, let last = samples.indices.last else { return } + samples[last].expectedInterval = max(samples[last].expectedInterval, interval) + for key in interfaces.keys { + guard let index = interfaces[key]?.indices.last, + let previous = interfaces[key]?.last?.expectedInterval else { continue } + interfaces[key]?[index].expectedInterval = max(previous, interval) + } + } + 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, @@ -55,6 +68,7 @@ nonisolated struct InterfaceTrendSample: Sendable { let date: Date let download: Double? let upload: Double? + /// Scheduled cadence from this point to the next interface sample. var expectedInterval: TimeInterval = 2 } @@ -72,7 +86,7 @@ nonisolated struct GPUUtilizationSummary { 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 <= max(a.expectedInterval, b.expectedInterval) * 2.5, + 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 } diff --git a/kymo/Core/Services/MetricsStore.swift b/kymo/Core/Services/MetricsStore.swift index 6afb666..3d33b09 100644 --- a/kymo/Core/Services/MetricsStore.swift +++ b/kymo/Core/Services/MetricsStore.swift @@ -54,6 +54,9 @@ final class MetricsStore { needsHistoryBoundary = needsHistoryBoundary || reset scheduledInterval = effectiveMilliseconds guard hasSamplingDemand else { needsHistoryBoundary = true; return } + if !needsHistoryBoundary { + history.recordScheduledInterval(Double(scheduledInterval) / 1000) + } var delay = Duration.zero if !sampleImmediately, let lastPublishedAt { delay = max(.zero, .milliseconds(effectiveMilliseconds) - lastPublishedAt.duration(to: .now)) diff --git a/kymo/UI/Charts/PanelCurveGeometry.swift b/kymo/UI/Charts/PanelCurveGeometry.swift index 63f1ee4..4951144 100644 --- a/kymo/UI/Charts/PanelCurveGeometry.swift +++ b/kymo/UI/Charts/PanelCurveGeometry.swift @@ -8,8 +8,8 @@ nonisolated enum PanelCurveGeometry { static func allowedGap(at index: Int, intervals: [TimeInterval], fallback: TimeInterval) -> TimeInterval { guard index > 0, index < intervals.count else { return fallback } - let pair = [intervals[index - 1], intervals[index]].filter { $0.isFinite && $0 > 0 } - return pair.isEmpty ? fallback : max(5, (pair.max() ?? 2) * 2) + let interval = intervals[index - 1] + return interval.isFinite && interval > 0 ? max(5, interval * 2) : fallback } static func runs(dates: [Date], values: [Double?], maximumGap: TimeInterval = 5, boundaryDates: Set = [], intervals: [TimeInterval] = []) -> [[Sample]] { diff --git a/kymoTests/BackgroundTrendChecks.swift b/kymoTests/BackgroundTrendChecks.swift new file mode 100644 index 0000000..3faef20 --- /dev/null +++ b/kymoTests/BackgroundTrendChecks.swift @@ -0,0 +1,62 @@ +import Foundation + +@main struct BackgroundTrendChecks { + @MainActor static func main() async throws { + let suite = "kymo-background-checks-" + UUID().uuidString + let defaults = UserDefaults(suiteName: suite)! + defer { defaults.removePersistentDomain(forName: suite) } + let preferences = SamplingPreferences(defaults: defaults) + preferences.panelMilliseconds = 2_000 + preferences.backgroundMilliseconds = 30_000 + preferences.backgroundEnabled = true + let store = MetricsStore(sampling: preferences, energyEnabled: false) + store.setPanelVisible(true) + try await until { store.history.samples.count >= 2 } + store.setPanelVisible(false) + let hiddenCount = store.history.samples.count + try await Task.sleep(for: .seconds(6)) + precondition(store.history.samples.count == hiddenCount, "The 30-second background deadline has not arrived") + precondition(store.processSnapshot == nil && store.energy == nil) + store.setPanelVisible(true) + try await until { store.history.samples.count > hiddenCount } + let samples = store.history.samples + let runs = PanelCurveGeometry.runs(dates: samples.map(\.date), values: samples.map(\.memory), + boundaryDates: Set(samples.filter(\.breakBefore).map(\.date)), intervals: samples.map(\.expectedInterval)) + precondition(runs.count == 1, "Short hides with background recording enabled must keep a continuous curve") + print("PASS: six-second hide before the first 30-second background sample remains continuous") + + // A full background interval must still collect real resource samples without process scans. + preferences.backgroundMilliseconds = 1_000 + store.setPanelVisible(false) + let backgroundCount = store.history.samples.count + try await until { store.history.samples.count >= backgroundCount + 2 } + precondition(store.processSnapshot == nil && store.energy == nil) + store.setPanelVisible(true) + let lastBackgroundDate = store.snapshot.date + try await until { store.snapshot.date > lastBackgroundDate } + let recorded = store.history.samples + precondition(PanelCurveGeometry.runs(dates: recorded.map(\.date), values: recorded.map(\.memory), + boundaryDates: Set(recorded.filter(\.breakBefore).map(\.date)), intervals: recorded.map(\.expectedInterval)).count == 1) + print("PASS: hidden resource samples are recorded and reconnect on reopen") + + preferences.backgroundEnabled = false + store.setPanelVisible(false) + let stoppedCount = store.history.samples.count + try await Task.sleep(for: .milliseconds(650)) + precondition(store.history.samples.count == stoppedCount) + store.setPanelVisible(true) + try await until { store.history.samples.count > stoppedCount } + precondition(store.history.samples.last?.breakBefore == true) + let stopped = store.history.samples + precondition(PanelCurveGeometry.runs(dates: stopped.map(\.date), values: stopped.map(\.memory), + boundaryDates: Set(stopped.filter(\.breakBefore).map(\.date)), intervals: stopped.map(\.expectedInterval)).count == 2) + store.togglePause() + print("PASS: disabling background recording still stops sampling and preserves the real gap") + } + + @MainActor private static func until(_ predicate: () -> Bool) async throws { + let deadline = ContinuousClock.now.advanced(by: .seconds(4)) + while !predicate() && ContinuousClock.now < deadline { try await Task.sleep(for: .milliseconds(20)) } + precondition(predicate(), "Timed out waiting for a resource sample") + } +} diff --git a/kymoTests/GPUStatisticsChecks.swift b/kymoTests/GPUStatisticsChecks.swift index b56c94f..4dd9d33 100644 --- a/kymoTests/GPUStatisticsChecks.swift +++ b/kymoTests/GPUStatisticsChecks.swift @@ -6,7 +6,7 @@ import Foundation TrendSample(date: Date(timeIntervalSince1970: time), cpu: nil, gpu: value, memory: nil, breakBefore: boundary, expectedInterval: interval) } - let variable = GPUUtilizationSummary(samples: [sample(0, 0), sample(2, 1), sample(10, 1, interval: 8)]) + let variable = GPUUtilizationSummary(samples: [sample(0, 0), sample(2, 1, interval: 8), sample(10, 1)]) precondition(abs(variable.average! - 0.9) < 0.00001 && variable.peak == 1) let clipped = GPUUtilizationSummary(samples: [sample(0, 0, interval: 120), sample(120, 1, interval: 120)]) precondition(abs(clipped.average! - 0.75) < 0.00001 && clipped.coverage == 60) @@ -15,6 +15,8 @@ import Foundation precondition(GPUUtilizationSummary(samples: [sample(0, 1), sample(2, nil), sample(4, 0)]).average == nil) precondition(GPUUtilizationSummary(samples: [sample(0, 1), sample(2, 0, boundary: true)]).average == nil) precondition(GPUUtilizationSummary(samples: [sample(0, 1), sample(60, 0)]).average == nil) + precondition(GPUUtilizationSummary(samples: [sample(0, 1), sample(8, 0, interval: 30)]).average == nil, + "A later slow cadence must not reconnect an earlier missed interval") precondition(GPUMonitor.memoryBytes(NSNumber(value: -1)) == nil) precondition(GPUMonitor.memoryBytes(NSNumber(value: Double.nan)) == nil) precondition(GPUMonitor.memoryBytes(NSNumber(value: 0)) == 0) diff --git a/kymoTests/NativeMetricDrawingChecks.swift b/kymoTests/NativeMetricDrawingChecks.swift index 5e3c0c9..9b53356 100644 --- a/kymoTests/NativeMetricDrawingChecks.swift +++ b/kymoTests/NativeMetricDrawingChecks.swift @@ -31,6 +31,15 @@ import QuartzCore precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0, "Missing values must leave a real gap") plot.configure(input([nil,nil,nil,nil])) precondition(redPixels(bitmap(plot)) == 0) + let changedDates = [0.0, 2, 8, 10].map { Date(timeIntervalSinceReferenceDate: $0) } + plot.configure(.init(frame: .init(dates: changedDates, series: [[0.8,0.8,0.8,0.8]], + intervals: [2,30,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5)) + precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) > 10, + "Reopening before the first background deadline must keep the curve connected") + plot.configure(.init(frame: .init(dates: [changedDates[0], changedDates[2]], series: [[0.8,0.8]], + intervals: [2,30], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5)) + precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) == 0, + "A later slow cadence must not reconnect an earlier missed sample") var hovered = continuous; hovered.hoveredIndex = 1 plot.configure(hovered) precondition(redPixels(bitmap(plot)) > 0) diff --git a/kymoTests/PanelCurveChecks.swift b/kymoTests/PanelCurveChecks.swift index ebcbe15..9da965f 100644 --- a/kymoTests/PanelCurveChecks.swift +++ b/kymoTests/PanelCurveChecks.swift @@ -13,6 +13,10 @@ import Foundation precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 3600, boundaryDates: [slow[1]]).count == 2) precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, intervals: [1800, 1800, 0.5]).count == 1) precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, boundaryDates: [slow[2]], intervals: [1800, 1800, 0.5]).count == 2) + let changed = [0.0, 8, 10, 18].map { Date(timeIntervalSinceReferenceDate: $0) } + precondition(PanelCurveGeometry.runs(dates: changed, values: [0.1, 0.2, 0.3, 0.4], + intervals: [2, 30, 2, 2]).count == 3, + "A slow cadence applies only to its outgoing segment; earlier and later real gaps remain gaps") let frame = PanelCurveFrame(dates: dates, series: [Array(repeating: 0.3, count: 60)], intervals: Array(repeating: 2, count: 60), boundaryDates: []) precondition(frame.dates.count == 60) let domain = PanelCurveFrame.domain(begin: dates.first!, end: dates.last!) diff --git a/kymoTests/SamplingChecks.swift b/kymoTests/SamplingChecks.swift index 3c71f95..284b8b4 100644 --- a/kymoTests/SamplingChecks.swift +++ b/kymoTests/SamplingChecks.swift @@ -49,6 +49,21 @@ import Foundation extended.network = nil precondition(extended.downloadRate == nil) + var scheduledHistory = MetricHistory() + scheduledHistory.recordScheduledInterval(30) + extended.network = [NetworkInterfaceMetrics(name: "en0", received: 100, sent: 50, download: 20, upload: 10)] + scheduledHistory.append(extended) + scheduledHistory.recordScheduledInterval(30) + scheduledHistory.recordScheduledInterval(2) + scheduledHistory.recordScheduledInterval(.nan) + scheduledHistory.recordScheduledInterval(-1) + precondition(scheduledHistory.samples.last?.expectedInterval == 30) + precondition(scheduledHistory.interfaces.values.allSatisfy { $0.last?.expectedInterval == 30 }) + scheduledHistory.append(extended) + precondition(scheduledHistory.samples.map(\.expectedInterval) == [30, 2]) + precondition(scheduledHistory.interfaces.values.allSatisfy { $0.map(\.expectedInterval) == [30, 2] }, + "Every interface must preserve only the outgoing slow interval, then resume its normal cadence") + var history = MetricHistory() for index in 0..<100 { var item = MetricsSnapshot() diff --git a/tools/check.py b/tools/check.py index f4e77d5..78e1958 100644 --- a/tools/check.py +++ b/tools/check.py @@ -19,6 +19,7 @@ CHECKS = {name: list(CORE) for name in ( "SamplingChecks", "SamplingIntervalChecks", "UnifiedPanelChecks", "MemoryChecks", "GPUStatisticsChecks", "StageCChecks", "MachPortChecks", "ReleaseServiceChecks")} CHECKS.update({ + "BackgroundTrendChecks": CORE + ["kymo/UI/Charts/PanelCurveGeometry.swift"], "ProcessEnergyChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Core/Models/ProcessEnergy.swift", "kymo/Core/Monitors/ProcessEnergyMonitor.swift"], "ProcessEnergyReaderChecks": ["kymo/Core/Models/ProcessMetrics.swift", "kymo/Core/Models/ProcessEnergy.swift", "SMARTService/ProcessEnergyReader.swift"], "BoundedProcessChecks": ["kymo/Core/Services/BoundedProcess.swift"],