Module: BenchBloc::RakeHelpers

Included in:
BenchBloc
Defined in:
lib/bench_bloc/helpers/rake_helpers.rb

Instance Method Summary collapse

Instance Method Details

#add_bench_hooksObject



77
78
79
80
81
82
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 77

def add_bench_hooks
  bench_tasks.each do |task|
  Rake::Task[task.name]
    .enhance(['bench_bloc:parse_options_util', 'bench_bloc:clear_tests_util'])
  end
end

#bench_tasksObject



4
5
6
7
8
9
10
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 4

def bench_tasks
  Rake.application.tasks.select do |task|
    task.name.starts_with?("bench_bloc") &&
    !task.name.ends_with?("_util") &&
    task.name != "bench_bloc:all"
  end
end

#is_task?(obj) ⇒ Boolean



45
46
47
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 45

def is_task? obj
  obj.keys.any?(:to_prof)
end

#option_parserObject



12
13
14
15
16
17
18
19
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 12

def option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: rake bench_bloc:* [options]"
    opts.on("-r", "--ruby-prof", "Print a RubyProf report") do |rp|
      @options[:ruby_prof] = rp
    end
  end
end

#put_all_taskObject



69
70
71
72
73
74
75
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 69

def put_all_task
  desc "Run all benchmarks"
  task all: :environment do
    bench_tasks.each(&:execute)
    Rake::Task["bench_bloc:clear_tests_util"].invoke
  end
end

#put_bloc_namespaces(bloc) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 84

def put_bloc_namespaces bloc
  bloc.keys.each do |key|
    namespace :bench_bloc do
      put_namespace key, bloc[key]
      put_options_parser_task
      put_clear_tests_task
      put_all_task
    end
  end
end

#put_clear_tests_taskObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 58

def put_clear_tests_task
  desc "Clear Tests"
  task clear_tests_util: :environment do
    at_exit do
      test_ts = Timesheet.where("general_remarks LIKE '%BENCHTEST%'")
      puts "Clearing #{test_ts.count} test timesheets"
      test_ts.destroy_all
    end
  end
end

#put_namespace(key, namespace) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 21

def put_namespace key, namespace
  namespace key do
    namespace.keys.each do |ns_key|
      if is_task? namespace[ns_key]
        put_task ns_key, namespace[ns_key]
      else
        put_namespace ns_key, namespace[ns_key]
      end
    end
  end
end

#put_options_parser_taskObject



49
50
51
52
53
54
55
56
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 49

def put_options_parser_task
  desc "Options parser for bench tasks"
  task parse_options_util: :environment do
    @options = {}
    option_parser.parse!
    option_parser.parse!
  end
end

#put_task(key, new_task) ⇒ Object

TODO: Add a ruby-prof method here if argument is passed



34
35
36
37
38
39
40
41
42
43
# File 'lib/bench_bloc/helpers/rake_helpers.rb', line 34

def put_task key, new_task
  desc new_task[:desc]
  task key => :environment do
    to_profs = [new_task[:to_prof].call].flatten
    bm_results = bm_run_results new_task, to_profs
    bm_log_results bm_results, new_task[:desc]
    # run ruby-prof
    # format_ruby_prof(run_ruby_prof(new_task[:prof], tp)) if @options[:ruby_prof] == true
  end
end