From 0d1f7584ba25e7289871b5503f010874bc2aef49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= Date: Mon, 9 May 2011 23:29:00 +0100 Subject: contemplate unsupported metrics --- .../lib/active_support/testing/performance.rb | 34 +++++++++++----------- .../lib/active_support/testing/performance/ruby.rb | 12 -------- .../testing/performance/ruby/yarv.rb | 2 +- 3 files changed, 18 insertions(+), 30 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3