diff options
-rw-r--r-- | railties/CHANGELOG | 7 | ||||
-rw-r--r-- | railties/Rakefile | 4 | ||||
-rw-r--r-- | railties/bin/console | 13 | ||||
-rw-r--r-- | railties/bin/console_sandbox | 6 | ||||
-rw-r--r-- | railties/bin/profiler | 27 | ||||
-rw-r--r-- | railties/lib/console_profile.rb | 14 | ||||
-rw-r--r-- | railties/lib/console_sandbox.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 2 |
8 files changed, 57 insertions, 22 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 5097943d4f..5664206ed0 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,3 +1,10 @@ +*SVN* + +* Added console --profile for profiling an IRB session #1154 [bitsweat] + +* Changed console_sandbox into console --sandbox #1154 [bitsweat] + + *0.12.1* (20th April, 2005) * Upgraded to Active Record 1.10.1, Action Pack 1.8.1, Action Mailer 0.9.1, Action Web Service 0.7.1 diff --git a/railties/Rakefile b/railties/Rakefile index b8017cefe9..6d47bc7dd7 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -26,7 +26,7 @@ TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/test ) LOG_FILES = %w( server.log development.log test.log production.log ) HTML_FILES = %w( 404.html 500.html index.html favicon.ico javascripts/prototype.js ) -BIN_FILES = %w( generate destroy breakpointer console console_sandbox server update runner profiler benchmarker ) +BIN_FILES = %w( generate destroy breakpointer console server update runner profiler benchmarker ) VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties ) @@ -385,4 +385,4 @@ task :release => [:gem] do first_file = false end end -end
\ No newline at end of file +end diff --git a/railties/bin/console b/railties/bin/console index fa7acc1598..4ebcaa0b23 100644 --- a/railties/bin/console +++ b/railties/bin/console @@ -2,15 +2,18 @@ irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb' require 'optparse' -options = {} +options = { :sandbox => false, :profile => 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 -libs = " -r #{File.dirname(__FILE__)}/../config/environment" -libs << " -r #{File.dirname(__FILE__)}/console_sandbox" if options[:sandbox] -libs << " -r irb/completion" +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] @@ -19,4 +22,4 @@ if options[:sandbox] else puts "Loading #{ENV['RAILS_ENV']} environment." end -exec "#{irb} #{libs}" +exec "#{options[:irb]} #{libs} --prompt-mode simple" diff --git a/railties/bin/console_sandbox b/railties/bin/console_sandbox index 80f3dbc223..e69de29bb2 100644 --- a/railties/bin/console_sandbox +++ b/railties/bin/console_sandbox @@ -1,6 +0,0 @@ -ActiveRecord::Base.lock_mutex -ActiveRecord::Base.connection.begin_db_transaction -at_exit do - ActiveRecord::Base.connection.rollback_db_transaction - ActiveRecord::Base.unlock_mutex -end diff --git a/railties/bin/profiler b/railties/bin/profiler index f0f14a2b99..d606a76abf 100644 --- a/railties/bin/profiler +++ b/railties/bin/profiler @@ -1,17 +1,28 @@ #!/usr/local/bin/ruby if ARGV.empty? - puts "Usage: profiler 'Person.expensive_method(10)' [times]" + $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' -require "profiler" -# Don't include compilation in the profile -eval(ARGV.first) +# Default to a single execution. +N = (ARGV[1] || 1).to_i -Profiler__::start_profile -(ARGV[1] || 1).to_i.times { eval(ARGV.first) } -Profiler__::stop_profile -Profiler__::print_profile($stdout)
\ No newline at end of file +# 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 diff --git a/railties/lib/console_profile.rb b/railties/lib/console_profile.rb new file mode 100644 index 0000000000..afec28795d --- /dev/null +++ b/railties/lib/console_profile.rb @@ -0,0 +1,14 @@ +# 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 diff --git a/railties/lib/console_sandbox.rb b/railties/lib/console_sandbox.rb new file mode 100644 index 0000000000..80f3dbc223 --- /dev/null +++ b/railties/lib/console_sandbox.rb @@ -0,0 +1,6 @@ +ActiveRecord::Base.lock_mutex +ActiveRecord::Base.connection.begin_db_transaction +at_exit do + ActiveRecord::Base.connection.rollback_db_transaction + ActiveRecord::Base.unlock_mutex +end diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 765c91e406..5d0c2a7d98 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -43,7 +43,7 @@ class AppGenerator < Rails::Generator::Base m.file "environments/test.rb", "config/environments/test.rb" # Scripts - %w(console console_sandbox destroy generate server runner benchmarker profiler).each do |file| + %w(console destroy generate server runner benchmarker profiler).each do |file| m.file "bin/#{file}", "script/#{file}", script_options end if options[:gem] |