Module: Mach5::Command::Benchmark

Included in:
Runner
Defined in:
lib/mach5-tools/command/benchmark.rb

Instance Method Summary collapse

Instance Method Details

#_all_benchmarksObject



35
36
37
38
39
40
41
42
# File 'lib/mach5-tools/command/benchmark.rb', line 35

def _all_benchmarks
  @config.benchmarks.commits.each do |commit|
    checkout(commit)
    before
    save(run(@config.benchmarks[commit]), commit)
    after
  end
end

#_only_benchmarks(benchmarks) ⇒ Object



17
18
19
20
21
22
# File 'lib/mach5-tools/command/benchmark.rb', line 17

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_new_benchmarksObject



44
45
46
47
48
49
# File 'lib/mach5-tools/command/benchmark.rb', line 44

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

#_run_benchmarks(benchmarks, commit) ⇒ Object



51
52
53
54
55
56
# File 'lib/mach5-tools/command/benchmark.rb', line 51

def _run_benchmarks(benchmarks, commit)
  checkout(commit)
  before
  save(run(benchmarks), commit)
  after
end

#_select_benchmarks(commit, commit_id, benchmarks) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/mach5-tools/command/benchmark.rb', line 24

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



13
14
15
# File 'lib/mach5-tools/command/benchmark.rb', line 13

def checkout(commit_id)
  Kernel.system "git checkout #{commit_id}"
end

#find_new_benchmarks(benchmarks, commit) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/mach5-tools/command/benchmark.rb', line 58

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_benchmarksObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mach5-tools/command/benchmark.rb', line 75

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

#run(benchmarks) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/mach5-tools/command/benchmark.rb', line 4

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



66
67
68
69
70
71
72
73
# File 'lib/mach5-tools/command/benchmark.rb', line 66

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