@@ -73,17 +73,18 @@ class Profiler {
73
73
74
74
/**
75
75
* @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, end: Function } } The trace object
77
77
*/
78
78
function createTrace ( outputPath ) {
79
79
const trace = new Trace ( {
80
80
noStream : true
81
81
} ) ;
82
82
const profiler = new Profiler ( inspector ) ;
83
+ const fsStream = fs . createWriteStream ( outputPath ) ;
83
84
84
85
let counter = 0 ;
85
86
86
- trace . pipe ( fs . createWriteStream ( outputPath ) ) ;
87
+ trace . pipe ( fsStream ) ;
87
88
// These are critical events that need to be inserted so that tools like
88
89
// chrome dev tools can load the profile.
89
90
trace . instantEvent ( {
@@ -119,7 +120,8 @@ function createTrace(outputPath) {
119
120
return {
120
121
trace,
121
122
counter,
122
- profiler
123
+ profiler,
124
+ end : callback => fsStream . end ( callback )
123
125
} ;
124
126
}
125
127
@@ -169,16 +171,17 @@ class ProfilingPlugin {
169
171
) ;
170
172
171
173
// We need to write out the CPU profile when we are all done.
172
- compiler . hooks . done . tap (
174
+ compiler . hooks . done . tapAsync (
173
175
{
174
176
name : pluginName ,
175
177
stage : Infinity
176
178
} ,
177
- ( ) => {
179
+ ( stats , callback ) => {
178
180
tracer . profiler . stopProfiling ( ) . then ( parsedResults => {
179
181
if ( parsedResults === undefined ) {
180
182
tracer . profiler . destroy ( ) ;
181
183
tracer . trace . flush ( ) ;
184
+ tracer . end ( callback ) ;
182
185
return ;
183
186
}
184
187
@@ -226,6 +229,7 @@ class ProfilingPlugin {
226
229
227
230
tracer . profiler . destroy ( ) ;
228
231
tracer . trace . flush ( ) ;
232
+ tracer . end ( callback ) ;
229
233
} ) ;
230
234
}
231
235
) ;
0 commit comments