fix: two-phase ps sampling for space-safe command parsing (issue #29)#38
Merged
Conversation
added 2 commits
April 21, 2026 11:53
…pace-sensitive field splitting (issue #29) Phase 1: parse pid/cpu/rss via regex from `ps -axo pid=,%cpu=,rss=` (no comm=) Phase 2: fetch `ps -p <pid> -o comm=` concurrently for top-priority PIDs only Covered by 6 regression tests in Tests/ProcessBarMonitorTests/
…ilable command (PR #38 review fix) The pid-based fallback key ("pid:<n>") is now used when command is nil and no metadata cache entry exists, instead of the previous "" fallback that caused unrelated processes to collapse into one aggregate. Also adds: - aggregateKeyForTest() test helper (static, nonisolated) - 4 new aggregation regression tests: • non-prioritized nil-command processes each get unique key • prioritized PID with failed fetchCommand avoids empty-key collision • resolved commands still group correctly by command string • spaced command paths resolve correctly without pid fallback Fixes review blocking issue on PR #38.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
根因:原代码
ps -axo pid=,comm=,%cpu=,rss=按空格 split 解析,command/path 含空格时字段错位导致整行被丢弃,top apps 列表缺少真实高负载进程。方案:两阶段采样,完全避开空格问题:
ps -axo pid=,%cpu=,rss=用正则稳定解析 pid/cpu/rss,command 置空ps -p <pid> -o comm=(comm= 格式无空格),填回 command改动
ProcessSnapshotProvider.swiftcomm=字段;新增fetchCommand()/fetchCommands();RawProcess.command改为可选ProcessSnapshotProviderTests.swiftPackage.swiftProcessBarMonitorTeststest targetswift build && swift test✅待你 review / 合并
按流程,等你确认后 merge。