Repository navigation
feat(process): processMemory.summarize 按进程归属汇总 Lithe 实例的内存 - #43
Merged
Merged
Conversation
宿主传入原生进程表(进程号、父进程号、负责进程号、启动时间、内存、角色), Core 判定每个进程属于主进程、语言服务器、插件服务、子进程还是系统辅助进程, 按类别汇总并给出占用最多的进程。进程号复用、父链成环、重复进程号和缺少主进程 都有明确处理,共享 fixture memory-summary-v1.json 覆盖这些情况。
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.
关联
状态栏的内存详情显示 Lithe 实例占用多少内存:主进程、语言服务器、插件服务、它们启动的子进程,以及 macOS 上替 Lithe 渲染网页的 WebKit 辅助进程。原来桌面端用
ps读进程树、在 Go 里按父进程求和,口径是 RSS,和活动监视器不一致,也算不到系统辅助进程。这个 PR 让 Core 负责判定归属和汇总,宿主只提供原生进程表。桌面端改动在配套 PR 1lck/Lithe-IDEA#1926(固定在本 PR 的 commit5e2a580,本 PR 合入后改为 main 上的 commit)。改动
processMemory.summarize:请求给出主进程号hostProcessId、进程表processes(processId、parentProcessId、name、bytes,可选的responsibleProcessId与startTime)、宿主登记的角色roles(processId、kind、name)和可选的entryLimit;返回totalBytes、按类别的categories(kind、bytes、processCount)、占用最多的entries(kind、name、processId、bytes、processCount)和其余项的合计omitted(count、bytes)。host。childProcess,按主进程的直接子进程分组。responsibleProcessId是主进程的进程是systemHelper(macOS 的 WebKit 辅助进程),按最上层的这类进程分组。entryLimit默认 20、最多 200;名称截到 80 个字符;占用相同时按类别、名称、进程号排序,结果稳定。invalid_request。rust/crates/process/src/memory.rs,由lithe-process导出;Cargo.toml的描述同步更新。protocol/command.rs(枚举和命令名)、runtime/dispatcher.rs(分发,坏请求返回invalid_request)、runtime/request_trace.rs(状态栏每隔几秒调用一次,列为高频命令,不逐次追踪,测试同步)。rust/contracts/rust-core-api.md:命令表新增一行,新增 “processMemory.summarize” 一节,写明请求、归属规则、返回值和错误。rust/fixtures/process-lifecycle/memory-summary-v1.json:7 个用例(实例的每一部分、从终端启动的主进程不负责辅助进程、父进程比子进程晚启动即进程号复用、父链成环、角色指向主进程/重复/已退出的进程、超出上限的项合计且同值按类别名称进程号排序、上限为 0 只返回合计)和 5 个无效请求(缺少主进程、重复进程号、未知角色、缺少 bytes、负的 bytes)。桌面端测试读同一份样例。验证
cargo test -p lithe-process -p lithe-core:全部通过,含memory.rs的单元测试和tests/process_memory.rs对共享样例的回放。cargo fmt --all -- --check、cargo clippy -p lithe-process -p lithe-core --all-targets -- -D warnings、scripts/rust-core/verify-rust-core-comments.sh:通过。LITHE_CORE_RUST_DIR指向本分支跑scripts/desktop/desktop-go.sh test ./...:55 个包全部通过。不涉及插件契约、能力版本或插件函数协议,所以不需要更新协议记录。