Froze rails gems
[depot.git] / vendor / rails / railties / lib / commands / performance / profiler.rb
1 if ARGV.empty?
2 $stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
3 exit(1)
4 end
5
6 # Keep the expensive require out of the profile.
7 $stderr.puts 'Loading Rails...'
8 require RAILS_ROOT + '/config/environment'
9
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"
13 else
14 eval "def profile_me() #{ARGV[0]} end"
15 end
16
17 # Use the ruby-prof extension if available. Fall back to stdlib profiler.
18 begin
19 begin
20 require "ruby-prof"
21 $stderr.puts 'Using the ruby-prof extension.'
22 RubyProf.measure_mode = RubyProf::WALL_TIME
23 RubyProf.start
24 profile_me
25 results = RubyProf.stop
26 if ARGV[2]
27 printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
28 else
29 printer_class = RubyProf::FlatPrinter
30 end
31 printer = printer_class.new(results)
32 printer.print($stderr, 0)
33 rescue LoadError
34 require "prof"
35 $stderr.puts 'Using the old ruby-prof extension.'
36 Prof.clock_mode = Prof::GETTIMEOFDAY
37 Prof.start
38 profile_me
39 results = Prof.stop
40 require 'rubyprof_ext'
41 Prof.print_profile(results, $stderr)
42 end
43 rescue LoadError
44 require 'profiler'
45 $stderr.puts 'Using the standard Ruby profiler.'
46 Profiler__.start_profile
47 profile_me
48 Profiler__.stop_profile
49 Profiler__.print_profile($stderr)
50 end