GitHubivarvong

ply

main
ply6 git calls32 ms24 KiB5 cachedprotocol v2
52 lines3.7 KiBRaw
1// Merge NODE_V8_COVERAGE output from many processes into per-file line coverage for src/, listing uncovered lines.
2// NODE_V8_COVERAGE=/tmp/cov node --test ... && node test/fuzz/*.mjs ...; node test/coverage.mjs /tmp/cov [--lines]
3import { readdirSync, readFileSync } from 'node:fs';
4import { join, relative } from 'node:path';
5import { fileURLToPath } from 'node:url';
7const dir = process.argv[2] ?? '/tmp/cov';
8const showLines = process.argv.includes('--lines');
9const srcRoot = fileURLToPath(new URL('../src/', import.meta.url));
11// per file: max count seen per byte offset (union across processes = max over all ranges that cover the byte)
12const files = new Map(); // url → { source, counts: Int32Array }
13for (const f of readdirSync(dir)) {
14 if (!f.endsWith('.json')) continue;
15 const j = JSON.parse(readFileSync(join(dir, f), 'utf8'));
16 for (const s of j.result) {
17 if (!s.url.startsWith('file://') || !fileURLToPath(s.url).startsWith(srcRoot)) continue;
18 const path = fileURLToPath(s.url);
19 if (!files.has(s.url)) { const source = readFileSync(path, 'utf8'); files.set(s.url, { path, source, counts: new Int32Array(source.length).fill(-1) }); }
20 const { counts } = files.get(s.url);
21 // V8 block coverage: ranges are nested; apply outer first then inner so inner overrides. Sort by start asc, end desc.
22 const ranges = s.functions.flatMap(fn => fn.ranges.map(r => ({ ...r, block: fn.isBlockCoverage })));
23 ranges.sort((a, b) => a.startOffset - b.startOffset || b.endOffset - a.endOffset);
24 const local = new Int32Array(counts.length).fill(-1);
25 for (const r of ranges) local.fill(r.count, r.startOffset, r.endOffset);
26 for (let i = 0; i < counts.length; i++) if (local[i] > counts[i]) counts[i] = local[i];
27 }
30const rows = [];
31let totLines = 0, totCovered = 0;
32for (const [, { path, source, counts }] of [...files].sort()) {
33 const lines = source.split('\n');
34 let off = 0, covered = 0, executable = 0; const uncovered = [];
35 for (let i = 0; i < lines.length; i++) {
36 const line = lines[i], start = off, end = off + line.length; off = end + 1;
37 const code = line.trim();
38 if (!code || code.startsWith('//') || code === '}' || code === '};' || code === ');' || code.startsWith('import ') || code.startsWith('export {') || /^(export )?(const|let) [A-Z_]+ = /.test(code) && !code.includes('=>') && !code.includes('(')) continue;
39 // a line is covered if any non-whitespace byte in it has count > 0; uncovered if all its bytes are 0; unknown (-1) is skipped
40 let any = false, zero = false, known = false;
41 for (let p = start; p < end; p++) { if (/\s/.test(source[p])) continue; const c = counts[p]; if (c < 0) continue; known = true; if (c > 0) { any = true; break; } else zero = true; }
42 if (!known) continue;
43 executable++;
44 if (any) covered++; else uncovered.push(i + 1);
45 }
46 totLines += executable; totCovered += covered;
47 rows.push({ file: relative(srcRoot, path), executable, covered, pct: executable ? (100 * covered / executable) : 100, uncovered });
49const ranges = u => { const out = []; for (let i = 0; i < u.length; i++) { let j = i; while (j + 1 < u.length && u[j + 1] === u[j] + 1) j++; out.push(i === j ? `${u[i]}` : `${u[i]}-${u[j]}`); i = j; } return out.join(','); };
50console.log('file'.padEnd(14), 'lines'.padStart(6), 'cov'.padStart(6), 'pct'.padStart(7));
51for (const r of rows) console.log(r.file.padEnd(14), String(r.executable).padStart(6), String(r.covered).padStart(6), (r.pct.toFixed(1) + '%').padStart(7), showLines && r.uncovered.length ? ' uncovered: ' + ranges(r.uncovered) : '');
52console.log('TOTAL'.padEnd(14), String(totLines).padStart(6), String(totCovered).padStart(6), ((100 * totCovered / totLines).toFixed(1) + '%').padStart(7));
Diagnostics6 git calls · 32 ms
CallStatusSizeTime032 ms
discover200191 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=11990
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=919
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:02005.6 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=22
git.response.bytes=5724
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=5724
git.pkt.payload.max=5697
git.sideband.band1.bytes=5697
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=5697
git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetch2001.6 KiB · hit22 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1636
git.response.cache=HIT
git.response.duration_ms=22
git.fetch.wants=6e6ff95121b6e640b1b21cd2d9ae0db95cfefe61
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1636
git.pkt.payload.max=1609
git.sideband.band1.bytes=1609
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e0f843be02332c
Request
eda06ea3…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format