Class: Mach5::Runner
- Inherits:
-
Object
- Object
- Mach5::Runner
- Defined in:
- lib/mach5-tools/runner.rb
Instance Method Summary collapse
- #_all_benchmarks ⇒ Object
- #_all_charts ⇒ Object
- #_check_benchmarks(chart) ⇒ Object
- #_generate_chart(chart) ⇒ Object
- #_only_benchmarks(benchmarks) ⇒ Object
- #_only_charts(charts) ⇒ Object
- #_only_new_benchmarks ⇒ Object
- #_only_new_charts ⇒ Object
- #_run_benchmarks(benchmarks, commit) ⇒ Object
- #_select_benchmarks(commit, commit_id, benchmarks) ⇒ Object
- #checkout(commit_id) ⇒ Object
- #find_new_benchmarks(benchmarks, commit) ⇒ Object
-
#initialize(config) ⇒ Runner
constructor
A new instance of Runner.
- #list_benchmarks ⇒ Object
- #list_charts ⇒ Object
- #run(benchmarks) ⇒ Object
- #save(json, commit) ⇒ Object
Constructor Details
#initialize(config) ⇒ Runner
Returns a new instance of Runner.
5 6 7 |
# File 'lib/mach5-tools/runner.rb', line 5 def initialize(config) @config = config end |
Instance Method Details
#_all_benchmarks ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/mach5-tools/runner.rb', line 56 def _all_benchmarks @config.benchmarks.commits.each do |commit| checkout(commit) before save(run(@config.benchmarks[commit]), commit) after end end |
#_all_charts ⇒ Object
79 80 81 82 83 |
# File 'lib/mach5-tools/runner.rb', line 79 def _all_charts @config.charts.each do |chart| _generate_chart(chart) end end |
#_check_benchmarks(chart) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mach5-tools/runner.rb', line 107 def _check_benchmarks(chart) benchmarks = [] chart.series.each do |benchmark| filename = "" if @config.benchmarks.tagged[benchmark[:commit_id]] filename = "#{File.join(@config.output_folder, @config.benchmarks.tagged[benchmark[:commit_id]])}.#{benchmark[:benchmark_id]}.json" else filename = "#{File.join(@config.output_folder, benchmark[:commit_id])}.#{benchmark[:benchmark_id]}.json" end unless File.exists?(filename) benchmarks << "#{benchmark[:commit_id]}.#{benchmark[:benchmark_id]}" end end benchmarks end |
#_generate_chart(chart) ⇒ Object
101 102 103 104 105 |
# File 'lib/mach5-tools/runner.rb', line 101 def _generate_chart(chart) benchmarks = _check_benchmarks(chart) _only_benchmarks(benchmarks) if benchmarks.size > 0 Kernel.system "phantomjs #{File.join(File.dirname(__FILE__), "js/chart.js")} #{File.join(File.dirname(__FILE__), "js")} \"[#{chart.build.to_json.gsub("\"", "\\\"")}]\" #{File.join(@config.output_folder, chart.id)}.png" end |
#_only_benchmarks(benchmarks) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mach5-tools/runner.rb', line 38 def _only_benchmarks(benchmarks) @config.benchmarks.commits.each do |commit| selected_benchmarks = _select_benchmarks(commit, @config.benchmarks.has_tag?(commit), benchmarks) _run_benchmarks(selected_benchmarks, commit) if selected_benchmarks.size > 0 end end |
#_only_charts(charts) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/mach5-tools/runner.rb', line 85 def _only_charts(charts) @config.charts.each do |chart| if charts.include? chart.id _generate_chart(chart) end end end |
#_only_new_benchmarks ⇒ Object
65 66 67 68 69 70 |
# File 'lib/mach5-tools/runner.rb', line 65 def _only_new_benchmarks @config.benchmarks.commits.each do |commit| new_benchmarks = find_new_benchmarks(@config.benchmarks[commit], commit) _run_benchmarks(new_benchmarks, commit) if new_benchmarks.size > 0 end end |
#_only_new_charts ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/mach5-tools/runner.rb', line 93 def _only_new_charts @config.charts.each do |chart| unless File.exists?("#{File.join(@config.output_folder, chart.id)}.png") _generate_chart(chart) end end end |
#_run_benchmarks(benchmarks, commit) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/mach5-tools/runner.rb', line 72 def _run_benchmarks(benchmarks, commit) checkout(commit) before save(run(benchmarks), commit) after end |
#_select_benchmarks(commit, commit_id, benchmarks) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mach5-tools/runner.rb', line 45 def _select_benchmarks(commit, commit_id, benchmarks) selected_benchmarks = [] @config.benchmarks[commit].each do |benchmark| without_tag = "#{commit}.#{benchmark}" with_tag = "#{commit_id}.#{benchmark}" selected_benchmarks << benchmark if benchmarks.include?(without_tag) selected_benchmarks << benchmark if benchmarks.include?(with_tag) and commit_id end selected_benchmarks end |
#checkout(commit_id) ⇒ Object
140 141 142 |
# File 'lib/mach5-tools/runner.rb', line 140 def checkout(commit_id) Kernel.system "git checkout #{commit_id}" end |
#find_new_benchmarks(benchmarks, commit) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/mach5-tools/runner.rb', line 123 def find_new_benchmarks(benchmarks, commit) new_benchmarks = [] benchmarks.each do |benchmark| new_benchmarks << benchmark unless File.exists?(File.join(@config.output_folder, "#{commit}.#{benchmark}.json")) end new_benchmarks end |
#list_benchmarks ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mach5-tools/runner.rb', line 144 def list_benchmarks benchmark_list = [] @config.benchmarks.commits.each do |commit| commit_id = @config.benchmarks.has_tag?(commit) commit_id = commit unless commit_id @config.benchmarks[commit].each do |benchmark| benchmark_list << "#{commit_id}.#{benchmark}" end end benchmark_list end |
#list_charts ⇒ Object
156 157 158 |
# File 'lib/mach5-tools/runner.rb', line 156 def list_charts @config.charts.map(&:id) end |
#run(benchmarks) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mach5-tools/runner.rb', line 17 def run(benchmarks) results = "" @config.run_commands.each do |command| output = IO.popen "#{command} --color --json run #{benchmarks.join(' ')}" results = output.readlines.join end JSON.parse(results) end |
#save(json, commit) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/mach5-tools/runner.rb', line 131 def save(json, commit) Dir.mkdir(@config.output_folder) unless Dir.exists?(@config.output_folder) json.each do |key, value| File.open(File.join(@config.output_folder, "#{commit}.#{key}.json"), "w") do |f| f.write(value.to_json) end end end |