UNPKG

972 BJavaScriptView Raw
1'use strict'
2
3const typeMap = new Map([
4 ['SCA', 'V8.GCScavenger'],
5 ['MSC', 'V8.GCMarkSweepCompact'],
6 ['NONE', null]
7])
8
9function generateTraceEvent (data) {
10 const output = []
11
12 let lastType = null
13 let startIndex = -1
14 for (let i = 0; i < data.length; i++) {
15 const type = typeMap.get(data[i])
16 if (lastType === null) {
17 // prepear next type
18 lastType = type
19 startIndex = i
20 } else if (type !== lastType) {
21 const startTimestamp = startIndex * 10
22 const endTimestamp = i * 10
23
24 output.push({
25 pid: 0,
26 tid: 0,
27 ts: startTimestamp * 1e3,
28 ph: 'X',
29 cat: 'v8',
30 name: lastType,
31 dur: (endTimestamp - startTimestamp) * 1e3,
32 args: {
33 startTimestamp: startTimestamp,
34 endTimestamp: endTimestamp
35 }
36 })
37
38 // prepear next type
39 lastType = type
40 startIndex = i
41 }
42 }
43
44 return output
45}
46
47module.exports = generateTraceEvent