webpack 4.1.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,405 +1,409 @@
|
|
1
|
-
const fs = require("fs");
|
2
|
-
const
|
3
|
-
const validateOptions = require("schema-utils");
|
4
|
-
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
5
|
-
let inspector = undefined;
|
6
|
-
|
7
|
-
try {
|
8
|
-
inspector = require("inspector"); // eslint-disable-line node/no-missing-require
|
9
|
-
} catch (e) {
|
10
|
-
console.log("Unable to CPU profile in < node 8.0");
|
11
|
-
}
|
12
|
-
|
13
|
-
class Profiler {
|
14
|
-
constructor(inspector) {
|
15
|
-
this.session = undefined;
|
16
|
-
this.inspector = inspector;
|
17
|
-
}
|
18
|
-
|
19
|
-
hasSession() {
|
20
|
-
return this.session !== undefined;
|
21
|
-
}
|
22
|
-
|
23
|
-
startProfiling() {
|
24
|
-
if (this.inspector === undefined) {
|
25
|
-
return Promise.resolve();
|
26
|
-
}
|
27
|
-
|
28
|
-
try {
|
29
|
-
this.session = new inspector.Session();
|
30
|
-
this.session.connect();
|
31
|
-
} catch (_) {
|
32
|
-
this.session = undefined;
|
33
|
-
return Promise.resolve();
|
34
|
-
}
|
35
|
-
|
36
|
-
return Promise.all([
|
37
|
-
this.sendCommand("Profiler.setSamplingInterval", {
|
38
|
-
interval: 100
|
39
|
-
}),
|
40
|
-
this.sendCommand("Profiler.enable"),
|
41
|
-
this.sendCommand("Profiler.start")
|
42
|
-
]);
|
43
|
-
}
|
44
|
-
|
45
|
-
sendCommand(method, params) {
|
46
|
-
if (this.hasSession()) {
|
47
|
-
return new Promise((res, rej) => {
|
48
|
-
return this.session.post(method, params, (err, params) => {
|
49
|
-
if (err !== null) {
|
50
|
-
rej(err);
|
51
|
-
} else {
|
52
|
-
res(params);
|
53
|
-
}
|
54
|
-
});
|
55
|
-
});
|
56
|
-
} else {
|
57
|
-
return Promise.resolve();
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
destroy() {
|
62
|
-
if (this.hasSession()) {
|
63
|
-
this.session.disconnect();
|
64
|
-
}
|
65
|
-
|
66
|
-
return Promise.resolve();
|
67
|
-
}
|
68
|
-
|
69
|
-
stopProfiling() {
|
70
|
-
return this.sendCommand("Profiler.stop");
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
/**
|
75
|
-
* @param {string} outputPath The location where to write the log.
|
76
|
-
* @returns {{trace: ?, counter: number, profiler: Profiler}} The trace object
|
77
|
-
*/
|
78
|
-
function createTrace(outputPath) {
|
79
|
-
const trace = new
|
80
|
-
noStream: true
|
81
|
-
});
|
82
|
-
const profiler = new Profiler(inspector);
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
//
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
{
|
251
|
-
instance:
|
252
|
-
name: "
|
253
|
-
},
|
254
|
-
{
|
255
|
-
instance:
|
256
|
-
name: "
|
257
|
-
},
|
258
|
-
{
|
259
|
-
instance:
|
260
|
-
name: "
|
261
|
-
},
|
262
|
-
{
|
263
|
-
instance:
|
264
|
-
name: "
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
"
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
}
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
};
|
403
|
-
|
404
|
-
|
405
|
-
|
1
|
+
const fs = require("fs");
|
2
|
+
const { Tracer } = require("chrome-trace-event");
|
3
|
+
const validateOptions = require("schema-utils");
|
4
|
+
const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
5
|
+
let inspector = undefined;
|
6
|
+
|
7
|
+
try {
|
8
|
+
inspector = require("inspector"); // eslint-disable-line node/no-missing-require
|
9
|
+
} catch (e) {
|
10
|
+
console.log("Unable to CPU profile in < node 8.0");
|
11
|
+
}
|
12
|
+
|
13
|
+
class Profiler {
|
14
|
+
constructor(inspector) {
|
15
|
+
this.session = undefined;
|
16
|
+
this.inspector = inspector;
|
17
|
+
}
|
18
|
+
|
19
|
+
hasSession() {
|
20
|
+
return this.session !== undefined;
|
21
|
+
}
|
22
|
+
|
23
|
+
startProfiling() {
|
24
|
+
if (this.inspector === undefined) {
|
25
|
+
return Promise.resolve();
|
26
|
+
}
|
27
|
+
|
28
|
+
try {
|
29
|
+
this.session = new inspector.Session();
|
30
|
+
this.session.connect();
|
31
|
+
} catch (_) {
|
32
|
+
this.session = undefined;
|
33
|
+
return Promise.resolve();
|
34
|
+
}
|
35
|
+
|
36
|
+
return Promise.all([
|
37
|
+
this.sendCommand("Profiler.setSamplingInterval", {
|
38
|
+
interval: 100
|
39
|
+
}),
|
40
|
+
this.sendCommand("Profiler.enable"),
|
41
|
+
this.sendCommand("Profiler.start")
|
42
|
+
]);
|
43
|
+
}
|
44
|
+
|
45
|
+
sendCommand(method, params) {
|
46
|
+
if (this.hasSession()) {
|
47
|
+
return new Promise((res, rej) => {
|
48
|
+
return this.session.post(method, params, (err, params) => {
|
49
|
+
if (err !== null) {
|
50
|
+
rej(err);
|
51
|
+
} else {
|
52
|
+
res(params);
|
53
|
+
}
|
54
|
+
});
|
55
|
+
});
|
56
|
+
} else {
|
57
|
+
return Promise.resolve();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
destroy() {
|
62
|
+
if (this.hasSession()) {
|
63
|
+
this.session.disconnect();
|
64
|
+
}
|
65
|
+
|
66
|
+
return Promise.resolve();
|
67
|
+
}
|
68
|
+
|
69
|
+
stopProfiling() {
|
70
|
+
return this.sendCommand("Profiler.stop");
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @param {string} outputPath The location where to write the log.
|
76
|
+
* @returns {{trace: ?, counter: number, profiler: Profiler, end: Function}} The trace object
|
77
|
+
*/
|
78
|
+
function createTrace(outputPath) {
|
79
|
+
const trace = new Tracer({
|
80
|
+
noStream: true
|
81
|
+
});
|
82
|
+
const profiler = new Profiler(inspector);
|
83
|
+
const fsStream = fs.createWriteStream(outputPath);
|
84
|
+
|
85
|
+
let counter = 0;
|
86
|
+
|
87
|
+
trace.pipe(fsStream);
|
88
|
+
// These are critical events that need to be inserted so that tools like
|
89
|
+
// chrome dev tools can load the profile.
|
90
|
+
trace.instantEvent({
|
91
|
+
name: "TracingStartedInPage",
|
92
|
+
id: ++counter,
|
93
|
+
cat: ["disabled-by-default-devtools.timeline"],
|
94
|
+
args: {
|
95
|
+
data: {
|
96
|
+
sessionId: "-1",
|
97
|
+
page: "0xfff",
|
98
|
+
frames: [
|
99
|
+
{
|
100
|
+
frame: "0xfff",
|
101
|
+
url: "webpack",
|
102
|
+
name: ""
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
trace.instantEvent({
|
110
|
+
name: "TracingStartedInBrowser",
|
111
|
+
id: ++counter,
|
112
|
+
cat: ["disabled-by-default-devtools.timeline"],
|
113
|
+
args: {
|
114
|
+
data: {
|
115
|
+
sessionId: "-1"
|
116
|
+
}
|
117
|
+
}
|
118
|
+
});
|
119
|
+
|
120
|
+
return {
|
121
|
+
trace,
|
122
|
+
counter,
|
123
|
+
profiler,
|
124
|
+
end: callback => fsStream.end(callback)
|
125
|
+
};
|
126
|
+
}
|
127
|
+
|
128
|
+
const pluginName = "ProfilingPlugin";
|
129
|
+
|
130
|
+
class ProfilingPlugin {
|
131
|
+
constructor(opts) {
|
132
|
+
validateOptions(schema, opts || {}, "Profiling plugin");
|
133
|
+
opts = opts || {};
|
134
|
+
this.outputPath = opts.outputPath || "events.json";
|
135
|
+
}
|
136
|
+
|
137
|
+
apply(compiler) {
|
138
|
+
const tracer = createTrace(this.outputPath);
|
139
|
+
tracer.profiler.startProfiling();
|
140
|
+
|
141
|
+
// Compiler Hooks
|
142
|
+
Object.keys(compiler.hooks).forEach(hookName => {
|
143
|
+
compiler.hooks[hookName].intercept(
|
144
|
+
makeInterceptorFor("Compiler", tracer)(hookName)
|
145
|
+
);
|
146
|
+
});
|
147
|
+
|
148
|
+
Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
|
149
|
+
compiler.resolverFactory.hooks[hookName].intercept(
|
150
|
+
makeInterceptorFor("Resolver", tracer)(hookName)
|
151
|
+
);
|
152
|
+
});
|
153
|
+
|
154
|
+
compiler.hooks.compilation.tap(
|
155
|
+
pluginName,
|
156
|
+
(compilation, { normalModuleFactory, contextModuleFactory }) => {
|
157
|
+
interceptAllHooksFor(compilation, tracer, "Compilation");
|
158
|
+
interceptAllHooksFor(
|
159
|
+
normalModuleFactory,
|
160
|
+
tracer,
|
161
|
+
"Normal Module Factory"
|
162
|
+
);
|
163
|
+
interceptAllHooksFor(
|
164
|
+
contextModuleFactory,
|
165
|
+
tracer,
|
166
|
+
"Context Module Factory"
|
167
|
+
);
|
168
|
+
interceptAllParserHooks(normalModuleFactory, tracer);
|
169
|
+
interceptTemplateInstancesFrom(compilation, tracer);
|
170
|
+
}
|
171
|
+
);
|
172
|
+
|
173
|
+
// We need to write out the CPU profile when we are all done.
|
174
|
+
compiler.hooks.done.tapAsync(
|
175
|
+
{
|
176
|
+
name: pluginName,
|
177
|
+
stage: Infinity
|
178
|
+
},
|
179
|
+
(stats, callback) => {
|
180
|
+
tracer.profiler.stopProfiling().then(parsedResults => {
|
181
|
+
if (parsedResults === undefined) {
|
182
|
+
tracer.profiler.destroy();
|
183
|
+
tracer.trace.flush();
|
184
|
+
tracer.end(callback);
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
|
188
|
+
const cpuStartTime = parsedResults.profile.startTime;
|
189
|
+
const cpuEndTime = parsedResults.profile.endTime;
|
190
|
+
|
191
|
+
tracer.trace.completeEvent({
|
192
|
+
name: "TaskQueueManager::ProcessTaskFromWorkQueue",
|
193
|
+
id: ++tracer.counter,
|
194
|
+
cat: ["toplevel"],
|
195
|
+
ts: cpuStartTime,
|
196
|
+
args: {
|
197
|
+
src_file: "../../ipc/ipc_moji_bootstrap.cc",
|
198
|
+
src_func: "Accept"
|
199
|
+
}
|
200
|
+
});
|
201
|
+
|
202
|
+
tracer.trace.completeEvent({
|
203
|
+
name: "EvaluateScript",
|
204
|
+
id: ++tracer.counter,
|
205
|
+
cat: ["devtools.timeline"],
|
206
|
+
ts: cpuStartTime,
|
207
|
+
dur: cpuEndTime - cpuStartTime,
|
208
|
+
args: {
|
209
|
+
data: {
|
210
|
+
url: "webpack",
|
211
|
+
lineNumber: 1,
|
212
|
+
columnNumber: 1,
|
213
|
+
frame: "0xFFF"
|
214
|
+
}
|
215
|
+
}
|
216
|
+
});
|
217
|
+
|
218
|
+
tracer.trace.instantEvent({
|
219
|
+
name: "CpuProfile",
|
220
|
+
id: ++tracer.counter,
|
221
|
+
cat: ["disabled-by-default-devtools.timeline"],
|
222
|
+
ts: cpuEndTime,
|
223
|
+
args: {
|
224
|
+
data: {
|
225
|
+
cpuProfile: parsedResults.profile
|
226
|
+
}
|
227
|
+
}
|
228
|
+
});
|
229
|
+
|
230
|
+
tracer.profiler.destroy();
|
231
|
+
tracer.trace.flush();
|
232
|
+
tracer.end(callback);
|
233
|
+
});
|
234
|
+
}
|
235
|
+
);
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
const interceptTemplateInstancesFrom = (compilation, tracer) => {
|
240
|
+
const {
|
241
|
+
mainTemplate,
|
242
|
+
chunkTemplate,
|
243
|
+
hotUpdateChunkTemplate,
|
244
|
+
moduleTemplates
|
245
|
+
} = compilation;
|
246
|
+
|
247
|
+
const { javascript, webassembly } = moduleTemplates;
|
248
|
+
|
249
|
+
[
|
250
|
+
{
|
251
|
+
instance: mainTemplate,
|
252
|
+
name: "MainTemplate"
|
253
|
+
},
|
254
|
+
{
|
255
|
+
instance: chunkTemplate,
|
256
|
+
name: "ChunkTemplate"
|
257
|
+
},
|
258
|
+
{
|
259
|
+
instance: hotUpdateChunkTemplate,
|
260
|
+
name: "HotUpdateChunkTemplate"
|
261
|
+
},
|
262
|
+
{
|
263
|
+
instance: javascript,
|
264
|
+
name: "JavaScriptModuleTemplate"
|
265
|
+
},
|
266
|
+
{
|
267
|
+
instance: webassembly,
|
268
|
+
name: "WebAssemblyModuleTemplate"
|
269
|
+
}
|
270
|
+
].forEach(templateObject => {
|
271
|
+
Object.keys(templateObject.instance.hooks).forEach(hookName => {
|
272
|
+
templateObject.instance.hooks[hookName].intercept(
|
273
|
+
makeInterceptorFor(templateObject.name, tracer)(hookName)
|
274
|
+
);
|
275
|
+
});
|
276
|
+
});
|
277
|
+
};
|
278
|
+
|
279
|
+
const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
280
|
+
if (Reflect.has(instance, "hooks")) {
|
281
|
+
Object.keys(instance.hooks).forEach(hookName => {
|
282
|
+
instance.hooks[hookName].intercept(
|
283
|
+
makeInterceptorFor(logLabel, tracer)(hookName)
|
284
|
+
);
|
285
|
+
});
|
286
|
+
}
|
287
|
+
};
|
288
|
+
|
289
|
+
const interceptAllParserHooks = (moduleFactory, tracer) => {
|
290
|
+
const moduleTypes = [
|
291
|
+
"javascript/auto",
|
292
|
+
"javascript/dynamic",
|
293
|
+
"javascript/esm",
|
294
|
+
"json",
|
295
|
+
"webassembly/experimental"
|
296
|
+
];
|
297
|
+
|
298
|
+
moduleTypes.forEach(moduleType => {
|
299
|
+
moduleFactory.hooks.parser
|
300
|
+
.for(moduleType)
|
301
|
+
.tap("ProfilingPlugin", (parser, parserOpts) => {
|
302
|
+
interceptAllHooksFor(parser, tracer, "Parser");
|
303
|
+
});
|
304
|
+
});
|
305
|
+
};
|
306
|
+
|
307
|
+
const makeInterceptorFor = (instance, tracer) => hookName => ({
|
308
|
+
register: ({ name, type, context, fn }) => {
|
309
|
+
const newFn = makeNewProfiledTapFn(hookName, tracer, {
|
310
|
+
name,
|
311
|
+
type,
|
312
|
+
fn
|
313
|
+
});
|
314
|
+
return {
|
315
|
+
name,
|
316
|
+
type,
|
317
|
+
context,
|
318
|
+
fn: newFn
|
319
|
+
};
|
320
|
+
}
|
321
|
+
});
|
322
|
+
|
323
|
+
/**
|
324
|
+
* @param {string} hookName Name of the hook to profile.
|
325
|
+
* @param {{counter: number, trace: *, profiler: *}} tracer Instance of tracer.
|
326
|
+
* @param {{name: string, type: string, fn: Function}} opts Options for the profiled fn.
|
327
|
+
* @returns {*} Chainable hooked function.
|
328
|
+
*/
|
329
|
+
const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
330
|
+
const defaultCategory = ["blink.user_timing"];
|
331
|
+
|
332
|
+
switch (type) {
|
333
|
+
case "promise":
|
334
|
+
return (...args) => {
|
335
|
+
// eslint-disable-line
|
336
|
+
const id = ++tracer.counter;
|
337
|
+
tracer.trace.begin({
|
338
|
+
name,
|
339
|
+
id,
|
340
|
+
cat: defaultCategory
|
341
|
+
});
|
342
|
+
return fn(...args).then(r => {
|
343
|
+
tracer.trace.end({
|
344
|
+
name,
|
345
|
+
id,
|
346
|
+
cat: defaultCategory
|
347
|
+
});
|
348
|
+
return r;
|
349
|
+
});
|
350
|
+
};
|
351
|
+
case "async":
|
352
|
+
return (...args) => {
|
353
|
+
// eslint-disable-line
|
354
|
+
const id = ++tracer.counter;
|
355
|
+
tracer.trace.begin({
|
356
|
+
name,
|
357
|
+
id,
|
358
|
+
cat: defaultCategory
|
359
|
+
});
|
360
|
+
fn(...args, (...r) => {
|
361
|
+
const callback = args.pop();
|
362
|
+
tracer.trace.end({
|
363
|
+
name,
|
364
|
+
id,
|
365
|
+
cat: defaultCategory
|
366
|
+
});
|
367
|
+
callback(...r);
|
368
|
+
});
|
369
|
+
};
|
370
|
+
case "sync":
|
371
|
+
return (...args) => {
|
372
|
+
// eslint-disable-line
|
373
|
+
const id = ++tracer.counter;
|
374
|
+
// Do not instrument ourself due to the CPU
|
375
|
+
// profile needing to be the last event in the trace.
|
376
|
+
if (name === pluginName) {
|
377
|
+
return fn(...args);
|
378
|
+
}
|
379
|
+
|
380
|
+
tracer.trace.begin({
|
381
|
+
name,
|
382
|
+
id,
|
383
|
+
cat: defaultCategory
|
384
|
+
});
|
385
|
+
let r;
|
386
|
+
try {
|
387
|
+
r = fn(...args);
|
388
|
+
} catch (error) {
|
389
|
+
tracer.trace.end({
|
390
|
+
name,
|
391
|
+
id,
|
392
|
+
cat: defaultCategory
|
393
|
+
});
|
394
|
+
throw error;
|
395
|
+
}
|
396
|
+
tracer.trace.end({
|
397
|
+
name,
|
398
|
+
id,
|
399
|
+
cat: defaultCategory
|
400
|
+
});
|
401
|
+
return r;
|
402
|
+
};
|
403
|
+
default:
|
404
|
+
break;
|
405
|
+
}
|
406
|
+
};
|
407
|
+
|
408
|
+
module.exports = ProfilingPlugin;
|
409
|
+
module.exports.Profiler = Profiler;
|