From 883088e52136666bc639845f39209b528b4964ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brzo=CC=81ska?= Date: Mon, 5 Mar 2018 22:46:45 +0100 Subject: [PATCH 1/3] fix(ProfilingPlugin): complete after the writeStream had finished flushing the data to the filesystem Fixes a race-condition where `events.json` might not yet be available immediately after compilation. --- lib/debug/ProfilingPlugin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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); }); } ); From cdeffb39b06c2a5d56af9e34576d5de66b6d6a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brzo=CC=81ska?= Date: Wed, 7 Mar 2018 20:28:14 +0100 Subject: [PATCH 2/3] fix(ProfilingPlugin): only expose the end method of fsStream --- lib/debug/ProfilingPlugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 2c05c368b..57e49b002 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -73,7 +73,7 @@ class Profiler { /** * @param {string} outputPath The location where to write the log. - * @returns {{trace: ?, counter: number, profiler: Profiler, fsStream: WriteStream}} The trace object + * @returns {{trace: ?, counter: number, profiler: Profiler, end: Function}} The trace object */ function createTrace(outputPath) { const trace = new Trace({ @@ -121,7 +121,7 @@ function createTrace(outputPath) { trace, counter, profiler, - fsStream + end: (callback) => fsStream.end(callback) }; } @@ -181,7 +181,7 @@ class ProfilingPlugin { if (parsedResults === undefined) { tracer.profiler.destroy(); tracer.trace.flush(); - tracer.fsStream.end(callback); + tracer.end(callback); return; } @@ -229,7 +229,7 @@ class ProfilingPlugin { tracer.profiler.destroy(); tracer.trace.flush(); - tracer.fsStream.end(callback); + tracer.end(callback); }); } ); From bd043f8e26faeaaabf03cd71dc18c6e96fddc03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bazyli=20Brzo=CC=81ska?= Date: Wed, 7 Mar 2018 21:09:09 +0100 Subject: [PATCH 3/3] fix lint --- lib/debug/ProfilingPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index 57e49b002..ab82ca090 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -121,7 +121,7 @@ function createTrace(outputPath) { trace, counter, profiler, - end: (callback) => fsStream.end(callback) + end: callback => fsStream.end(callback) }; }