From 2bccdba9d1403ce0010b0efa317376c01236440a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 21 May 2005 10:49:15 +0000 Subject: Made the console and profiler work with the default 1.8.2 profiler #1325 [bitsweat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1339 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/bin/console | 4 +--- railties/bin/profiler | 40 +++++++++++++++++++++++----------------- railties/lib/console_profile.rb | 14 -------------- 3 files changed, 24 insertions(+), 34 deletions(-) (limited to 'railties') diff --git a/railties/bin/console b/railties/bin/console index 4ebcaa0b23..eece24a9ca 100644 --- a/railties/bin/console +++ b/railties/bin/console @@ -2,10 +2,9 @@ irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb' require 'optparse' -options = { :sandbox => false, :profile => false, :irb => irb } +options = { :sandbox => false, :irb => irb } OptionParser.new do |opt| opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |options[:sandbox]| } - opt.on('--profile', 'Profile the session and print results on exit.') { |options[:profile]| } opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |options[:irb]| } opt.parse!(ARGV) end @@ -13,7 +12,6 @@ end libs = " -r irb/completion" libs << " -r #{File.dirname(__FILE__)}/../config/environment" libs << " -r console_sandbox" if options[:sandbox] -libs << " -r console_profile" if options[:profile] ENV['RAILS_ENV'] = ARGV.first || 'development' if options[:sandbox] diff --git a/railties/bin/profiler b/railties/bin/profiler index d606a76abf..d8927a1c49 100644 --- a/railties/bin/profiler +++ b/railties/bin/profiler @@ -1,28 +1,34 @@ #!/usr/local/bin/ruby - if ARGV.empty? $stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times]" - exit + exit(1) end # Keep the expensive require out of the profile. -puts 'Loading Rails...' +$stderr.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 < 1 + eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end" +else + eval "def profile_me() #{ARGV[0]} end" end -end_eval -# Require the profiler at_exit wrapper from railties/lib. -require 'console_profile' - -# Blast off! -profile_me +# Use the ruby-prof extension if available. Fall back to stdlib profiler. +begin + require 'prof' + $stderr.puts 'Using the ruby-prof extension.' + Prof.clock_mode = Prof::GETTIMEOFDAY + Prof.start + profile_me + results = Prof.stop + require 'rubyprof_ext' + Prof.print_profile(results, $stderr) +rescue LoadError + $stderr.puts 'Using the standard Ruby profiler.' + Profiler__.start_profile + profile_me + Profiler__.stop_profile + Profiler__.print_profile($stderr) +end diff --git a/railties/lib/console_profile.rb b/railties/lib/console_profile.rb index afec28795d..e69de29bb2 100644 --- a/railties/lib/console_profile.rb +++ b/railties/lib/console_profile.rb @@ -1,14 +0,0 @@ -# No GC nonsense. -GC.disable - -# Try to load the ruby-prof extension; fail back to the pure-Ruby -# profiler included in the standard library. -begin - require 'prof' - Prof.clock_mode = Prof::CPU - puts 'Using the fast ruby-prof extension' - require 'unprof' -rescue LoadError - puts 'Using the slow pure-Ruby profiler' - require 'profile' -end -- cgit v1.2.3