|
1 |
| -// @ts-check |
2 |
| -const fs = require("fs"); |
3 |
| -const git = require('simple-git/promise')('.') |
4 |
| -const readline = require('readline') |
5 |
| - |
6 |
| -/** @typedef {{ [s: string]: number}} Histogram */ |
7 |
| - |
8 |
| -async function main() { |
9 |
| - /** @type {Histogram} */ |
10 |
| - const edits = Object.create(null) |
11 |
| - /** @type {Histogram} */ |
12 |
| - const perf = JSON.parse(fs.readFileSync('.parallelperf.json', 'utf8')) |
13 |
| - |
14 |
| - await collectCommits(git, "release-2.3", "master", /*author*/ undefined, files => fillMap(files, edits)) |
15 |
| - |
16 |
| - const totalTime = Object.values(perf).reduce((n,m) => n + m, 0) |
17 |
| - const untouched = Object.values(perf).length - Object.values(edits).length |
18 |
| - const totalEdits = Object.values(edits).reduce((n,m) => n + m, 0) + untouched + Object.values(edits).length |
19 |
| - |
20 |
| - let i = 0 |
21 |
| - /** @type {{ name: string, time: number, edits: number, cost: number }[]} */ |
22 |
| - let data = [] |
23 |
| - for (const k in perf) { |
24 |
| - const otherk = k.replace(/tsrunner-[a-z-]+?:\/\//, '') |
25 |
| - const percentTime = perf[k] / totalTime |
26 |
| - const percentHits = (1 + (edits[otherk] || 0)) / totalEdits |
27 |
| - const cost = 5 + Math.log(percentTime / percentHits) |
28 |
| - data.push({ name: otherk, time: perf[k], edits: 1 + (edits[otherk] || 0), cost}) |
29 |
| - if (edits[otherk]) |
30 |
| - i++ |
31 |
| - } |
32 |
| - const output = { |
33 |
| - totalTime, |
34 |
| - totalEdits, |
35 |
| - data: data.sort((x,y) => y.cost - x.cost).map(x => ({ ...x, cost: x.cost.toFixed(2) })) |
36 |
| - } |
37 |
| - |
38 |
| - fs.writeFileSync('tests/.test-cost.json', JSON.stringify(output), 'utf8') |
39 |
| -} |
40 |
| - |
41 |
| -main().catch(e => { |
42 |
| - console.log(e); |
43 |
| - process.exit(1); |
44 |
| -}) |
45 |
| - |
46 |
| -/** |
47 |
| - * @param {string[]} files |
48 |
| - * @param {Histogram} histogram |
49 |
| - */ |
50 |
| -function fillMap(files, histogram) { |
51 |
| - // keep edits to test cases (but not /users), and not file moves |
52 |
| - const tests = files.filter(f => f.startsWith('tests/cases/') && !f.startsWith('tests/cases/user') && !/=>/.test(f)) |
53 |
| - for (const test of tests) { |
54 |
| - histogram[test] = (histogram[test] || 0) + 1 |
55 |
| - } |
56 |
| -} |
57 |
| - |
58 |
| -/** |
59 |
| - * @param {string} s |
60 |
| - */ |
61 |
| -function isSquashMergeMessage(s) { |
62 |
| - return /\(#[0-9]+\)$/.test(s) |
63 |
| -} |
64 |
| - |
65 |
| -/** |
66 |
| - * @param {string} s |
67 |
| - */ |
68 |
| -function isMergeCommit(s) { |
69 |
| - return /Merge pull request #[0-9]+/.test(s) |
70 |
| -} |
71 |
| - |
72 |
| -/** |
73 |
| - * @param {string} s |
74 |
| - */ |
75 |
| -function parseFiles(s) { |
76 |
| - const lines = s.split('\n') |
77 |
| - // Note that slice(2) only works for merge commits, which have an empty newline after the title |
78 |
| - return lines.slice(2, lines.length - 2).map(line => line.split("|")[0].trim()) |
79 |
| -} |
80 |
| - |
81 |
| -/** |
82 |
| - * @param {import('simple-git/promise').SimpleGit} git |
83 |
| - * @param {string} from |
84 |
| - * @param {string} to |
85 |
| - * @param {string | undefined} author - only include commits from this author |
86 |
| - * @param {(files: string[]) => void} update |
87 |
| - */ |
88 |
| - async function collectCommits(git, from, to, author, update) { |
89 |
| - let i = 0 |
90 |
| - for (const commit of (await git.log({ from, to })).all) { |
91 |
| - i++ |
92 |
| - if ((!author || commit.author_name === author) && isMergeCommit(commit.message) || isSquashMergeMessage(commit.message)) { |
93 |
| - readline.clearLine(process.stdout, /*left*/ -1) |
94 |
| - readline.cursorTo(process.stdout, 0) |
95 |
| - process.stdout.write(i + ": " + commit.date) |
96 |
| - const files = parseFiles(await git.show([commit.hash, "--stat=1000,960,40", "--pretty=oneline"])) |
97 |
| - update(files) |
98 |
| - } |
99 |
| - } |
100 |
| -} |
101 |
| - |
102 |
| - |
103 |
| - |
| 1 | +// @ts-check |
| 2 | +const fs = require("fs"); |
| 3 | +const git = require('simple-git/promise')('.') |
| 4 | +const readline = require('readline') |
| 5 | + |
| 6 | +/** @typedef {{ [s: string]: number}} Histogram */ |
| 7 | + |
| 8 | +async function main() { |
| 9 | + /** @type {Histogram} */ |
| 10 | + const edits = Object.create(null) |
| 11 | + /** @type {Histogram} */ |
| 12 | + const perf = JSON.parse(fs.readFileSync('.parallelperf.json', 'utf8')) |
| 13 | + |
| 14 | + await collectCommits(git, "release-2.3", "master", /*author*/ undefined, files => fillMap(files, edits)) |
| 15 | + |
| 16 | + const totalTime = Object.values(perf).reduce((n,m) => n + m, 0) |
| 17 | + const untouched = Object.values(perf).length - Object.values(edits).length |
| 18 | + const totalEdits = Object.values(edits).reduce((n,m) => n + m, 0) + untouched + Object.values(edits).length |
| 19 | + |
| 20 | + let i = 0 |
| 21 | + /** @type {{ name: string, time: number, edits: number, cost: number }[]} */ |
| 22 | + let data = [] |
| 23 | + for (const k in perf) { |
| 24 | + const otherk = k.replace(/tsrunner-[a-z-]+?:\/\//, '') |
| 25 | + const percentTime = perf[k] / totalTime |
| 26 | + const percentHits = (1 + (edits[otherk] || 0)) / totalEdits |
| 27 | + const cost = 5 + Math.log(percentTime / percentHits) |
| 28 | + data.push({ name: otherk, time: perf[k], edits: 1 + (edits[otherk] || 0), cost}) |
| 29 | + if (edits[otherk]) |
| 30 | + i++ |
| 31 | + } |
| 32 | + const output = { |
| 33 | + totalTime, |
| 34 | + totalEdits, |
| 35 | + data: data.sort((x,y) => y.cost - x.cost).map(x => ({ ...x, cost: x.cost.toFixed(2) })) |
| 36 | + } |
| 37 | + |
| 38 | + fs.writeFileSync('tests/.test-cost.json', JSON.stringify(output), 'utf8') |
| 39 | +} |
| 40 | + |
| 41 | +main().catch(e => { |
| 42 | + console.log(e); |
| 43 | + process.exit(1); |
| 44 | +}) |
| 45 | + |
| 46 | +/** |
| 47 | + * @param {string[]} files |
| 48 | + * @param {Histogram} histogram |
| 49 | + */ |
| 50 | +function fillMap(files, histogram) { |
| 51 | + // keep edits to test cases (but not /users), and not file moves |
| 52 | + const tests = files.filter(f => f.startsWith('tests/cases/') && !f.startsWith('tests/cases/user') && !/=>/.test(f)) |
| 53 | + for (const test of tests) { |
| 54 | + histogram[test] = (histogram[test] || 0) + 1 |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * @param {string} s |
| 60 | + */ |
| 61 | +function isSquashMergeMessage(s) { |
| 62 | + return /\(#[0-9]+\)$/.test(s) |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * @param {string} s |
| 67 | + */ |
| 68 | +function isMergeCommit(s) { |
| 69 | + return /Merge pull request #[0-9]+/.test(s) |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * @param {string} s |
| 74 | + */ |
| 75 | +function parseFiles(s) { |
| 76 | + const lines = s.split('\n') |
| 77 | + // Note that slice(2) only works for merge commits, which have an empty newline after the title |
| 78 | + return lines.slice(2, lines.length - 2).map(line => line.split("|")[0].trim()) |
| 79 | +} |
| 80 | + |
| 81 | +/** |
| 82 | + * @param {import('simple-git/promise').SimpleGit} git |
| 83 | + * @param {string} from |
| 84 | + * @param {string} to |
| 85 | + * @param {string | undefined} author - only include commits from this author |
| 86 | + * @param {(files: string[]) => void} update |
| 87 | + */ |
| 88 | + async function collectCommits(git, from, to, author, update) { |
| 89 | + let i = 0 |
| 90 | + for (const commit of (await git.log({ from, to })).all) { |
| 91 | + i++ |
| 92 | + if ((!author || commit.author_name === author) && isMergeCommit(commit.message) || isSquashMergeMessage(commit.message)) { |
| 93 | + readline.clearLine(process.stdout, /*left*/ -1) |
| 94 | + readline.cursorTo(process.stdout, 0) |
| 95 | + process.stdout.write(i + ": " + commit.date) |
| 96 | + const files = parseFiles(await git.show([commit.hash, "--stat=1000,960,40", "--pretty=oneline"])) |
| 97 | + update(files) |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +
|
0 commit comments