3 if (require.main !== module) {
4 console.log('This should only be executed standalone'); // eslint-disable-line
8 var csv = require('fast-csv');
10 var metrics = require('datadog-metrics');
11 metrics.init({ prefix: 'build.benchmarks.' });
13 var os = require('os');
16 .fromStream(process.stdin, { headers: ['date', 'suite', 'benchmark', 'total', 'iterations'] })
17 .on('data', function(data) {
18 var benchmark = data.benchmark;
19 if (!benchmark) return; // Ignore bad lines
21 var tag = benchmark.replace(/^.*#/, '');
22 var tags = ['benchmark_host:' + os.hostname()]; // Can't use host
24 if (process.env.GIT_COMMIT) tags.push('commit:' + process.env.GIT_COMMIT);
25 if (process.env.GIT_BRANCH) tags.push('branch:' + process.env.GIT_BRANCH);
26 if (tag) tags.push('test:' + tag);
28 var metric = data.suite + '.' + benchmark.replace(/#.*/, '');
29 var total = parseFloat(data.total);
30 var iterations = parseInt(data.iterations, 10);
31 var avg = total / iterations;
33 if (isNaN(avg)) return; // Ignore bad lines
35 metrics.gauge(metric, avg, tags);
37 .on('end', function() {