UNPKG

2.55 kBJavaScriptView Raw
1'use strict';
2
3// some weird library written by sam
4const ChromeTrace = require('chrome-trace-event').Tracer;
5
6class Trace {
7 constructor() {
8 this.chromeTrace = new ChromeTrace({
9 // noStream: true,
10 });
11
12 this.tid = 0;
13 this.eventId = 0;
14
15 this.init();
16 }
17
18 getEventId() {
19 const id = this.eventId;
20 this.eventId++;
21 return id;
22 }
23
24 init() {
25 this.chromeTrace.instantEvent({
26 name: 'TracingStartedInPage',
27 id: this.getEventId(),
28 cat: ['disabled-by-default-devtools.timeline'],
29 args: {
30 data: {
31 sessionId: '-1',
32 page: '0xfff',
33 frames: [{
34 frame: '0xfff',
35 url: 'parcel',
36 name: ''
37 }]
38 }
39 }
40 });
41
42 this.chromeTrace.instantEvent({
43 name: 'TracingStartedInBrowser',
44 id: this.getEventId(),
45 cat: ['disabled-by-default-devtools.timeline'],
46 args: {
47 data: {
48 sessionId: '-1'
49 }
50 }
51 });
52 }
53
54 addCPUProfile(name, profile) {
55 const trace = this.chromeTrace;
56 const tid = this.tid;
57 this.tid++;
58
59 const cpuStartTime = profile.startTime;
60 const cpuEndTime = profile.endTime;
61
62 const common = {
63 pid: 8763,
64 tid
65 };
66
67 trace.instantEvent(Object.assign({}, common, {
68 id: this.getEventId(),
69 ph: 'X',
70 cat: ['toplevel'],
71 name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
72 args: {
73 src_file: '../../third_party/WebKit/Source/core/workers/DedicatedWorkerObjectProxy.cpp',
74 src_func: 'PostMessageToWorkerObject'
75 },
76 ts: cpuStartTime,
77 dur: cpuEndTime - cpuStartTime
78 }));
79
80 trace.completeEvent(Object.assign({}, common, {
81 name: 'EvaluateScript',
82 id: this.getEventId(),
83 cat: ['devtools.timeline'],
84 ts: cpuStartTime,
85 dur: cpuEndTime - cpuStartTime,
86 args: {
87 data: {
88 url: 'parcel',
89 lineNumber: 1,
90 columnNumber: 1,
91 frame: '0xFFF'
92 }
93 }
94 }));
95
96 trace.instantEvent(Object.assign({}, common, {
97 ts: 0,
98 ph: 'M',
99 cat: ['__metadata'],
100 name: 'thread_name',
101 args: { name }
102 }));
103
104 trace.instantEvent(Object.assign({}, common, {
105 name: 'CpuProfile',
106 id: this.getEventId(),
107 cat: ['disabled-by-default-devtools.timeline'],
108 ts: cpuEndTime,
109 args: {
110 data: {
111 cpuProfile: profile
112 }
113 }
114 }));
115 }
116
117 build() {
118 return this.chromeTrace.events;
119 }
120}
121
122module.exports = Trace;
\No newline at end of file