aboutsummaryrefslogblamecommitdiffstats
path: root/railties/bin/profiler
blob: d606a76abf72f5f13dd41f90007b6543a9e93360 (plain) (tree)
1
2
3
4
5
6
7
8
9


                     
                                                                      


      

                                                
                                                         
 

                                
 













                                                         
#!/usr/local/bin/ruby

if ARGV.empty?
  $stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times]"
  exit
end

# Keep the expensive require out of the profile.
puts 'Loading Rails...'
require File.dirname(__FILE__) + '/../config/environment'

# Default to a single execution.
N = (ARGV[1] || 1).to_i

# Define a method to profile.
eval <<end_eval
def profile_me
  for i in 1..#{N}
    #{ARGV[0]}
  end
end
end_eval

# Require the profiler at_exit wrapper from railties/lib.
require 'console_profile'

# Blast off!
profile_me