@parcel/workers 2.0.0-nightly.1298 → 2.0.0-nightly.1303
Sign up to get free protection for your applications and to get access to all the features.
- package/index.d.ts +10 -9
- package/lib/Worker.js +2 -1
- package/lib/WorkerFarm.js +11 -4
- package/lib/child.js +19 -2
- package/lib/index.js +15 -0
- package/package.json +8 -8
- package/src/Worker.js +2 -0
- package/src/WorkerFarm.js +5 -4
- package/src/child.js +13 -3
- package/src/index.js +7 -1
- package/lib/Profiler.js +0 -80
- package/lib/Trace.js +0 -131
- package/src/Profiler.js +0 -93
- package/src/Trace.js +0 -125
package/index.d.ts
CHANGED
@@ -3,14 +3,15 @@ import {FilePath} from '@parcel/types';
|
|
3
3
|
type BackendType = 'process' | 'threads';
|
4
4
|
|
5
5
|
export type FarmOptions = {
|
6
|
-
maxConcurrentWorkers: number
|
7
|
-
maxConcurrentCallsPerWorker: number
|
8
|
-
forcedKillTime: number
|
9
|
-
useLocalWorker: boolean
|
10
|
-
warmWorkers: boolean
|
11
|
-
workerPath?: FilePath
|
12
|
-
backend: BackendType
|
13
|
-
shouldPatchConsole?: boolean
|
6
|
+
maxConcurrentWorkers: number;
|
7
|
+
maxConcurrentCallsPerWorker: number;
|
8
|
+
forcedKillTime: number;
|
9
|
+
useLocalWorker: boolean;
|
10
|
+
warmWorkers: boolean;
|
11
|
+
workerPath?: FilePath;
|
12
|
+
backend: BackendType;
|
13
|
+
shouldPatchConsole?: boolean;
|
14
|
+
shouldTrace?: boolean;
|
14
15
|
};
|
15
16
|
|
16
17
|
declare class WorkerFarm {
|
@@ -19,4 +20,4 @@ declare class WorkerFarm {
|
|
19
20
|
end(): Promise<void>;
|
20
21
|
}
|
21
22
|
|
22
|
-
export default WorkerFarm;
|
23
|
+
export default WorkerFarm;
|
package/lib/Worker.js
CHANGED
@@ -107,7 +107,8 @@ class Worker extends _events().default {
|
|
107
107
|
this.call({
|
108
108
|
method: 'childInit',
|
109
109
|
args: [forkModule, {
|
110
|
-
shouldPatchConsole: !!this.options.shouldPatchConsole
|
110
|
+
shouldPatchConsole: !!this.options.shouldPatchConsole,
|
111
|
+
shouldTrace: !!this.options.shouldTrace
|
111
112
|
}],
|
112
113
|
retries: 0,
|
113
114
|
skipReadyCheck: true,
|
package/lib/WorkerFarm.js
CHANGED
@@ -71,9 +71,15 @@ var _childState = require("./childState");
|
|
71
71
|
|
72
72
|
var _backend = require("./backend");
|
73
73
|
|
74
|
-
|
74
|
+
function _profiler() {
|
75
|
+
const data = require("@parcel/profiler");
|
75
76
|
|
76
|
-
|
77
|
+
_profiler = function () {
|
78
|
+
return data;
|
79
|
+
};
|
80
|
+
|
81
|
+
return data;
|
82
|
+
}
|
77
83
|
|
78
84
|
function _fs() {
|
79
85
|
const data = _interopRequireDefault(require("fs"));
|
@@ -247,6 +253,7 @@ class WorkerFarm extends _events().default {
|
|
247
253
|
forcedKillTime: this.options.forcedKillTime,
|
248
254
|
backend: this.options.backend,
|
249
255
|
shouldPatchConsole: this.options.shouldPatchConsole,
|
256
|
+
shouldTrace: this.options.shouldTrace,
|
250
257
|
sharedReferences: this.sharedReferences
|
251
258
|
});
|
252
259
|
worker.fork((0, _nullthrows().default)(this.options.workerPath));
|
@@ -512,7 +519,7 @@ class WorkerFarm extends _events().default {
|
|
512
519
|
}));
|
513
520
|
}
|
514
521
|
|
515
|
-
this.profiler = new
|
522
|
+
this.profiler = new (_profiler().SamplingProfiler)();
|
516
523
|
promises.push(this.profiler.startProfiling());
|
517
524
|
await Promise.all(promises);
|
518
525
|
}
|
@@ -540,7 +547,7 @@ class WorkerFarm extends _events().default {
|
|
540
547
|
}
|
541
548
|
|
542
549
|
var profiles = await Promise.all(promises);
|
543
|
-
let trace = new
|
550
|
+
let trace = new (_profiler().Trace)();
|
544
551
|
let filename = `profile-${getTimeId()}.trace`;
|
545
552
|
let stream = trace.pipe(_fs().default.createWriteStream(filename));
|
546
553
|
|
package/lib/child.js
CHANGED
@@ -57,7 +57,15 @@ function _core() {
|
|
57
57
|
|
58
58
|
var _bus = _interopRequireDefault(require("./bus"));
|
59
59
|
|
60
|
-
|
60
|
+
function _profiler() {
|
61
|
+
const data = require("@parcel/profiler");
|
62
|
+
|
63
|
+
_profiler = function () {
|
64
|
+
return data;
|
65
|
+
};
|
66
|
+
|
67
|
+
return data;
|
68
|
+
}
|
61
69
|
|
62
70
|
var _Handle2 = _interopRequireDefault(require("./Handle"));
|
63
71
|
|
@@ -87,6 +95,10 @@ class Child {
|
|
87
95
|
|
88
96
|
this.loggerDisposable = _logger().default.onLog(event => {
|
89
97
|
_bus.default.emit('logEvent', event);
|
98
|
+
}); // .. and do the same for trace events
|
99
|
+
|
100
|
+
this.tracerDisposable = _profiler().tracer.onTrace(event => {
|
101
|
+
_bus.default.emit('traceEvent', event);
|
90
102
|
});
|
91
103
|
}
|
92
104
|
|
@@ -169,12 +181,16 @@ class Child {
|
|
169
181
|
(0, _logger().unpatchConsole)();
|
170
182
|
}
|
171
183
|
|
184
|
+
if (childOptions.shouldTrace) {
|
185
|
+
_profiler().tracer.enable();
|
186
|
+
}
|
187
|
+
|
172
188
|
result = responseFromContent(await this.childInit(moduleName, child));
|
173
189
|
} catch (e) {
|
174
190
|
result = errorResponseFromError(e);
|
175
191
|
}
|
176
192
|
} else if (method === 'startProfile') {
|
177
|
-
this.profiler = new
|
193
|
+
this.profiler = new (_profiler().SamplingProfiler)();
|
178
194
|
|
179
195
|
try {
|
180
196
|
result = responseFromContent(await this.profiler.startProfiling());
|
@@ -305,6 +321,7 @@ class Child {
|
|
305
321
|
|
306
322
|
handleEnd() {
|
307
323
|
this.loggerDisposable.dispose();
|
324
|
+
this.tracerDisposable.dispose();
|
308
325
|
}
|
309
326
|
|
310
327
|
createReverseHandle(fn) {
|
package/lib/index.js
CHANGED
@@ -41,6 +41,16 @@ function _logger() {
|
|
41
41
|
|
42
42
|
var _bus = _interopRequireDefault(require("./bus"));
|
43
43
|
|
44
|
+
function _profiler() {
|
45
|
+
const data = require("@parcel/profiler");
|
46
|
+
|
47
|
+
_profiler = function () {
|
48
|
+
return data;
|
49
|
+
};
|
50
|
+
|
51
|
+
return data;
|
52
|
+
}
|
53
|
+
|
44
54
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
45
55
|
|
46
56
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -81,6 +91,11 @@ if (!_WorkerFarm.default.isWorker()) {
|
|
81
91
|
default:
|
82
92
|
throw new Error('Unknown log level');
|
83
93
|
}
|
94
|
+
}); // Forward all trace events originating from workers into the main process
|
95
|
+
|
96
|
+
|
97
|
+
_bus.default.on('traceEvent', e => {
|
98
|
+
_profiler().tracer.trace(e);
|
84
99
|
});
|
85
100
|
}
|
86
101
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/workers",
|
3
|
-
"version": "2.0.0-nightly.
|
3
|
+
"version": "2.0.0-nightly.1303+cd4336412",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
@@ -21,20 +21,20 @@
|
|
21
21
|
"node": ">= 12.0.0"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
-
"@parcel/diagnostic": "2.0.0-nightly.
|
25
|
-
"@parcel/logger": "2.0.0-nightly.
|
26
|
-
"@parcel/
|
27
|
-
"@parcel/
|
28
|
-
"
|
24
|
+
"@parcel/diagnostic": "2.0.0-nightly.1303+cd4336412",
|
25
|
+
"@parcel/logger": "2.0.0-nightly.1303+cd4336412",
|
26
|
+
"@parcel/profiler": "2.8.4-nightly.2926+cd4336412",
|
27
|
+
"@parcel/types": "2.0.0-nightly.1303+cd4336412",
|
28
|
+
"@parcel/utils": "2.0.0-nightly.1303+cd4336412",
|
29
29
|
"nullthrows": "^1.1.1"
|
30
30
|
},
|
31
31
|
"peerDependencies": {
|
32
|
-
"@parcel/core": "2.0.0-nightly.
|
32
|
+
"@parcel/core": "2.0.0-nightly.1301+cd4336412"
|
33
33
|
},
|
34
34
|
"browser": {
|
35
35
|
"./src/cpuCount.js": false,
|
36
36
|
"./src/process/ProcessWorker.js": false,
|
37
37
|
"./src/threads/ThreadsWorker.js": false
|
38
38
|
},
|
39
|
-
"gitHead": "
|
39
|
+
"gitHead": "cd4336412242b6d6da40ef6cba8e7ac99c72b090"
|
40
40
|
}
|
package/src/Worker.js
CHANGED
@@ -23,6 +23,7 @@ type WorkerOpts = {|
|
|
23
23
|
forcedKillTime: number,
|
24
24
|
backend: BackendType,
|
25
25
|
shouldPatchConsole?: boolean,
|
26
|
+
shouldTrace?: boolean,
|
26
27
|
sharedReferences: $ReadOnlyMap<SharedReference, mixed>,
|
27
28
|
|};
|
28
29
|
|
@@ -108,6 +109,7 @@ export default class Worker extends EventEmitter {
|
|
108
109
|
forkModule,
|
109
110
|
{
|
110
111
|
shouldPatchConsole: !!this.options.shouldPatchConsole,
|
112
|
+
shouldTrace: !!this.options.shouldTrace,
|
111
113
|
},
|
112
114
|
],
|
113
115
|
retries: 0,
|
package/src/WorkerFarm.js
CHANGED
@@ -26,8 +26,7 @@ import cpuCount from './cpuCount';
|
|
26
26
|
import Handle from './Handle';
|
27
27
|
import {child} from './childState';
|
28
28
|
import {detectBackend} from './backend';
|
29
|
-
import
|
30
|
-
import Trace from './Trace';
|
29
|
+
import {SamplingProfiler, Trace} from '@parcel/profiler';
|
31
30
|
import fs from 'fs';
|
32
31
|
import logger from '@parcel/logger';
|
33
32
|
|
@@ -44,6 +43,7 @@ export type FarmOptions = {|
|
|
44
43
|
workerPath?: FilePath,
|
45
44
|
backend: BackendType,
|
46
45
|
shouldPatchConsole?: boolean,
|
46
|
+
shouldTrace?: boolean,
|
47
47
|
|};
|
48
48
|
|
49
49
|
type WorkerModule = {|
|
@@ -77,7 +77,7 @@ export default class WorkerFarm extends EventEmitter {
|
|
77
77
|
sharedReferences: Map<SharedReference, mixed> = new Map();
|
78
78
|
sharedReferencesByValue: Map<mixed, SharedReference> = new Map();
|
79
79
|
serializedSharedReferences: Map<SharedReference, ?ArrayBuffer> = new Map();
|
80
|
-
profiler: ?
|
80
|
+
profiler: ?SamplingProfiler;
|
81
81
|
|
82
82
|
constructor(farmOptions: $Shape<FarmOptions> = {}) {
|
83
83
|
super();
|
@@ -239,6 +239,7 @@ export default class WorkerFarm extends EventEmitter {
|
|
239
239
|
forcedKillTime: this.options.forcedKillTime,
|
240
240
|
backend: this.options.backend,
|
241
241
|
shouldPatchConsole: this.options.shouldPatchConsole,
|
242
|
+
shouldTrace: this.options.shouldTrace,
|
242
243
|
sharedReferences: this.sharedReferences,
|
243
244
|
});
|
244
245
|
|
@@ -516,7 +517,7 @@ export default class WorkerFarm extends EventEmitter {
|
|
516
517
|
);
|
517
518
|
}
|
518
519
|
|
519
|
-
this.profiler = new
|
520
|
+
this.profiler = new SamplingProfiler();
|
520
521
|
|
521
522
|
promises.push(this.profiler.startProfiling());
|
522
523
|
await Promise.all(promises);
|
package/src/child.js
CHANGED
@@ -18,7 +18,7 @@ import Logger, {patchConsole, unpatchConsole} from '@parcel/logger';
|
|
18
18
|
import ThrowableDiagnostic, {anyToDiagnostic} from '@parcel/diagnostic';
|
19
19
|
import {deserialize} from '@parcel/core';
|
20
20
|
import bus from './bus';
|
21
|
-
import
|
21
|
+
import {SamplingProfiler, tracer} from '@parcel/profiler';
|
22
22
|
import _Handle from './Handle';
|
23
23
|
|
24
24
|
// The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
|
@@ -37,8 +37,9 @@ export class Child {
|
|
37
37
|
responseId: number = 0;
|
38
38
|
responseQueue: Map<number, ChildCall> = new Map();
|
39
39
|
loggerDisposable: IDisposable;
|
40
|
+
tracerDisposable: IDisposable;
|
40
41
|
child: ChildImpl;
|
41
|
-
profiler: ?
|
42
|
+
profiler: ?SamplingProfiler;
|
42
43
|
handles: Map<number, Handle> = new Map();
|
43
44
|
sharedReferences: Map<SharedReference, mixed> = new Map();
|
44
45
|
sharedReferencesByValue: Map<mixed, SharedReference> = new Map();
|
@@ -56,6 +57,10 @@ export class Child {
|
|
56
57
|
this.loggerDisposable = Logger.onLog(event => {
|
57
58
|
bus.emit('logEvent', event);
|
58
59
|
});
|
60
|
+
// .. and do the same for trace events
|
61
|
+
this.tracerDisposable = tracer.onTrace(event => {
|
62
|
+
bus.emit('traceEvent', event);
|
63
|
+
});
|
59
64
|
}
|
60
65
|
|
61
66
|
workerApi: {|
|
@@ -141,12 +146,16 @@ export class Child {
|
|
141
146
|
unpatchConsole();
|
142
147
|
}
|
143
148
|
|
149
|
+
if (childOptions.shouldTrace) {
|
150
|
+
tracer.enable();
|
151
|
+
}
|
152
|
+
|
144
153
|
result = responseFromContent(await this.childInit(moduleName, child));
|
145
154
|
} catch (e) {
|
146
155
|
result = errorResponseFromError(e);
|
147
156
|
}
|
148
157
|
} else if (method === 'startProfile') {
|
149
|
-
this.profiler = new
|
158
|
+
this.profiler = new SamplingProfiler();
|
150
159
|
try {
|
151
160
|
result = responseFromContent(await this.profiler.startProfiling());
|
152
161
|
} catch (e) {
|
@@ -289,6 +298,7 @@ export class Child {
|
|
289
298
|
|
290
299
|
handleEnd(): void {
|
291
300
|
this.loggerDisposable.dispose();
|
301
|
+
this.tracerDisposable.dispose();
|
292
302
|
}
|
293
303
|
|
294
304
|
createReverseHandle(fn: (...args: Array<any>) => mixed): Handle {
|
package/src/index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
// @flow
|
2
|
-
import type {LogEvent} from '@parcel/types';
|
2
|
+
import type {TraceEvent, LogEvent} from '@parcel/types';
|
3
3
|
import invariant from 'assert';
|
4
4
|
import WorkerFarm from './WorkerFarm';
|
5
5
|
import Logger from '@parcel/logger';
|
6
6
|
import bus from './bus';
|
7
|
+
import {tracer} from '@parcel/profiler';
|
7
8
|
|
8
9
|
if (!WorkerFarm.isWorker()) {
|
9
10
|
// Forward all logger events originating from workers into the main process
|
@@ -29,6 +30,11 @@ if (!WorkerFarm.isWorker()) {
|
|
29
30
|
throw new Error('Unknown log level');
|
30
31
|
}
|
31
32
|
});
|
33
|
+
|
34
|
+
// Forward all trace events originating from workers into the main process
|
35
|
+
bus.on('traceEvent', (e: TraceEvent) => {
|
36
|
+
tracer.trace(e);
|
37
|
+
});
|
32
38
|
}
|
33
39
|
|
34
40
|
export default WorkerFarm;
|
package/lib/Profiler.js
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
function _assert() {
|
9
|
-
const data = _interopRequireDefault(require("assert"));
|
10
|
-
|
11
|
-
_assert = function () {
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
17
|
-
|
18
|
-
function _diagnostic() {
|
19
|
-
const data = _interopRequireDefault(require("@parcel/diagnostic"));
|
20
|
-
|
21
|
-
_diagnostic = function () {
|
22
|
-
return data;
|
23
|
-
};
|
24
|
-
|
25
|
-
return data;
|
26
|
-
}
|
27
|
-
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
|
-
|
30
|
-
class Profiler {
|
31
|
-
startProfiling() {
|
32
|
-
let inspector;
|
33
|
-
|
34
|
-
try {
|
35
|
-
inspector = require('inspector');
|
36
|
-
} catch (err) {
|
37
|
-
throw new (_diagnostic().default)({
|
38
|
-
diagnostic: {
|
39
|
-
message: `The inspector module isn't available`,
|
40
|
-
origin: '@parcel/workers',
|
41
|
-
hints: ['Disable build profiling']
|
42
|
-
}
|
43
|
-
});
|
44
|
-
}
|
45
|
-
|
46
|
-
this.session = new inspector.Session();
|
47
|
-
this.session.connect();
|
48
|
-
return Promise.all([this.sendCommand('Profiler.setSamplingInterval', {
|
49
|
-
interval: 100
|
50
|
-
}), this.sendCommand('Profiler.enable'), this.sendCommand('Profiler.start')]);
|
51
|
-
}
|
52
|
-
|
53
|
-
sendCommand(method, params) {
|
54
|
-
(0, _assert().default)(this.session != null);
|
55
|
-
return new Promise((resolve, reject) => {
|
56
|
-
this.session.post(method, params, (err, params) => {
|
57
|
-
if (err == null) {
|
58
|
-
resolve(params);
|
59
|
-
} else {
|
60
|
-
reject(err);
|
61
|
-
}
|
62
|
-
});
|
63
|
-
});
|
64
|
-
}
|
65
|
-
|
66
|
-
destroy() {
|
67
|
-
if (this.session != null) {
|
68
|
-
this.session.disconnect();
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
async stopProfiling() {
|
73
|
-
let res = await this.sendCommand('Profiler.stop');
|
74
|
-
this.destroy();
|
75
|
-
return res.profile;
|
76
|
-
}
|
77
|
-
|
78
|
-
}
|
79
|
-
|
80
|
-
exports.default = Profiler;
|
package/lib/Trace.js
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
|
8
|
-
function _chromeTraceEvent() {
|
9
|
-
const data = require("chrome-trace-event");
|
10
|
-
|
11
|
-
_chromeTraceEvent = function () {
|
12
|
-
return data;
|
13
|
-
};
|
14
|
-
|
15
|
-
return data;
|
16
|
-
}
|
17
|
-
|
18
|
-
class Trace {
|
19
|
-
constructor() {
|
20
|
-
this.tracer = new (_chromeTraceEvent().Tracer)();
|
21
|
-
this.tid = 0;
|
22
|
-
this.eventId = 0;
|
23
|
-
}
|
24
|
-
|
25
|
-
getEventId() {
|
26
|
-
return this.eventId++;
|
27
|
-
}
|
28
|
-
|
29
|
-
init(ts) {
|
30
|
-
this.tracer.instantEvent({
|
31
|
-
name: 'TracingStartedInPage',
|
32
|
-
id: this.getEventId(),
|
33
|
-
ts,
|
34
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
35
|
-
args: {
|
36
|
-
data: {
|
37
|
-
sessionId: '-1',
|
38
|
-
page: '0xfff',
|
39
|
-
frames: [{
|
40
|
-
frame: '0xfff',
|
41
|
-
url: 'parcel',
|
42
|
-
name: ''
|
43
|
-
}]
|
44
|
-
}
|
45
|
-
}
|
46
|
-
});
|
47
|
-
this.tracer.instantEvent({
|
48
|
-
name: 'TracingStartedInBrowser',
|
49
|
-
id: this.getEventId(),
|
50
|
-
ts,
|
51
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
52
|
-
args: {
|
53
|
-
data: {
|
54
|
-
sessionId: '-1'
|
55
|
-
}
|
56
|
-
}
|
57
|
-
});
|
58
|
-
}
|
59
|
-
|
60
|
-
addCPUProfile(name, profile) {
|
61
|
-
if (this.eventId === 0) {
|
62
|
-
this.init(profile.startTime);
|
63
|
-
}
|
64
|
-
|
65
|
-
const trace = this.tracer;
|
66
|
-
const tid = this.tid;
|
67
|
-
this.tid++;
|
68
|
-
const cpuStartTime = profile.startTime;
|
69
|
-
const cpuEndTime = profile.endTime;
|
70
|
-
trace.instantEvent({
|
71
|
-
tid,
|
72
|
-
id: this.getEventId(),
|
73
|
-
cat: ['toplevel'],
|
74
|
-
name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
|
75
|
-
args: {
|
76
|
-
src_file: '../../ipc/ipc_moji_bootstrap.cc',
|
77
|
-
src_func: 'Accept'
|
78
|
-
},
|
79
|
-
ts: cpuStartTime
|
80
|
-
});
|
81
|
-
trace.completeEvent({
|
82
|
-
tid,
|
83
|
-
name: 'EvaluateScript',
|
84
|
-
id: this.getEventId(),
|
85
|
-
cat: ['devtools.timeline'],
|
86
|
-
ts: cpuStartTime,
|
87
|
-
dur: cpuEndTime - cpuStartTime,
|
88
|
-
args: {
|
89
|
-
data: {
|
90
|
-
url: 'parcel',
|
91
|
-
lineNumber: 1,
|
92
|
-
columnNumber: 1,
|
93
|
-
frame: '0xFFF'
|
94
|
-
}
|
95
|
-
}
|
96
|
-
});
|
97
|
-
trace.instantEvent({
|
98
|
-
tid,
|
99
|
-
ts: 0,
|
100
|
-
ph: 'M',
|
101
|
-
cat: ['__metadata'],
|
102
|
-
name: 'thread_name',
|
103
|
-
args: {
|
104
|
-
name
|
105
|
-
}
|
106
|
-
});
|
107
|
-
trace.instantEvent({
|
108
|
-
tid,
|
109
|
-
name: 'CpuProfile',
|
110
|
-
id: this.getEventId(),
|
111
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
112
|
-
ts: cpuEndTime,
|
113
|
-
args: {
|
114
|
-
data: {
|
115
|
-
cpuProfile: profile
|
116
|
-
}
|
117
|
-
}
|
118
|
-
});
|
119
|
-
}
|
120
|
-
|
121
|
-
pipe(writable) {
|
122
|
-
return this.tracer.pipe(writable);
|
123
|
-
}
|
124
|
-
|
125
|
-
flush() {
|
126
|
-
this.tracer.push(null);
|
127
|
-
}
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
exports.default = Trace;
|
package/src/Profiler.js
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
// @flow
|
2
|
-
import type {Session} from 'inspector';
|
3
|
-
import invariant from 'assert';
|
4
|
-
import ThrowableDiagnostic from '@parcel/diagnostic';
|
5
|
-
|
6
|
-
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
|
7
|
-
export type Profile = {|
|
8
|
-
nodes: Array<ProfileNode>,
|
9
|
-
startTime: number,
|
10
|
-
endTime: number,
|
11
|
-
samples?: Array<number>,
|
12
|
-
timeDeltas?: Array<number>,
|
13
|
-
|};
|
14
|
-
|
15
|
-
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
|
16
|
-
type ProfileNode = {|
|
17
|
-
id: number,
|
18
|
-
callFrame: CallFrame,
|
19
|
-
hitCount?: number,
|
20
|
-
children?: Array<number>,
|
21
|
-
deoptReason?: string,
|
22
|
-
positionTicks?: PositionTickInfo,
|
23
|
-
|};
|
24
|
-
|
25
|
-
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
|
26
|
-
type CallFrame = {|
|
27
|
-
functionName: string,
|
28
|
-
scriptId: string,
|
29
|
-
url: string,
|
30
|
-
lineNumber: string,
|
31
|
-
columnNumber: string,
|
32
|
-
|};
|
33
|
-
|
34
|
-
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
|
35
|
-
type PositionTickInfo = {|
|
36
|
-
line: number,
|
37
|
-
ticks: number,
|
38
|
-
|};
|
39
|
-
|
40
|
-
export default class Profiler {
|
41
|
-
session: Session;
|
42
|
-
|
43
|
-
startProfiling(): Promise<mixed> {
|
44
|
-
let inspector;
|
45
|
-
try {
|
46
|
-
inspector = require('inspector');
|
47
|
-
} catch (err) {
|
48
|
-
throw new ThrowableDiagnostic({
|
49
|
-
diagnostic: {
|
50
|
-
message: `The inspector module isn't available`,
|
51
|
-
origin: '@parcel/workers',
|
52
|
-
hints: ['Disable build profiling'],
|
53
|
-
},
|
54
|
-
});
|
55
|
-
}
|
56
|
-
|
57
|
-
this.session = new inspector.Session();
|
58
|
-
this.session.connect();
|
59
|
-
|
60
|
-
return Promise.all([
|
61
|
-
this.sendCommand('Profiler.setSamplingInterval', {
|
62
|
-
interval: 100,
|
63
|
-
}),
|
64
|
-
this.sendCommand('Profiler.enable'),
|
65
|
-
this.sendCommand('Profiler.start'),
|
66
|
-
]);
|
67
|
-
}
|
68
|
-
|
69
|
-
sendCommand(method: string, params: mixed): Promise<{profile: Profile, ...}> {
|
70
|
-
invariant(this.session != null);
|
71
|
-
return new Promise((resolve, reject) => {
|
72
|
-
this.session.post(method, params, (err, params) => {
|
73
|
-
if (err == null) {
|
74
|
-
resolve(params);
|
75
|
-
} else {
|
76
|
-
reject(err);
|
77
|
-
}
|
78
|
-
});
|
79
|
-
});
|
80
|
-
}
|
81
|
-
|
82
|
-
destroy() {
|
83
|
-
if (this.session != null) {
|
84
|
-
this.session.disconnect();
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
async stopProfiling(): Promise<Profile> {
|
89
|
-
let res = await this.sendCommand('Profiler.stop');
|
90
|
-
this.destroy();
|
91
|
-
return res.profile;
|
92
|
-
}
|
93
|
-
}
|
package/src/Trace.js
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
// @flow
|
2
|
-
import type {Profile} from './Profiler';
|
3
|
-
import type {Writable} from 'stream';
|
4
|
-
import {Tracer} from 'chrome-trace-event';
|
5
|
-
|
6
|
-
export default class Trace {
|
7
|
-
tracer: Tracer;
|
8
|
-
tid: number;
|
9
|
-
eventId: number;
|
10
|
-
|
11
|
-
constructor() {
|
12
|
-
this.tracer = new Tracer();
|
13
|
-
this.tid = 0;
|
14
|
-
this.eventId = 0;
|
15
|
-
}
|
16
|
-
|
17
|
-
getEventId(): number {
|
18
|
-
return this.eventId++;
|
19
|
-
}
|
20
|
-
|
21
|
-
init(ts: number) {
|
22
|
-
this.tracer.instantEvent({
|
23
|
-
name: 'TracingStartedInPage',
|
24
|
-
id: this.getEventId(),
|
25
|
-
ts,
|
26
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
27
|
-
args: {
|
28
|
-
data: {
|
29
|
-
sessionId: '-1',
|
30
|
-
page: '0xfff',
|
31
|
-
frames: [
|
32
|
-
{
|
33
|
-
frame: '0xfff',
|
34
|
-
url: 'parcel',
|
35
|
-
name: '',
|
36
|
-
},
|
37
|
-
],
|
38
|
-
},
|
39
|
-
},
|
40
|
-
});
|
41
|
-
|
42
|
-
this.tracer.instantEvent({
|
43
|
-
name: 'TracingStartedInBrowser',
|
44
|
-
id: this.getEventId(),
|
45
|
-
ts,
|
46
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
47
|
-
args: {
|
48
|
-
data: {
|
49
|
-
sessionId: '-1',
|
50
|
-
},
|
51
|
-
},
|
52
|
-
});
|
53
|
-
}
|
54
|
-
|
55
|
-
addCPUProfile(name: string, profile: Profile) {
|
56
|
-
if (this.eventId === 0) {
|
57
|
-
this.init(profile.startTime);
|
58
|
-
}
|
59
|
-
const trace = this.tracer;
|
60
|
-
const tid = this.tid;
|
61
|
-
this.tid++;
|
62
|
-
|
63
|
-
const cpuStartTime = profile.startTime;
|
64
|
-
const cpuEndTime = profile.endTime;
|
65
|
-
|
66
|
-
trace.instantEvent({
|
67
|
-
tid,
|
68
|
-
id: this.getEventId(),
|
69
|
-
cat: ['toplevel'],
|
70
|
-
name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
|
71
|
-
args: {
|
72
|
-
src_file: '../../ipc/ipc_moji_bootstrap.cc',
|
73
|
-
src_func: 'Accept',
|
74
|
-
},
|
75
|
-
ts: cpuStartTime,
|
76
|
-
});
|
77
|
-
|
78
|
-
trace.completeEvent({
|
79
|
-
tid,
|
80
|
-
name: 'EvaluateScript',
|
81
|
-
id: this.getEventId(),
|
82
|
-
cat: ['devtools.timeline'],
|
83
|
-
ts: cpuStartTime,
|
84
|
-
dur: cpuEndTime - cpuStartTime,
|
85
|
-
args: {
|
86
|
-
data: {
|
87
|
-
url: 'parcel',
|
88
|
-
lineNumber: 1,
|
89
|
-
columnNumber: 1,
|
90
|
-
frame: '0xFFF',
|
91
|
-
},
|
92
|
-
},
|
93
|
-
});
|
94
|
-
|
95
|
-
trace.instantEvent({
|
96
|
-
tid,
|
97
|
-
ts: 0,
|
98
|
-
ph: 'M',
|
99
|
-
cat: ['__metadata'],
|
100
|
-
name: 'thread_name',
|
101
|
-
args: {name},
|
102
|
-
});
|
103
|
-
|
104
|
-
trace.instantEvent({
|
105
|
-
tid,
|
106
|
-
name: 'CpuProfile',
|
107
|
-
id: this.getEventId(),
|
108
|
-
cat: ['disabled-by-default-devtools.timeline'],
|
109
|
-
ts: cpuEndTime,
|
110
|
-
args: {
|
111
|
-
data: {
|
112
|
-
cpuProfile: profile,
|
113
|
-
},
|
114
|
-
},
|
115
|
-
});
|
116
|
-
}
|
117
|
-
|
118
|
-
pipe(writable: Writable): stream$Writable {
|
119
|
-
return this.tracer.pipe(writable);
|
120
|
-
}
|
121
|
-
|
122
|
-
flush() {
|
123
|
-
this.tracer.push(null);
|
124
|
-
}
|
125
|
-
}
|