Skip to content

Commit

Permalink
Continuing to restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegeek committed Oct 30, 2024
1 parent 0f2f19b commit 85f1e14
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 68 deletions.
5 changes: 4 additions & 1 deletion lib/awfy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
require_relative "awfy/version"
require_relative "awfy/suite"
require_relative "awfy/options"
require_relative "awfy/git"
require_relative "awfy/runner"
require_relative "awfy/run"
require_relative "awfy/run_report"
require_relative "awfy/list"
require_relative "awfy/ips"
require_relative "awfy/memory"
require_relative "awfy/cli"

module Awfy
Expand Down
49 changes: 5 additions & 44 deletions lib/awfy/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ def self.exit_on_failure? = true

desc "list [GROUP]", "List all tests in a group"
def list(group = nil)
runner.start(group) { List.perform(_1, shell) }
runner.start(group) { List.new(shell).list(_1) }
end

desc "ips [GROUP] [REPORT] [TEST]", "Run IPS benchmarks. Can generate summary across implementations, runtimes and branches."
def ips(group = nil, report = nil, test = nil)
say "Running IPS for:"
say "> #{requested_tests(group, report, test)}..."

run_pref_test(group) { run_ips(_1, report, test) }
runner.start(group) { IPS.new(shell).benchmark(_1, report, test) }
end

desc "memory [GROUP] [REPORT] [TEST]", "Run memory profiling. Can generate summary across implementations, runtimes and branches."
def memory(group = nil, report = nil, test = nil)
say "Running memory profiling for:"
say "> #{requested_tests(group, report, test)}..."

run_pref_test(group) { run_memory(_1, report, test) }
runner.start(group) { Memory.new(shell).benchmark(_1, report, test) }
end

desc "flamegraph GROUP REPORT TEST", "Run flamegraph profiling"
Expand Down Expand Up @@ -72,6 +72,8 @@ def profile(group = nil, report = nil, test = nil)
def awfy_options
Options.new(
verbose: options[:verbose],
summary: options[:summary],
summary_format: "descending", # TODO
temp_output_directory: options[:temp_output_directory],
setup_file_path: options[:setup_file_path],
tests_path: options[:tests_path],
Expand All @@ -91,42 +93,6 @@ def requested_tests(group, report = nil, test = nil)
tests.join("/")
end

def run_pref_test(group, &)
configure_benchmark_run
prepare_output_directory
if group
run_group(group, &)
else
run_groups(&)
end
end

def run_groups(&)
current_groups.keys.each do |group_name|
run_group(group_name, &)
end
end

def current_groups
@current_groups ||= Awfy.groups.dup.freeze
end

def run_group(group_name)
group = current_groups[group_name]
raise "Group not found" unless group
yield group
end

def list_group(group)
say "> #{group[:name]}"
group[:reports].each do |report|
say " - #{report[:name]}"
report[:tests].each do |test|
say " Test: #{test[:name]}"
end
end
end

def run_ips(group, report_name, test_name)
if verbose?
say "> IPS for:"
Expand Down Expand Up @@ -289,11 +255,6 @@ def generate_flamegraph(label = nil, open: true, ignore_gc: false, interval: 100
result
end

def prepare_output_directory
FileUtils.mkdir_p(temp_dir) unless Dir.exist?(temp_dir)
Dir.glob("#{temp_dir}/*.json").each { |file| File.delete(file) }
end

def save_memory_profile_report_to_file(file_name, results)
data = results.map do |label_and_data|
result = label_and_data[:data]
Expand Down
9 changes: 9 additions & 0 deletions lib/awfy/git.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Awfy
class Git
def initialize(path)
@client = Git.open(path)
end
end
end
12 changes: 12 additions & 0 deletions lib/awfy/ips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Awfy
class IPS
def initialize(shell)
@shell = shell
end

def benchmark(group, report, test)
end
end
end
17 changes: 6 additions & 11 deletions lib/awfy/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

module Awfy
class List
def self.perform(group, shell)
new(group, shell).perform
end

def initialize(group, shell)
@group = group
def initialize(shell)
@shell = shell
end

def perform
say "> #{@group[:name]}"
@group[:reports].each do |report|
say " - #{report[:name]}"
def list(group)
say "> \"#{group[:name]}\":"
group[:reports].each do |report|
say " \"#{report[:name]}\""
report[:tests].each do |test|
say " Test: #{test[:name]}"
say " | #{test[:control] ? "Control" : "Test"}: \"#{test[:name]}\""
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/awfy/memory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Awfy
class Memory
def initialize(shell)
@shell = shell
end

def benchmark(group, report, test)
end
end
end
24 changes: 13 additions & 11 deletions lib/awfy/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module Awfy
class Options
def initialize(verbose:, temp_output_directory:, setup_file_path:, tests_path:, compare_with_branch:, assert:, runtime:)
def initialize(verbose:, summary:, summary_format:, temp_output_directory:, setup_file_path:, tests_path:, compare_with_branch:, assert:, runtime:)
@verbose = verbose
@summary = summary
@summary_format = summary_format
@temp_output_directory = temp_output_directory
@setup_file_path = setup_file_path
@tests_path = tests_path
Expand All @@ -12,18 +14,18 @@ def initialize(verbose:, temp_output_directory:, setup_file_path:, tests_path:,
@runtime = runtime
end

def verbose?
@verbose
end
def yjit_only? = runtime == "yjit"

def assert?
@assert
end
def both_runtimes? = runtime == "both"

def humanized_runtime
@runtime.upcase
end
def show_summary? = @summary

def verbose? = @verbose

def assert? = @assert

def humanized_runtime = @runtime.upcase

attr_reader :temp_output_directory, :setup_file_path, :tests_path, :compare_with_branch, :runtime
attr_reader :temp_output_directory, :setup_file_path, :tests_path, :compare_with_branch, :runtime, :summary_format
end
end
16 changes: 16 additions & 0 deletions lib/awfy/run_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Awfy
class RunReport
def initialize(group, report, shell, git_client, options)
@group = group
@report = report
@shell = shell
@git_client = git_client
@options = options
end

def start(&)
end
end
end
3 changes: 2 additions & 1 deletion lib/awfy/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def run_groups(&)

def run_group(group_name, &)
group = @groups[group_name]
Run.new(group, shell, git_client, options).start(&)
raise "Group '#{group_name}' not found" unless group
yield group
end

private
Expand Down

0 comments on commit 85f1e14

Please sign in to comment.