diff options
author | kpdecker <kpdecker@gmail.com> | 2013-08-25 14:14:33 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-08-25 14:14:33 -0500 |
commit | 672aeda17f9309ad7e4d31ef1c3b9a302fbb5baf (patch) | |
tree | 7459fe83e58ae9d12d2e699eaa46528587015bc8 | |
parent | 74369f724c1cf5d658736bd581348677f464f76c (diff) | |
download | handlebars.js-672aeda17f9309ad7e4d31ef1c3b9a302fbb5baf.zip handlebars.js-672aeda17f9309ad7e4d31ef1c3b9a302fbb5baf.tar.gz handlebars.js-672aeda17f9309ad7e4d31ef1c3b9a302fbb5baf.tar.bz2 |
Metrics collection framework
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | Gruntfile.js | 12 | ||||
-rw-r--r-- | bench/index.js | 14 | ||||
-rw-r--r-- | tasks/metrics.js | 63 |
4 files changed, 79 insertions, 11 deletions
diff --git a/.travis.yml b/.travis.yml index 6eace31..5c62e30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ script: after_success: - grunt publish + - grunt metrics email: on_failure: change diff --git a/Gruntfile.js b/Gruntfile.js index 25e24c5..a332716 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -87,17 +87,7 @@ module.exports = function(grunt) { done(); }); }); - grunt.registerTask('bench', function() { - var done = this.async(); - - var runner = childProcess.fork('./bench/handlebars', [], {stdio: 'inherit'}); - runner.on('close', function(code) { - if (code != 0) { - grunt.fatal(code + ' tests failed'); - } - done(); - }); - }); + grunt.registerTask('bench', ['metrics']); grunt.registerTask('build', ['jshint', 'parser', 'dist-dir', 'concat', 'uglify', 'test']); grunt.registerTask('default', 'build'); diff --git a/bench/index.js b/bench/index.js new file mode 100644 index 0000000..462b046 --- /dev/null +++ b/bench/index.js @@ -0,0 +1,14 @@ +var fs = require('fs'); + +var metrics = fs.readdirSync(__dirname); +metrics.forEach(function(metric) { + if (metric === 'index.js' || !/(.*)\.js$/.test(metric)) { + return; + } + + var name = RegExp.$1; + metric = require('./' + name); + if (metric instanceof Function) { + module.exports[name] = metric; + } +}); diff --git a/tasks/metrics.js b/tasks/metrics.js new file mode 100644 index 0000000..c4a202b --- /dev/null +++ b/tasks/metrics.js @@ -0,0 +1,63 @@ +var _ = require('underscore'), + async = require('async'), + git = require('./util/git'), + Keen = require('keen.io'), + metrics = require('../bench'); + +module.exports = function(grunt) { + grunt.registerTask('metrics', function() { + var done = this.async(), + execName = grunt.option('name'), + events = {}, + + projectId = process.env.KEEN_PROJECTID, + writeKey = process.env.KEEN_WRITEKEY, + keen; + + if (!execName && projectId && writeKey) { + keen = Keen.configure({ + projectId: projectId, + writeKey: writeKey + }); + } + + async.each(_.keys(metrics), function(name, complete) { + if (/^_/.test(name) || (execName && name !== execName)) { + return complete(); + } + + metrics[name](grunt, function(data) { + events[name] = data; + complete(); + }); + }, + function() { + if (!keen) { + return done(); + } + + emit(keen, events, function(err, res) { + if (err) { + throw err; + } + + grunt.log.writeln('Metrics recorded.'); + done(); + }); + }); + }); +}; +function emit(keen, collections, callback) { + git.commitInfo(function(err, info) { + _.each(collections, function(collection) { + _.each(collection, function(event) { + if (info.tagName) { + event.tag = info.tagName; + } + event.sha = info.head; + }); + }); + + keen.addEvents(collections, callback); + }); +} |