1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added console --profile for profiling an IRB session #1154 [bitsweat]. Changed console_sandbox into console --sandbox #1154 [bitsweat]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1261 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-04-30 15:37:45 +00:00
parent e6f3e5d900
commit 54f2d1d944
8 changed files with 57 additions and 22 deletions

View file

@ -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) *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 * Upgraded to Active Record 1.10.1, Action Pack 1.8.1, Action Mailer 0.9.1, Action Web Service 0.7.1

View file

@ -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 ) 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 ) 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 ) VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
@ -385,4 +385,4 @@ task :release => [:gem] do
first_file = false first_file = false
end end
end end
end end

View file

@ -2,15 +2,18 @@
irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb' irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
require 'optparse' require 'optparse'
options = {} options = { :sandbox => false, :profile => false, :irb => irb }
OptionParser.new do |opt| OptionParser.new do |opt|
opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |options[:sandbox]| } 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) opt.parse!(ARGV)
end end
libs = " -r #{File.dirname(__FILE__)}/../config/environment" libs = " -r irb/completion"
libs << " -r #{File.dirname(__FILE__)}/console_sandbox" if options[:sandbox] libs << " -r #{File.dirname(__FILE__)}/../config/environment"
libs << " -r irb/completion" libs << " -r console_sandbox" if options[:sandbox]
libs << " -r console_profile" if options[:profile]
ENV['RAILS_ENV'] = ARGV.first || 'development' ENV['RAILS_ENV'] = ARGV.first || 'development'
if options[:sandbox] if options[:sandbox]
@ -19,4 +22,4 @@ if options[:sandbox]
else else
puts "Loading #{ENV['RAILS_ENV']} environment." puts "Loading #{ENV['RAILS_ENV']} environment."
end end
exec "#{irb} #{libs}" exec "#{options[:irb]} #{libs} --prompt-mode simple"

View file

@ -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

View file

@ -1,17 +1,28 @@
#!/usr/local/bin/ruby #!/usr/local/bin/ruby
if ARGV.empty? if ARGV.empty?
puts "Usage: profiler 'Person.expensive_method(10)' [times]" $stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times]"
exit exit
end end
# Keep the expensive require out of the profile.
puts 'Loading Rails...'
require File.dirname(__FILE__) + '/../config/environment' require File.dirname(__FILE__) + '/../config/environment'
require "profiler"
# Don't include compilation in the profile # Default to a single execution.
eval(ARGV.first) N = (ARGV[1] || 1).to_i
Profiler__::start_profile # Define a method to profile.
(ARGV[1] || 1).to_i.times { eval(ARGV.first) } eval <<end_eval
Profiler__::stop_profile def profile_me
Profiler__::print_profile($stdout) 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

View file

@ -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

View file

@ -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

View file

@ -43,7 +43,7 @@ class AppGenerator < Rails::Generator::Base
m.file "environments/test.rb", "config/environments/test.rb" m.file "environments/test.rb", "config/environments/test.rb"
# Scripts # 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 m.file "bin/#{file}", "script/#{file}", script_options
end end
if options[:gem] if options[:gem]