aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-03-30 03:23:16 +0100
committerGonçalo Silva <goncalossilva@gmail.com>2011-03-30 03:23:16 +0100
commit09cdd1cac149cf8e18f16e39937d659146e61f70 (patch)
treec12e5237938e41de7adc347a7ce558fde0955c4f
parent391ccdaf35f41e38905a940a72e30b484cb0baf9 (diff)
downloadrails-09cdd1cac149cf8e18f16e39937d659146e61f70.tar.gz
rails-09cdd1cac149cf8e18f16e39937d659146e61f70.tar.bz2
rails-09cdd1cac149cf8e18f16e39937d659146e61f70.zip
check if there is support for the specified metric when profiling
-rw-r--r--activesupport/lib/active_support/testing/performance.rb18
-rw-r--r--activesupport/lib/active_support/testing/performance/jruby.rb15
-rw-r--r--activesupport/lib/active_support/testing/performance/rubinius.rb15
-rw-r--r--activesupport/lib/active_support/testing/performance/ruby.rb8
4 files changed, 32 insertions, 24 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 71d49459ef..5e9bc40976 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -10,12 +10,10 @@ module ActiveSupport
# each implementation should define metrics and freeze the defaults
DEFAULTS =
if ARGV.include?('--benchmark') # HAX for rake test
- { :benchmark => true,
- :runs => 4,
+ { :runs => 4,
:output => 'tmp/performance' }
else
- { :benchmark => false,
- :runs => 1,
+ { :runs => 1,
:output => 'tmp/performance' }
end
@@ -87,7 +85,7 @@ module ActiveSupport
end
def run_profile(metric)
- klass = full_profile_options[:benchmark] ? Benchmarker : Profiler
+ klass = ARGV.include?('--benchmark') ? Benchmarker : Profiler
performer = klass.new(self, metric)
performer.run
@@ -117,10 +115,18 @@ module ActiveSupport
class Profiler < Performer
def initialize(*args)
super
+ @supported = false
+ end
+
+ def report
+ if @supported
+ super
+ else
+ '%20s: unsupported' % @metric.name
+ end
end
def run; end
- def report; end
def record; end
end
diff --git a/activesupport/lib/active_support/testing/performance/jruby.rb b/activesupport/lib/active_support/testing/performance/jruby.rb
index b76c11f12b..6993db1a3b 100644
--- a/activesupport/lib/active_support/testing/performance/jruby.rb
+++ b/activesupport/lib/active_support/testing/performance/jruby.rb
@@ -10,7 +10,7 @@ module ActiveSupport
{:metrics => [:wall_time, :user_time, :memory, :gc_runs, :gc_time]}
else
{ :metrics => [:wall_time],
- :formats => [:flat, :graph] }
+ :formats => [:flat, :graph] }
end).freeze
protected
@@ -21,7 +21,14 @@ module ActiveSupport
class Performer; end
class Profiler < Performer
+ def initialize(*args)
+ super
+ @supported = @metric.is_a?(Metrics::WallTime)
+ end
+
def run
+ return unless @supported
+
@data = JRuby::Profiler.profile do
full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
end
@@ -32,11 +39,9 @@ module ActiveSupport
@total = @data.getDuration / 1000 / 1000 / 1000.0 # seconds
end
- def report
- super
- end
-
def record
+ return unless @supported
+
klasses = full_profile_options[:formats].map { |f| JRuby::Profiler.const_get("#{f.to_s.camelize}ProfilePrinter") }.compact
klasses.each do |klass|
diff --git a/activesupport/lib/active_support/testing/performance/rubinius.rb b/activesupport/lib/active_support/testing/performance/rubinius.rb
index 547b7cf048..b2e77b3ce9 100644
--- a/activesupport/lib/active_support/testing/performance/rubinius.rb
+++ b/activesupport/lib/active_support/testing/performance/rubinius.rb
@@ -18,8 +18,15 @@ module ActiveSupport
class Performer; end
- class Profiler < Performer
+ class Profiler < Performer
+ def initialize(*args)
+ super
+ @supported = @metric.is_a?(Metrics::WallTime)
+ end
+
def run
+ return unless @supported
+
@profiler = Rubinius::Profiler::Instrumenter.new
@profiler.profile(false) do
@@ -29,11 +36,9 @@ module ActiveSupport
@total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds
end
- def report
- super
- end
-
def record
+ return unless @supported
+
if(full_profile_options[:formats].include?(:flat))
create_path_and_open_file(:flat) do |file|
@profiler.show(file)
diff --git a/activesupport/lib/active_support/testing/performance/ruby.rb b/activesupport/lib/active_support/testing/performance/ruby.rb
index d08eedc653..e887af1979 100644
--- a/activesupport/lib/active_support/testing/performance/ruby.rb
+++ b/activesupport/lib/active_support/testing/performance/ruby.rb
@@ -41,14 +41,6 @@ module ActiveSupport
@total = @data.threads.values.sum(0) { |method_infos| method_infos.max.total_time }
end
- def report
- if @supported
- super
- else
- '%20s: unsupported' % @metric.name
- end
- end
-
def record
return unless @supported