Fix up Rubinius specific library specs.
[rbx.git] / bin / bm-automatic
blobaee2a6259aee3ac094262fe376bcd6dd988bba4d
1 #!/usr/bin/env ruby
3 require 'parsedate'
4 require 'tempfile'
6 # Options handling
7 require 'optparse'
8 require 'ostruct'
10 TEST_AFTER_REVISION = 'c7a7d86bdbc8c4a7351cb7142c90e74a6ef08515'
12 OPTIONS = OpenStruct.new
14 options = OptionParser.new do |opts|
15 opts.on('-h', '--help', 'Output this help information') do |h|
16 OPTIONS.help = h
17 end
19 opts.on('-r', '--results PATH', 'Path to results') do |r|
20 OPTIONS.results = r
21 end
22 end
24 options.parse!
26 if OPTIONS.help or not OPTIONS.results then
27 puts options.summarize
28 exit
29 end
31 class Commit
32 attr_reader :commit, :working_path, :results_path, :final_path
34 def initialize(commit)
35 @commit = commit
36 @working_path = Tempfile.new('rbx-working-').path
37 @results_path = Tempfile.new('rbx-results-').path
38 @final_path = OPTIONS.results + '/' + @commit + '/'
39 end
41 def date
42 matches = `git log --pretty=fuller #{commit}`.split(/\n/)[4].match(/: +(.+ \d\d\d\d) ([+-]\d\d)(\d\d)/)
43 date = ParseDate.parsedate(matches[1])
44 puts matches[2].to_i * 3600 + matches[3].to_i
45 Time.gm(*date) + matches[2].to_i * 3600 + matches[3].to_i
46 end
48 def date_string
49 d = date
50 "#{d.year}-#{'%02d' % d.month}-#{'%02d' % d.day}-" +
51 "#{'%02d' % d.hour}-#{'%02d' % d.min}-#{'%02d' % d.sec}"
52 end
54 def complete?
55 File.directory?(final_path)
56 end
58 def cleanup
59 execute "rm -rf #{working_path}",false
60 execute "rm -rf #{results_path}",false
61 end
63 def benchmark
64 begin
65 execute "git clone git://git.rubini.us/code #{working_path}"
67 Dir.chdir working_path
68 execute 'rake build'
70 Dir.mkdir results_path
71 execute "bin/bm -c -d -f -p #{results_path} -w >/dev/null 2>&1"
73 execute "mv #{results_path} #{final_path}"
74 rescue
75 warn "Failed during benchmark"
76 ensure
77 cleanup
78 end
79 end
80 end
82 def execute(command,raise_error = true)
83 puts command
84 unless system command then
85 warn $!
87 if raise_error
88 raise RunTimeError,$!
89 end
90 end
91 end
93 def benchmarkable_commits
94 commits = []
96 `git log`.grep(/^commit/).each do |line|
97 break if line =~ /#{TEST_AFTER_REVISION}$/
98 commit = Commit.new(line.match(/\w+$/)[0])
99 break if commit.complete?
100 commits << commit
103 commits.reverse
106 while true do
107 benchmarkable_commits.each { |commit| commit.benchmark }
108 sleep 60