diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-09 23:29:00 +0100 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-05-09 23:29:00 +0100 |
commit | 0d1f7584ba25e7289871b5503f010874bc2aef49 (patch) | |
tree | 9cb05b3b5d06807a9050e157b62a2bf49daadefc | |
parent | a43f95d235190139159dab3cf4863252b0e9bf0e (diff) | |
download | rails-0d1f7584ba25e7289871b5503f010874bc2aef49.tar.gz rails-0d1f7584ba25e7289871b5503f010874bc2aef49.tar.bz2 rails-0d1f7584ba25e7289871b5503f010874bc2aef49.zip |
contemplate unsupported metrics
3 files changed, 18 insertions, 30 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 4e58b6a564..b62d9b16e1 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -142,12 +142,16 @@ module ActiveSupport delegate :run_test, :full_profile_options, :full_test_name, :to => :@harness def initialize(harness, metric) - @harness, @metric = harness, metric + @harness, @metric, @supported = harness, metric, false end def report - rate = @total / full_profile_options[:runs] - '%20s: %s' % [@metric.name, @metric.format(rate)] + if @supported + rate = @total / full_profile_options[:runs] + '%20s: %s' % [@metric.name, @metric.format(rate)] + else + '%20s: unsupported' % @metric.name + end end protected @@ -158,19 +162,6 @@ module ActiveSupport # overridden by each implementation class Profiler < Performer - def initialize(*args) - super - @supported = false - end - - def report - if @supported - super - else - '%20s: unsupported' % @metric.name - end - end - def time_with_block before = Time.now yield @@ -181,8 +172,15 @@ module ActiveSupport def record; end end - class Benchmarker < Performer + class Benchmarker < Performer + def initialize(*args) + super + @supported = @metric.respond_to?('measure') + end + def run + return unless @supported + full_profile_options[:runs].to_i.times { run_test(@metric, :benchmark) } @total = @metric.total end @@ -257,6 +255,8 @@ module ActiveSupport end def benchmark + @unsureturn if measure.nil? + with_gc_stats do before = measure yield diff --git a/activesupport/lib/active_support/testing/performance/ruby.rb b/activesupport/lib/active_support/testing/performance/ruby.rb index 3dc668cd92..9f56a412a1 100644 --- a/activesupport/lib/active_support/testing/performance/ruby.rb +++ b/activesupport/lib/active_support/testing/performance/ruby.rb @@ -124,30 +124,18 @@ module ActiveSupport class Memory < DigitalInformationUnit Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) - - # overridden by each implementation - def measure; end end class Objects < Amount Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) - - # overridden by each implementation - def measure; end end class GcRuns < Amount Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS) - - # overridden by each implementation - def measure; end end class GcTime < Time Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME) - - # overridden by each implementation - def measure; end end end end diff --git a/activesupport/lib/active_support/testing/performance/ruby/yarv.rb b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb index 498bc6b4db..62095a8fe4 100644 --- a/activesupport/lib/active_support/testing/performance/ruby/yarv.rb +++ b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb @@ -17,7 +17,7 @@ module ActiveSupport end class Memory < DigitalInformationUnit - # Ruby 1.9 + GCdata patch + # Ruby 1.9 + GCdata patch if GC.respond_to?(:malloc_allocated_size) def measure GC.malloc_allocated_size |