Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/api/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ module.exports = function (targets, options) {
targets = [];
}

var makePlatform = new MakePlatform(),
root = path.resolve(options.dir || cdir),
cache = options.hasOwnProperty('cache') ? options.cache : true,
isStrict = options.hasOwnProperty('strict') ? options.strict : true,
logger,
graph;

return makePlatform.init(root, options.mode, options.config, { graph: options.graph, profiler: options.profiler })
var makePlatform = new MakePlatform();
var root = path.resolve(options.dir || cdir);
var cache = options.hasOwnProperty('cache') ? options.cache : true;
var isStrict = options.hasOwnProperty('strict') ? options.strict : true;
var needProfiler = options.profiler || options.profilerPercentiles;
var logger;
var graph;

return makePlatform.init(root, options.mode, options.config, { graph: options.graph, profiler: needProfiler })
.then(function () {
logger = makePlatform.getLogger();

Expand Down Expand Up @@ -71,14 +72,17 @@ module.exports = function (targets, options) {

return vow.when(makePlatform.saveCacheAsync(), makePlatform.destruct.bind(makePlatform))
.then(function () {
if (options.profiler) {
if (needProfiler) {
var percentileRanks = options.profilerPercentiles;
var profiler = makePlatform.getBuildProfiler();
var buildTimes = profiler.calculateBuildTimes(makePlatform.getBuildGraph());
var techMetricsData = profiler.calculateTechMetrics(buildTimes);
var techMetrics = profiler.calculateTechMetrics(buildTimes);
var techPercentiles = profiler.calculateTechPercentiles(techMetrics, percentileRanks);

return {
buildTimes: buildTimes,
techMetrics: techMetricsData
techMetrics: techMetrics,
techPercentiles: techPercentiles
};
}

Expand Down
33 changes: 33 additions & 0 deletions lib/build-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
var inherit = require('inherit');
var _ = require('lodash');
var percentile = require('percentile');
var rangem = require('rangem');

/**
Expand Down Expand Up @@ -165,6 +166,38 @@ module.exports = inherit(/** @lends BuildProfiler.prototype */ {
.sort(function (a, b) {
return b.buildTime - a.buildTime;
});
},
/**
* @param {Object} techMetrics
* @param {Number[]]} percentileRanks
*
* @returns {{tech: String, percentiles: {rank: Number, value: Number}[]}[]}
*/
calculateTechPercentiles: function (techMetrics, percentileRanks) {
var sortedPercentileRanks = percentileRanks.sort(function (a, b) { return a - b; });
var maxPercentileRankIndex = sortedPercentileRanks.length - 1;

if (percentileRanks.length === 0) {
return [];
}

return techMetrics.map(function (techInfo) {
return {
tech: techInfo.tech,
percentiles: sortedPercentileRanks.map(function (percentileRank) {
return {
rank: percentileRank,
value: percentile(percentileRank, techInfo.buildTimes)
};
})
};
})
.sort(function (tech1, tech2) {
var percentiles1 = tech1.percentiles;
var percentiles2 = tech2.percentiles;

return percentiles2[maxPercentileRankIndex].value - percentiles1[maxPercentileRankIndex].value;
});
}
});

Expand Down
14 changes: 7 additions & 7 deletions lib/cli/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*
* Этот файл запускает сборку из командной строки.
*/
var assign = require('lodash').assign;

var make = require('../api').make;
var profilerUI = require('../ui/profiler-ui');
var deprecate = require('../utils/deprecate');
Expand All @@ -24,12 +22,14 @@ module.exports = function (program) {
var args = program.args.slice(0);
var opts = args.pop();

var percentileRanks = opts.profilerPercentiles = opts.profilerPercentiles
? opts.profilerPercentiles.split(',')
: [];

deprecate.initialize({ hideWarnings: opts ? opts.hideWarnings : false });

make(args, assign({ profiler: opts.profilerPercentiles }, opts))
make(args, opts)
.then(function (data) {
var percentiles = opts.profilerPercentiles ? opts.profilerPercentiles.split(',') : [];

if (opts.profiler) {
if (opts.profiler === 'targets') {
profilerUI.printTargetTable(data.buildTimes);
Expand All @@ -38,8 +38,8 @@ module.exports = function (program) {
}
}

if (percentiles.length) {
profilerUI.printTechPercentileTable(data.techMetrics, percentiles);
if (percentileRanks.length) {
profilerUI.printTechPercentileTable(data.techPercentiles, percentileRanks);
}
})
.fail(function (err) {
Expand Down
15 changes: 7 additions & 8 deletions lib/ui/profiler-ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var _ = require('lodash');
var percentile = require('percentile');
var prettyMs = require('pretty-ms');
var Table = require('cli-table');

Expand Down Expand Up @@ -38,16 +37,16 @@ module.exports = {
console.log(printTable.toString());
},

printTechPercentileTable: function (data, percentiles) {
printTechPercentileTable: function (techPercentiles, percentileRanks) {
var printTable = new Table({
head: ['Tech'].concat(percentiles)
head: ['Tech'].concat(percentileRanks.map(function (rank) {
return rank + 'th';
}))
});

_.map(data, function (techInfo) {
printTable.push([techInfo.tech].concat(percentiles.map(function (percentileNumber) {
var time = percentile(percentileNumber, techInfo.buildTimes);

return prettyMs(time);
techPercentiles.map(function (techInfo) {
printTable.push([techInfo.tech].concat(techInfo.percentiles.map(function (item) {
return prettyMs(item.value);
})));
});

Expand Down