-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathsize.js
More file actions
49 lines (44 loc) · 934 Bytes
/
size.js
File metadata and controls
49 lines (44 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require("fs");
// run "cmd" and capture the output
function run(cmd) {
return new Promise((resolve, reject) => {
require("child_process").exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
resolve(stdout.trim());
}
});
});
}
function fmt(perc) {
return perc.toFixed(2).padStart(6) + "%";
}
function gethd(o) {
return (
fmt(o.retained_size_percent) +
" " +
fmt(o.shallow_size_percent) +
" " +
o.name
);
}
function cchildren(o) {
const r = {};
(o.children ?? []).forEach((c) => {
r[gethd(c)] = cchildren(c);
});
return r;
}
async function main() {
const o = JSON.parse(
await run("twiggy dominators target/strip.wasm -f json")
);
o.root = cchildren({ name: "ROOT", children: o.items });
delete o.items;
fs.writeFileSync(
"target/dominators.json",
JSON.stringify(o, null, 2)
);
}
main();