2
$stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
6
# Keep the expensive require out of the profile.
7
$stderr.puts 'Loading Rails...'
8
require RAILS_ROOT + '/config/environment'
10
# Define a method to profile.
11
if ARGV[1] and ARGV[1].to_i > 1
12
eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
14
eval "def profile_me() #{ARGV[0]} end"
17
# Use the ruby-prof extension if available. Fall back to stdlib profiler.
21
$stderr.puts 'Using the ruby-prof extension.'
22
RubyProf.measure_mode = RubyProf::WALL_TIME
25
results = RubyProf.stop
27
printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
29
printer_class = RubyProf::FlatPrinter
31
printer = printer_class.new(results)
32
printer.print($stderr)
35
$stderr.puts 'Using the old ruby-prof extension.'
36
Prof.clock_mode = Prof::GETTIMEOFDAY
40
require 'rubyprof_ext'
41
Prof.print_profile(results, $stderr)
45
$stderr.puts 'Using the standard Ruby profiler.'
46
Profiler__.start_profile
48
Profiler__.stop_profile
49
Profiler__.print_profile($stderr)