aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-03-26 03:10:00 +0000
committerGonçalo Silva <goncalossilva@gmail.com>2011-03-26 15:51:44 +0000
commit3872cc4a739db7e0fb5b4a910be371c048667ca7 (patch)
treeae48ee846e67207face3e4be1bdfc1d74f8f01d5 /activesupport
parent278344b3fab67fcc471f475992a86c3748a83e23 (diff)
downloadrails-3872cc4a739db7e0fb5b4a910be371c048667ca7.tar.gz
rails-3872cc4a739db7e0fb5b4a910be371c048667ca7.tar.bz2
rails-3872cc4a739db7e0fb5b4a910be371c048667ca7.zip
added support for profiling under rubinius
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb9
-rw-r--r--activesupport/lib/active_support/testing/performance/rubinius.rb58
-rw-r--r--activesupport/lib/active_support/testing/performance/ruby.rb6
3 files changed, 66 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 9a759433b9..bba05d0a51 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -6,9 +6,10 @@ require 'action_view/helpers/number_helper'
module ActiveSupport
module Testing
- module Performance
+ module Performance
+ # modified by each implementation
DEFAULTS =
- if benchmark = ARGV.include?('--benchmark') # HAX for rake test
+ if ARGV.include?('--benchmark') # HAX for rake test
{ :benchmark => true,
:runs => 4,
:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
@@ -17,10 +18,8 @@ module ActiveSupport
{ :benchmark => false,
:runs => 1,
:min_percent => 0.01,
- :metrics => [:process_time, :memory, :objects],
- :formats => [:flat, :graph_html, :call_tree],
:output => 'tmp/performance' }
- end.freeze
+ end
def self.included(base)
base.superclass_delegating_accessor :profile_options
diff --git a/activesupport/lib/active_support/testing/performance/rubinius.rb b/activesupport/lib/active_support/testing/performance/rubinius.rb
index b9c7061571..8f1047381b 100644
--- a/activesupport/lib/active_support/testing/performance/rubinius.rb
+++ b/activesupport/lib/active_support/testing/performance/rubinius.rb
@@ -3,16 +3,70 @@ require 'rubinius/agent'
module ActiveSupport
module Testing
module Performance
+ if !ARGV.include?('--benchmark')
+ DEFAULTS.merge!(
+ { :metrics => [:wall_time],
+ :formats => [:flat, :graph] })
+ end
+
protected
def run_gc
GC.run(true)
end
+
+ class Performer; end
+
+ class Profiler < Performer
+ def initialize(*args)
+ super
+ end
+
+ def run
+ @profiler = Rubinius::Profiler::Instrumenter.new
+
+ @profiler.profile(false) do
+ profile_options[:runs].to_i.times { run_test(@metric, :profile) }
+ end
+
+ @total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds
+ end
+
+ def report
+ super
+ end
+
+ def record
+ if(profile_options[:formats].include?(:flat))
+ File.open(output_filename('FlatPrinter'), 'wb') do |file|
+ @profiler.show(file)
+ end
+ end
+
+ if(profile_options[:formats].include?(:graph))
+ @profiler.set_options({:graph => true})
+ File.open(output_filename('GraphPrinter'), 'wb') do |file|
+ @profiler.show(file)
+ end
+ end
+ end
+
+ protected
+ def output_filename(printer)
+ suffix =
+ case printer
+ when 'FlatPrinter'; 'flat.txt'
+ when 'GraphPrinter'; 'graph.txt'
+ else printer.sub(/Printer$/, '').underscore
+ end
+
+ "#{super()}_#{suffix}"
+ end
+ end
module Metrics
class Base
attr_reader :loopback
-
- # TODO
+
def profile
yield
end
diff --git a/activesupport/lib/active_support/testing/performance/ruby.rb b/activesupport/lib/active_support/testing/performance/ruby.rb
index 892baceeb2..13dfebbece 100644
--- a/activesupport/lib/active_support/testing/performance/ruby.rb
+++ b/activesupport/lib/active_support/testing/performance/ruby.rb
@@ -8,6 +8,12 @@ end
module ActiveSupport
module Testing
module Performance
+ if !ARGV.include?('--benchmark')
+ DEFAULTS.merge!(
+ { :metrics => [:process_time, :memory, :objects],
+ :formats => [:flat, :graph_html, :call_tree] })
+ end
+
protected
def run_gc
GC.start