@@ -73,17 +73,18 @@ class Profiler {
7373
7474/**
7575 * @param {string } outputPath The location where to write the log.
76- * @returns {{trace: ?, counter: number, profiler: Profiler} } The trace object
76+ * @returns {{trace: ?, counter: number, profiler: Profiler, fsStream: WriteStream } } The trace object
7777 */
7878function createTrace ( outputPath ) {
7979 const trace = new Trace ( {
8080 noStream : true
8181 } ) ;
8282 const profiler = new Profiler ( inspector ) ;
83+ const fsStream = fs . createWriteStream ( outputPath ) ;
8384
8485 let counter = 0 ;
8586
86- trace . pipe ( fs . createWriteStream ( outputPath ) ) ;
87+ trace . pipe ( fsStream ) ;
8788 // These are critical events that need to be inserted so that tools like
8889 // chrome dev tools can load the profile.
8990 trace . instantEvent ( {
@@ -119,7 +120,8 @@ function createTrace(outputPath) {
119120 return {
120121 trace,
121122 counter,
122- profiler
123+ profiler,
124+ fsStream
123125 } ;
124126}
125127
@@ -169,16 +171,17 @@ class ProfilingPlugin {
169171 ) ;
170172
171173 // We need to write out the CPU profile when we are all done.
172- compiler . hooks . done . tap (
174+ compiler . hooks . done . tapAsync (
173175 {
174176 name : pluginName ,
175177 stage : Infinity
176178 } ,
177- ( ) => {
179+ ( stats , callback ) => {
178180 tracer . profiler . stopProfiling ( ) . then ( parsedResults => {
179181 if ( parsedResults === undefined ) {
180182 tracer . profiler . destroy ( ) ;
181183 tracer . trace . flush ( ) ;
184+ tracer . fsStream . end ( callback ) ;
182185 return ;
183186 }
184187
@@ -226,6 +229,7 @@ class ProfilingPlugin {
226229
227230 tracer . profiler . destroy ( ) ;
228231 tracer . trace . flush ( ) ;
232+ tracer . fsStream . end ( callback ) ;
229233 } ) ;
230234 }
231235 ) ;
0 commit comments