Merge pull request #15157 from markjm/markjm/watch-mode-profile-plugin

Fix ProfilingPlugin for watch scenarios
This commit is contained in:
Tobias Koppers 2022-01-18 07:20:30 +01:00 committed by GitHub
commit bc80a83a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 11 deletions

View File

@ -123,9 +123,7 @@ class Profiler {
* @returns {Trace} The trace object
*/
const createTrace = (fs, outputPath) => {
const trace = new Tracer({
noStream: true
});
const trace = new Tracer();
const profiler = new Profiler(inspector);
if (/\/|\\/.test(outputPath)) {
const dirPath = dirname(fs, outputPath);
@ -173,6 +171,7 @@ const createTrace = (fs, outputPath) => {
counter,
profiler,
end: callback => {
trace.push("]");
// Wait until the write stream finishes.
fsStream.on("close", () => {
callback();
@ -242,10 +241,10 @@ class ProfilingPlugin {
stage: Infinity
},
(stats, callback) => {
if (compiler.watchMode) return callback();
tracer.profiler.stopProfiling().then(parsedResults => {
if (parsedResults === undefined) {
tracer.profiler.destroy();
tracer.trace.flush();
tracer.end(callback);
return;
}
@ -293,7 +292,6 @@ class ProfilingPlugin {
});
tracer.profiler.destroy();
tracer.trace.flush();
tracer.end(callback);
});
}
@ -346,11 +344,15 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
const makeInterceptorFor = (instance, tracer) => hookName => ({
register: ({ name, type, context, fn }) => {
const newFn = makeNewProfiledTapFn(hookName, tracer, {
name,
type,
fn
});
const newFn =
// Don't tap our own hooks to ensure stream can close cleanly
name === pluginName
? fn
: makeNewProfiledTapFn(hookName, tracer, {
name,
type,
fn
});
return {
name,
type,

View File

@ -396,7 +396,7 @@ const describeCases = config => {
done
)
) {
compiler.close();
compiler.close(() => {});
return;
}
compiler.close(done);

View File

@ -0,0 +1,3 @@
it("compiles", function() {
expect(WATCH_STEP).toBe("0");
})

View File

@ -0,0 +1,3 @@
it("should not crash on recompile", function() {
expect(WATCH_STEP).toBe("1");
})

View File

@ -0,0 +1,3 @@
module.exports = [
{ code: /DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK/ }
];

View File

@ -0,0 +1,6 @@
var webpack = require("../../../../");
/** @type {import("../../../../").Configuration} */
module.exports = {
plugins: [new webpack.debug.ProfilingPlugin()]
};