From 54f2d1d944bb7577ef33ab086191992210f4788c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 30 Apr 2005 15:37:45 +0000 Subject: 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 --- railties/lib/console_profile.rb | 14 ++++++++++++++ railties/lib/console_sandbox.rb | 6 ++++++ .../generators/applications/app/app_generator.rb | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 railties/lib/console_profile.rb create mode 100644 railties/lib/console_sandbox.rb (limited to 'railties/lib') 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] -- cgit v1.2.3