aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance
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 /activesupport/lib/active_support/testing/performance
parent391ccdaf35f41e38905a940a72e30b484cb0baf9 (diff)
downloadrails-09cdd1cac149cf8e18f16e39937d659146e61f70.tar.gz
rails-09cdd1cac149cf8e18f16e39937d659146e61f70.tar.bz2
rails-09cdd1cac149cf8e18f16e39937d659146e61f70.zip
check if there is support for the specified metric when profiling
Diffstat (limited to 'activesupport/lib/active_support/testing/performance')
-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
3 files changed, 20 insertions, 18 deletions
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