aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-30 15:37:45 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-30 15:37:45 +0000
commit54f2d1d944bb7577ef33ab086191992210f4788c (patch)
tree2362ded764df45f2d931cfe4d5f665f580067894 /railties/lib
parente6f3e5d90017f3f642dd2f4205679cc861a8a2ab (diff)
downloadrails-54f2d1d944bb7577ef33ab086191992210f4788c.tar.gz
rails-54f2d1d944bb7577ef33ab086191992210f4788c.tar.bz2
rails-54f2d1d944bb7577ef33ab086191992210f4788c.zip
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
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/console_profile.rb14
-rw-r--r--railties/lib/console_sandbox.rb6
-rw-r--r--railties/lib/rails_generator/generators/applications/app/app_generator.rb2
3 files changed, 21 insertions, 1 deletions
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]