aboutsummaryrefslogtreecommitdiffstats
path: root/railties/bin/profiler
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-05-21 10:49:15 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-05-21 10:49:15 +0000
commit2bccdba9d1403ce0010b0efa317376c01236440a (patch)
tree50431ff71a7ad24be3dd4cb12ad115be76eb28bf /railties/bin/profiler
parent997eb90c90ed43c5fa291a151f8848cb5758f467 (diff)
downloadrails-2bccdba9d1403ce0010b0efa317376c01236440a.tar.gz
rails-2bccdba9d1403ce0010b0efa317376c01236440a.tar.bz2
rails-2bccdba9d1403ce0010b0efa317376c01236440a.zip
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
Diffstat (limited to 'railties/bin/profiler')
-rw-r--r--railties/bin/profiler40
1 files changed, 23 insertions, 17 deletions
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 <<end_eval
-def profile_me
- for i in 1..#{N}
- #{ARGV[0]}
- end
+if ARGV[1] and ARGV[1].to_i > 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