From 09cdd1cac149cf8e18f16e39937d659146e61f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= Date: Wed, 30 Mar 2011 03:23:16 +0100 Subject: check if there is support for the specified metric when profiling --- .../lib/active_support/testing/performance.rb | 18 ++++++++++++------ .../lib/active_support/testing/performance/jruby.rb | 15 ++++++++++----- .../lib/active_support/testing/performance/rubinius.rb | 15 ++++++++++----- .../lib/active_support/testing/performance/ruby.rb | 8 -------- 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 -- cgit v1.2.3