Files
QLinker/tools/probe/reliability-timeline.mjs
T

20 lines
1.2 KiB
JavaScript
Raw Normal View History

// 只读分析:把 reliability-*.jsonl 还原成时间线,用于人工核对断线/重连与事件投递的先后关系。
// 用法: node tools/probe/reliability-timeline.mjs local/reliability-xxx.jsonl [seqFrom]
const fs = await import('node:fs');
const file = process.argv[2];
const from = Number(process.argv[3] || 0);
if (!file) { console.error('用法: node tools/probe/reliability-timeline.mjs <jsonl> [seqFrom]'); process.exit(1); }
const L = fs.readFileSync(file, 'utf8').trim().split(/\r?\n/).filter(Boolean).map((x) => JSON.parse(x));
const t0 = L[0].t;
const rows = [];
for (const o of L) {
if (o.kind === 'conn') rows.push({ t: o.t, s: `CONN ${o.conn} ${o.evt} gen=${o.gen}${o.code != null ? ' code=' + o.code : ''}` });
else if (o.kind === 'event') {
if (Number(o.real_seq) && Number(o.real_seq) >= from) rows.push({ t: o.t, s: `EVENT ${o.conn} gen=${o.gen} seq=${o.real_seq} segs=${o.segs}` });
else rows.push({ t: o.t, s: `EVENT ${o.conn} gen=${o.gen} post=${o.post_type} segs=${o.segs}` });
}
}
rows.sort((a, b) => a.t - b.t);
for (const r of rows) console.log(`+${String(r.t - t0).padStart(6)}ms ${r.s}`);
for (const o of L) if (o.kind === 'verdict') console.log('VERDICT ' + JSON.stringify(o));