-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhootToCsv.mjs
90 lines (83 loc) · 2.68 KB
/
hootToCsv.mjs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import fs from "fs";
import { exec } from "child_process";
// array of urls or ["label", "url"]
// run on a multi build page:
// [...$('.dropdown-item:contains(start_qunit_only)')].map(a => a.href)
const builds = [
"https://runbot250.odoo.com/runbot/static/build/73404418-master/logs/test_only.txt",
];
// Extract or not mobile test for the graph
const withMobile = false;
// Automatically open the graph view
const openGraphView = true;
// generate label if not provided
for (let i = 0; i < builds.length; i++) {
const build = builds[i];
if (!Array.isArray(build)) {
if (build.startsWith("https")) {
const re = /build\/(.*)\/logs/gm;
builds[i] = [re.exec(build)[1], build];
}
builds[i] = [build.split("/").at(-1), build]; //Sorry windows users
}
}
// fetch logs
await Promise.all(builds.map(([label, url]) => {
if (url.startsWith("https")) {
return new Promise((resolve) => {
exec(`wget -O ${label} ${url}`, resolve);
});
}
return new Promise((resolve) => {
exec(`cp ${url} ${label}`, resolve);
});
}));
// extract memory stats from build logs
const data = {};
for (const [label] of builds) {
data[label] = fs
.readFileSync(new URL(label, import.meta.url))
.toString()
.replace(/(^.*?\[MEMINFO\] @.*$\n)|(^.*$\n)/gm, "$1")
.replace(/[,"]/gm, "")
.replace(
/.*(\.MobileWebSuite|\.WebSuite).*: \[MEMINFO\] ([^ ]+) \(after GC\) - used: (\d+) - total: (\d+).*/gm,
"$2,$3,$4,$1"
)
.split("\n")
.map((line) => line.split(","))
.filter(([suite]) => suite);
}
// generate csv and json file
const res = [];
const jsonData = [];
res.push(builds.map(([label]) => [label, label]).flat().join(","));
let done = false;
let i = 0;
while (!done) {
const row = builds.map(([label]) => {
let suite = data[label][i]?.[0] || "";
const memory = data[label][i]?.[1] || ""; // [1]: used, [2]: total
const isMobile = data[label][i]?.[3] === ".MobileWebSuite";
if (isMobile) {
suite = `${suite} (mobile)`;
}
if (!isMobile || withMobile) {
let obj = jsonData.find((o) => o.suite === suite);
if (!obj) {
obj = { suite };
jsonData.push(obj);
}
obj[label] = memory;
}
return [suite, memory];
}).flat();
res.push(row.join(","));
i++;
done = row.every((cell) => cell === "");
}
fs.writeFileSync(new URL("data.csv", import.meta.url), res.join("\n"));
fs.writeFileSync(new URL("data.js", import.meta.url), `window.hootData = ${JSON.stringify(jsonData)}`);
if (openGraphView) {
exec("open index.html")
}