parcel-bundler
Version:
Blazing fast, zero configuration web application bundler
122 lines (106 loc) • 2.55 kB
JavaScript
'use strict';
// some weird library written by sam
const ChromeTrace = require('chrome-trace-event').Tracer;
class Trace {
constructor() {
this.chromeTrace = new ChromeTrace({
// noStream: true,
});
this.tid = 0;
this.eventId = 0;
this.init();
}
getEventId() {
const id = this.eventId;
this.eventId++;
return id;
}
init() {
this.chromeTrace.instantEvent({
name: 'TracingStartedInPage',
id: this.getEventId(),
cat: ['disabled-by-default-devtools.timeline'],
args: {
data: {
sessionId: '-1',
page: '0xfff',
frames: [{
frame: '0xfff',
url: 'parcel',
name: ''
}]
}
}
});
this.chromeTrace.instantEvent({
name: 'TracingStartedInBrowser',
id: this.getEventId(),
cat: ['disabled-by-default-devtools.timeline'],
args: {
data: {
sessionId: '-1'
}
}
});
}
addCPUProfile(name, profile) {
const trace = this.chromeTrace;
const tid = this.tid;
this.tid++;
const cpuStartTime = profile.startTime;
const cpuEndTime = profile.endTime;
const common = {
pid: 8763,
tid
};
trace.instantEvent(Object.assign({}, common, {
id: this.getEventId(),
ph: 'X',
cat: ['toplevel'],
name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
args: {
src_file: '../../third_party/WebKit/Source/core/workers/DedicatedWorkerObjectProxy.cpp',
src_func: 'PostMessageToWorkerObject'
},
ts: cpuStartTime,
dur: cpuEndTime - cpuStartTime
}));
trace.completeEvent(Object.assign({}, common, {
name: 'EvaluateScript',
id: this.getEventId(),
cat: ['devtools.timeline'],
ts: cpuStartTime,
dur: cpuEndTime - cpuStartTime,
args: {
data: {
url: 'parcel',
lineNumber: 1,
columnNumber: 1,
frame: '0xFFF'
}
}
}));
trace.instantEvent(Object.assign({}, common, {
ts: 0,
ph: 'M',
cat: ['__metadata'],
name: 'thread_name',
args: { name }
}));
trace.instantEvent(Object.assign({}, common, {
name: 'CpuProfile',
id: this.getEventId(),
cat: ['disabled-by-default-devtools.timeline'],
ts: cpuEndTime,
args: {
data: {
cpuProfile: profile
}
}
}));
}
build() {
return this.chromeTrace.events;
}
}
module.exports = Trace;