Last active
December 11, 2015 20:28
-
-
Save indutny/4655489 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Place in the folder with node's source and run following in bash: | |
// $ node graph.js 60bf2d6 0d7a021 > graph.log | |
// | |
var child_process = require('child_process'), | |
exec = child_process.exec; | |
var start = process.argv[2]; | |
var end = process.argv[3]; | |
var bench = process.argv[4]; | |
getCommits(start, end, function(err, commits) { | |
if (err) throw err; | |
var i = 0; | |
function run(callback) { | |
if (i >= commits.length) return callback(null); | |
var rev = commits[i++]; | |
console.error('[-] %s - building', rev); | |
build(rev, function(err) { | |
if (err) { | |
console.error(err); | |
return run(callback); | |
} | |
console.error('[+] %s - built', rev); | |
benchmark(rev, function(err) { | |
if (err) { | |
console.error(err); | |
return run(callback); | |
} | |
console.error('[+] %s - benchmarked', rev); | |
// Loop | |
run(callback); | |
}); | |
}); | |
} | |
run(function(err) { | |
if (err) throw err; | |
console.error('!!!!!!FINISHED!!!!!'); | |
}); | |
}); | |
function getCommits(start, end, callback) { | |
exec('git log --oneline ' + start + '..' + end, function(err, stdout) { | |
if (err) return callback(err); | |
var failed = false, | |
commits = stdout.split(/\r?\n/g).filter(function(line) { | |
return line; | |
}).map(function(line) { | |
var match = line.match(/^([\da-f]+) /); | |
if (match === null) { | |
failed = line; | |
return null; | |
} | |
return match[1]; | |
}); | |
if (failed) return callback(new Error('Match failed for: ' + failed)); | |
callback(null, commits); | |
}); | |
}; | |
function build(rev, callback) { | |
var cmd = 'git checkout ' + rev + ' && ./configure && make -j24 > /dev/null'; | |
exec(cmd, callback); | |
}; | |
function benchmark(rev, callback) { | |
var cmd = './node benchmark/http_simple_auto -c 250 -n 200000 bytes/1024'; | |
exec(cmd, function(err, stdout, stderr) { | |
if (err) return callback(err); | |
var rps = 0; | |
var match = stdout.split(/\r?\n/g).filter(function(line) { | |
return line; | |
}).some(function(line) { | |
var match = line.match(/^Requests per second:\s+(\d+\.\d+|\d+) /); | |
if (match === null) return false; | |
rps = parseFloat(match[1]); | |
return true; | |
}); | |
if (!match) { | |
console.error(stdout); | |
console.error(stderr); | |
return callback(new Error('Benchmarking failed')); | |
} | |
console.log('%s - %d', rev, rps); | |
callback(null); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment