profile progress

This commit is contained in:
Tobias Koppers 2013-07-04 11:02:35 +02:00
parent 996ea59bb0
commit d85324c9fd
2 changed files with 23 additions and 2 deletions

View File

@ -213,8 +213,9 @@ module.exports = function(optimist, argv, convertOptions) {
ifBooleanArg("progress", function() {
var ProgressPlugin = require("../lib/ProgressPlugin");
ensureArray(options, "plugins");
var chars = 0;
var chars = 0, lastState;
options.plugins.push(new ProgressPlugin(function(percentage, msg) {
var state = msg;
if(percentage < 1) {
percentage = Math.floor(percentage * 100);
msg = percentage + "% " + msg;
@ -226,6 +227,20 @@ module.exports = function(optimist, argv, convertOptions) {
chars = msg.length;
for(var i = 0; i < chars; i++)
process.stderr.write("\b");
if(options.profile) {
state = state.replace(/^\d+\/\d+\s+/, "");
if(percentage === 0) {
lastState = null;
lastStateTime = +new Date();
} else if(state !== lastState || percentage === 1) {
var now = +new Date();
if(lastState) {
process.stderr.write((now - lastStateTime) + "ms " + lastState + "\n");
}
lastState = state;
lastStateTime = now;
}
}
process.stderr.write(msg);
}));
});

View File

@ -30,7 +30,13 @@ ProgressPlugin.prototype.apply = function(compiler) {
update();
});
compilation.plugin("optimize", function() {
handler(0.75, "optimize");
handler(0.73, "optimize");
});
compilation.plugin("before-hash", function() {
handler(0.75, "hashing");
});
compilation.plugin("additional-chunk-assets", function() {
handler(0.78, "additional chunk assets");
});
compilation.plugin("optimize-chunk-assets", function(chunks, callback) {
handler(0.8, "optimize chunk assets");