mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #6678 from niieani/profiling-race
fix(ProfilingPlugin): complete after the writeStream had finished flushing the data to the filesystem
This commit is contained in:
		
						commit
						19ebed9527
					
				|  | @ -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, end: Function}} 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, | ||||
| 		end: callback => fsStream.end(callback) | ||||
| 	}; | ||||
| } | ||||
| 
 | ||||
|  | @ -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.end(callback); | ||||
| 						return; | ||||
| 					} | ||||
| 
 | ||||
|  | @ -226,6 +229,7 @@ class ProfilingPlugin { | |||
| 
 | ||||
| 					tracer.profiler.destroy(); | ||||
| 					tracer.trace.flush(); | ||||
| 					tracer.end(callback); | ||||
| 				}); | ||||
| 			} | ||||
| 		); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue