def run_urls_without_benchmark(gc_stats)
svl = nil
begin
if ARGV.include?('-svlPV')
require 'svlRubyPV'
svl = SvlRubyPV.new
elsif ARGV.include?('-svlMV')
require 'svlRubyMV'
svl = SvlRubyMV
end
rescue LoadError
end
ruby_prof = nil
ARGV.each{|arg| ruby_prof=$1 if arg =~ /-ruby_prof=([^ ]*)/ }
begin
if ruby_prof
if benchmark_file = ENV['RAILS_BENCHMARK_FILE']
$stderr = File.open(benchmark_file, "w")
end
require 'ruby-prof'
measure_mode = "WALL_TIME"
ARGV.each{|arg| measure_mode=$1.upcase if arg =~ /-measure_mode=([^ ]*)/ }
if %w(PROCESS_TIME WALL_TIME CPU_TIME ALLOCATIONS MEMORY).include?(measure_mode)
RubyProf.measure_mode = RubyProf.const_get measure_mode
else
$stderr = STDERR
$stderr.puts "unsupported ruby_prof measure mode: #{measure_mode}"
exit(-1)
end
RubyProf.start
end
rescue LoadError
$stderr = STDERR
$stderr.puts "ruby-prof not available: giving up"
exit(-1)
end
if svl
svl.startProfiler
svl.startDataCollection
end
setup_initial_env
GC.enable_stats if gc_stats
if gc_frequency==0
run_urls_without_benchmark_and_without_gc_control(@urls, iterations)
else
run_urls_without_benchmark_but_with_gc_control(@urls, iterations, gc_frequency)
end
if gc_stats
GC.enable if gc_frequency
GC.start
GC.dump
GC.disable_stats
GC.log "number of requests processed: #{@urls.size * iterations}"
end
if ARGV.include?('-leaks')
leaks_log = "#{ENV['RAILS_PERF_DATA']}/leaks.log"
leaks_command = "leaks -nocontext #{$$} >#{leaks_log}"
ENV.delete 'MallocStackLogging'
raise "could not execute leaks command" unless system(leaks_command)
mallocs, leaks = *`head -n 2 #{leaks_log}`.split("\n").map{|l| l.gsub(/Process #{$$}: /, '')}
if mem_leaks = (leaks =~ /(\d+) leaks for (\d+) total leaked bytes/)
$stderr.puts "\n!!!!! memory leaks detected !!!!! (#{leaks_log})"
$stderr.puts "=" * leaks.length
end
if gc_stats
GC.log mallocs
GC.log leaks
end
$stderr.puts mallocs, leaks
$stderr.puts "=" * leaks.length if mem_leaks
end
svl.stopDataCollection if svl
if defined? RubyProf
GC.disable
result = RubyProf.stop
GC.enable
min_percent = ruby_prof.split('/')[0].to_f rescue 0.1
threshold = ruby_prof.split('/')[1].to_f rescue 1.0
profile_type = nil
ARGV.each{|arg| profile_type=$1 if arg =~ /-profile_type=([^ ]*)/ }
profile_type ||= 'stack'
printer =
case profile_type
when 'stack' then RubyProf::CallStackPrinter
when 'grind' then RubyProf::CallTreePrinter
when 'flat' then RubyProf::FlatPrinter
when 'graph' then RubyProf::GraphHtmlPrinter
when 'multi' then RubyProf::MultiPrinter
else raise "unknown profile type: #{profile_type}"
end.new(result)
if profile_type == 'multi'
raise "you must specify a benchmark file when using multi printer" unless $stderr.is_a?(File)
$stderr.close
$stderr = STDERR
file_name = ENV['RAILS_BENCHMARK_FILE']
profile_name = File.basename(file_name).sub('.html','').sub(".#{profile_type}",'')
printer.print(:path => File.dirname(file_name),
:profile => profile_name,
:min_percent => min_percent, :threshold => threshold,
:title => "call tree/graph for benchmark #{@benchmark}")
else
printer.print($stderr, :min_percent => min_percent, :threshold => threshold,
:title => "call tree for benchmark #{@benchmark}")
end
end
delete_test_session
delete_new_test_sessions
end