forked from timotejroiko/zlib-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.js
More file actions
37 lines (28 loc) · 1.02 KB
/
parse.js
File metadata and controls
37 lines (28 loc) · 1.02 KB
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
const fs = require('fs')
function parseLogfile(path) {
const data = fs.readFileSync(path, 'utf8')
const events = {}
for (let line of data.split('\n')) {
line = line.trim()
if (!line) continue
const match = line.match(/^(?<type>[^,]+), (?:size=(?<size>\d+)|packed_size=(?<packed_size>\d+),? unpacked_size=(?<unpacked_size>\d+))/)
if (!match) {
console.error(`Failed to parse line: ${line}`)
continue
}
const { type, size, packed_size, unpacked_size } = match.groups
if (type === 'inflate') {
if (!events.inflate) {
events.inflate = []
events.inflateRatio = []
}
events.inflate.push(Number(packed_size))
events.inflateRatio.push(Number(packed_size) / Number(unpacked_size))
} else {
if (!events[type]) events[type] = []
events[type].push(Number(size))
}
}
return events
}
module.exports = { parseLogfile }