class BenchBloc::Bloc::Task
Attributes
description[R]
label[R]
namespace[R]
profile[R]
title[R]
to_profile[R]
Public Class Methods
new(namespace, bloc_task)
click to toggle source
Calls superclass method
BenchBloc::Bloc::new
# File lib/bench_bloc/bloc/bloc_task.rb, line 12 def initialize namespace, bloc_task super(bloc_task) @namespace = namespace parse_bloc_task bloc_task end
Public Instance Methods
rake_task()
click to toggle source
# File lib/bench_bloc/bloc/bloc_task.rb, line 18 def rake_task desc description task namespace => :environment do BenchBloc::Logger.new(run_benchmark, description).log_results BenchBloc::Logger::RubyProf .new(run_ruby_prof, description) .log_results if @ruby_prof == true end end
Private Instance Methods
parse_bloc_task(bloc_task)
click to toggle source
# File lib/bench_bloc/bloc/bloc_task.rb, line 49 def parse_bloc_task bloc_task @description = bloc_task[:description] @label = bloc_task[:label] @profile = bloc_task[:profile] @title = bloc_task[:title] @to_profile = bloc_task[:to_profile] @ruby_prof = bloc_task[:ruby_prof] || false end
run_benchmark()
click to toggle source
# File lib/bench_bloc/bloc/bloc_task.rb, line 30 def run_benchmark Benchmark.bm do |x| [to_profile.call].flatten.each do |otp| new_label = label.call(otp) set_db_logger x.report(new_label) do profile.call(otp) end end end end
run_ruby_prof()
click to toggle source
# File lib/bench_bloc/bloc/bloc_task.rb, line 42 def run_ruby_prof rp_profile = RubyProf::Profile.new result = rp_profile.profile do @profile.call end end
set_db_logger()
click to toggle source
# File lib/bench_bloc/bloc/bloc_task.rb, line 58 def set_db_logger if defined?(Rails) ActiveRecord::Base.logger = ::Logger.new("#{Rails.root}/log/bench_bloc_#{Time.now}_db_queries.log") end end