Repository navigation
mtproto-debug: 抓包页可以调缓冲上限,重载后保留 - #23
Open
std-external wants to merge 1 commit into
Open
std-external wants to merge 1 commit into
std-external wants to merge 1 commit into
Conversation
原来的 maxEvents 只能改配置文件,改完还得重启插件。现在页面上的 「N max」改成按钮:输入 100..20000 的整数,服务端 setMaxEvents 立即生效(先把 pending flush 进缓冲再整块淘汰),浏览器用 localStorage 记住,下次打开自动套用;配置默认值仍是 2000。 对应 Anillc 报的「2000 max 一下就刷下去」。单测覆盖运行时改上限、 整块淘汰计数,以及本地设置的解析/存储。
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.
问题
抓包页只有
N retained · 2,000 max · M dropped三个读数,想抓更多现场只能改配置文件再重启插件。群里报的现象是「2,000 max 一下就刷下去了」,先是被丢了 1,500 条,等反应过来现场已经没了。maxEvents本身早就是配置项(packages/mtproto-debug/src/index.ts,默认 2,000,范围 100..20,000),缺的是运行时入口。修复
maxEvents继续保持配置默认 2,000,另外让抓包页可以直接改,改完立即生效:app.yml/.runtime/app.yml里的maxEvents照旧可配(改配置文件仍需重启插件),默认 2000,边界 100..20,000 抽成MIN_MAX_EVENTS/MAX_MAX_EVENTSsetMaxEvents(value)(MtprotoDebugData,走 WebUI 的 Muon RPC):校验整数和范围 → 先把pending里的事件 flush 进缓冲 → 更新maxEvents/chunkSize→entry.mutate同步maxEvents、把本次淘汰数累加到dropped、revision += 1让页面重新拉一页chunks.ts的evictChunks提升为导出的trimChunkedEvents:缩小上限时立即整块淘汰,不用等新事件进来;淘汰仍以块为单位(每块 ≤250 条,块大小ceil(maxEvents/16)),保留窗口最多比上限少一块2,000 max变成按钮,点开Buffer size对话框,输入 100..20,000 的整数后 Apply;值写进localStorage(crossgram.mtproto-debug.maxEvents),页面下次打开时若和服务端当前值不同会自动重新套用(服务端重启回落到配置默认值也一样),坏值/无 storage 时静默忽略内存参考(本机用真实
serializeDebugEvent+ 分块缓冲合成 2 万条混合流量实测,脚本在任务目录):每条约 3.7 KB 堆、约 2.8 KB JSON,2,000 条 ≈ 7 MB,20,000 条 ≈ 70 MB。想再往上要同时调MAX_MAX_EVENTS并压测。验证
yarn vitest run packages/mtproto-debug:54 passed(新增src/index.test.ts的运行时改上限用例:先 flush 再淘汰、retained ≤ 新上限、dropped累加、非法值 50 / 1.5 / 字符串被拒;src/chunks.test.ts的trimChunkedEvents整块淘汰 + 放大上限不丢数据;新增client/buffer-size.test.ts的范围校验/存储往返/坏值容错)yarn vitest run packages/test-suite/src/config-schema.test.ts:24 passed(配置 schema 字段未变)yarn vitest run --config vitest.webui-react.config.mts packages/mtproto-debug/client:page/recordings/buffer-size通过npx tsc -p tsconfig.webui.json:通过2,000 max→ 输入 20000 → Apply → 标题读数变20,000 max、页面刷新后仍是 20,000;改回 2000 时dropped立刻按块增加来源:群里同学报告的抓包缓冲太小(QQ 群,MTProto capture 页面截图)。
后续(不在本 PR)
缓冲满时自动转存到已有的录制目录(复用
recordings.ts的RecordingStore.save(),约几十行),需要的话单独提。