Skip to content

Commit

Permalink
include FS usage monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Sep 1, 2015
1 parent b5c1ed2 commit 0816de6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
41 changes: 38 additions & 3 deletions lib/models/builder.js
Expand Up @@ -13,8 +13,31 @@ var attemptNeverIndex = require('../utilities/attempt-never-index');
var deprecate = require('../utilities/deprecate');
var findBuildFile = require('../utilities/find-build-file');
var viz = require('broccoli-viz');
var FSMonitor = require('fs-monitor-stack');

var signalsTrapped = false;
var buildCount = 0;

function outputViz(count, result, monitor) {
var processed = viz.process(result.graph);

processed.forEach(function(node) {
node.stats.fs = monitor.statsFor(node);
});

fs.writeFileSync('graph.' + count + '.dot', viz.dot(processed));
fs.writeFileSync('graph.' + count + '.json', JSON.stringify({
summary: {
output: result.directory,
totalTime: result.totalTime,
totalNodes: processed.length,
stats: {
fs: monitor.totalStats()
}
},
nodes: processed
}));
}

module.exports = Task.extend({
setupBroccoliBuilder: function() {
Expand All @@ -36,6 +59,20 @@ module.exports = Task.extend({
}

this.builder = new broccoli.Builder(this.tree);

var builder = this;

this.builder.on('start', function() {
builder.monitor = new FSMonitor();
});

this.builder.on('nodeStart', function(node) {
builder.monitor.push(node);
});

this.builder.on('nodeEnd', function() {
builder.monitor.pop();
});
},

trapSignals: function() {
Expand Down Expand Up @@ -147,9 +184,7 @@ module.exports = Task.extend({
})
.then(function(result) {
if (process.env.BROCCOLI_VIZ) {
var processed = viz.process(result.graph);
fs.writeFileSync('graph.dot', viz.dot(processed));
fs.writeFileSync('graph.json', JSON.stringify(processed));
outputViz(buildCount++, result, self.monitor);
}
return result;
})
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -73,7 +73,7 @@
"bower": "^1.3.12",
"bower-config": "0.6.1",
"bower-endpoint-parser": "0.2.2",
"broccoli": "0.16.5",
"broccoli": "broccolijs/broccoli#hooks",
"broccoli-caching-writer": "^1.1.0",
"broccoli-clean-css": "0.2.0",
"broccoli-es3-safe-recast": "^2.0.0",
Expand Down Expand Up @@ -112,6 +112,7 @@
"findup": "0.1.5",
"findup-sync": "^0.2.1",
"fs-extra": "0.22.1",
"fs-monitor-stack": "^1.0.2",
"git-repo-info": "^1.0.4",
"github": "^0.2.3",
"glob": "5.0.13",
Expand Down

0 comments on commit 0816de6

Please sign in to comment.