diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 76fb36f95..2c05c368b 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -73,17 +73,18 @@ class Profiler { /** * @param {string} outputPath The location where to write the log. - * @returns {{trace: ?, counter: number, profiler: Profiler}} The trace object + * @returns {{trace: ?, counter: number, profiler: Profiler, fsStream: WriteStream}} The trace object */ function createTrace(outputPath) { const trace = new Trace({ noStream: true }); const profiler = new Profiler(inspector); + const fsStream = fs.createWriteStream(outputPath); let counter = 0; - trace.pipe(fs.createWriteStream(outputPath)); + trace.pipe(fsStream); // These are critical events that need to be inserted so that tools like // chrome dev tools can load the profile. trace.instantEvent({ @@ -119,7 +120,8 @@ function createTrace(outputPath) { return { trace, counter, - profiler + profiler, + fsStream }; } @@ -169,16 +171,17 @@ class ProfilingPlugin { ); // We need to write out the CPU profile when we are all done. - compiler.hooks.done.tap( + compiler.hooks.done.tapAsync( { name: pluginName, stage: Infinity }, - () => { + (stats, callback) => { tracer.profiler.stopProfiling().then(parsedResults => { if (parsedResults === undefined) { tracer.profiler.destroy(); tracer.trace.flush(); + tracer.fsStream.end(callback); return; } @@ -226,6 +229,7 @@ class ProfilingPlugin { tracer.profiler.destroy(); tracer.trace.flush(); + tracer.fsStream.end(callback); }); } );