1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const readline = require('readline');
|
13 |
|
14 | const rl = readline.createInterface({
|
15 | input: process.stdin,
|
16 | output: process.stdout,
|
17 | terminal: false,
|
18 | });
|
19 |
|
20 | const rows = [];
|
21 |
|
22 | rl.on('line', (line) => {
|
23 | const idx = line.indexOf(':');
|
24 | if (idx < 0) {
|
25 | return;
|
26 | }
|
27 | const name = line.substring(0, idx).toLowerCase();
|
28 | if (name !== 'server-timing') {
|
29 | return;
|
30 | }
|
31 | const timings = line.substring(idx + 1).trim().split(',');
|
32 | let row = null;
|
33 | timings.forEach((t) => {
|
34 | t = t.trim().split(';');
|
35 | const [, time] = t[1].split('=');
|
36 | if (t[0] === 'total' && rows.length > 0) {
|
37 | rows[rows.length - 1].total = time;
|
38 | } else {
|
39 | const [, desc] = t[2].split('=');
|
40 | if (!row) {
|
41 | row = {};
|
42 | rows.push(row);
|
43 | }
|
44 | row[desc] = time;
|
45 | }
|
46 | });
|
47 | });
|
48 |
|
49 | rl.on('close', () => {
|
50 | const out = process.stdout;
|
51 | let headers;
|
52 | rows.forEach((row, idx) => {
|
53 | if (idx === 0) {
|
54 | headers = Object.keys(row);
|
55 | headers.forEach((name) => {
|
56 | out.write(`${name}, `);
|
57 | });
|
58 | out.write('\n');
|
59 | }
|
60 | Object.values(row).forEach((value) => {
|
61 | out.write(`${value}, `);
|
62 | });
|
63 | out.write('\n');
|
64 | });
|
65 | });
|