From 90a9a7013ca733c6414d8ec6ababae2c65ad7c99 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 18 Jun 2008 15:55:32 -0700 Subject: Write benchmark output to separate files per test+metric. Support Lloyd Hilaiel's GC.heap_info patch for current heap size. --- .../lib/active_support/testing/performance.rb | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 24936029a2..9f85bca716 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -97,6 +97,11 @@ module ActiveSupport rate = @total / profile_options[:runs] '%20s: %s/run' % [@metric.name, @metric.format(rate)] end + + protected + def output_filename + "#{profile_options[:output]}/#{full_test_name}" + end end class Benchmarker < Performer @@ -107,9 +112,9 @@ module ActiveSupport def record avg = @metric.total / profile_options[:runs].to_i - data = [full_test_name, @metric.name, avg, Time.now.utc.xmlschema] * ',' + now = Time.now.utc.xmlschema with_output_file do |file| - file.puts "#{data},#{environment}" + file.puts "#{avg},#{now},#{environment}" end end @@ -134,10 +139,10 @@ module ActiveSupport end protected - HEADER = 'test,metric,measurement,created_at,app,rails,ruby,platform' + HEADER = 'measurement,created_at,app,rails,ruby,platform' def with_output_file - fname = "#{profile_options[:output]}/benchmarks.csv" + fname = output_filename if new = !File.exist?(fname) FileUtils.mkdir_p(File.dirname(fname)) @@ -148,6 +153,10 @@ module ActiveSupport yield file end end + + def output_filename + "#{super}.csv" + end end class Profiler < Performer @@ -183,7 +192,7 @@ module ActiveSupport else printer_class.name.sub(/Printer$/, '').underscore end - "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}_#{suffix}" + "#{super()}_#{suffix}" end end @@ -287,18 +296,35 @@ module ActiveSupport class Memory < Base Mode = RubyProf::MEMORY + # ruby-prof wrapper if RubyProf.respond_to?(:measure_memory) def measure RubyProf.measure_memory / 1024.0 end + + # Ruby 1.8 + adymo patch elsif GC.respond_to?(:allocated_size) def measure GC.allocated_size / 1024.0 end + + # Ruby 1.8 + lloyd patch + elsif GC.respond_to?(:heap_info) + def measure + GC.heap_info['heap_current_memory'] / 1024.0 + end + + # Ruby 1.9 unpatched elsif GC.respond_to?(:malloc_allocated_size) def measure GC.malloc_allocated_size / 1024.0 end + + # Unavailable + else + def measure + 0 + end end def format(measurement) @@ -317,6 +343,10 @@ module ActiveSupport def measure ObjectSpace.allocated_objects end + else + def measure + 0 + end end def format(measurement) -- cgit v1.2.3 From 616bc42fd7675a42e8bd461855385d9a2b0cf5e3 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 18 Jun 2008 18:34:25 -0700 Subject: Performance: tweak unsupported metric error message --- activesupport/lib/active_support/testing/performance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 9f85bca716..ee09b301ba 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -44,7 +44,7 @@ module ActiveSupport run_profile(klass.new) result.add_run else - $stderr.puts "Skipping unknown metric #{metric_name.inspect}. Expected :process_time, :wall_time, :cpu_time, :memory, or :objects." + $stderr.puts '%20s: unsupported' % metric_name.to_s end end -- cgit v1.2.3 From 2541f7ac478e00d2a225399d1619ccf6c33f2d9c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 18 Jun 2008 18:36:04 -0700 Subject: Oops, include metric name in csv filename --- activesupport/lib/active_support/testing/performance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index ee09b301ba..728fa860cb 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -100,7 +100,7 @@ module ActiveSupport protected def output_filename - "#{profile_options[:output]}/#{full_test_name}" + "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}" end end -- cgit v1.2.3 From 1e0d2e36cc4b524ca5a4330eeb3e3fd7f5ca0b5e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 18 Jun 2008 18:46:17 -0700 Subject: Performance: add GC metrics for # of runs and total runtime --- .../lib/active_support/testing/performance.rb | 58 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 728fa860cb..2317171467 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -12,13 +12,13 @@ module ActiveSupport if benchmark = ARGV.include?('--benchmark') # HAX for rake test { :benchmark => true, :runs => 10, - :metrics => [:process_time, :memory, :objects], + :metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time], :output => 'tmp/performance' } else { :benchmark => false, :runs => 1, :min_percent => 0.02, - :metrics => [:wall_time, :memory, :objects], + :metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time], :formats => [:flat, :graph_html, :call_tree], :output => 'tmp/performance' } end @@ -72,9 +72,13 @@ module ActiveSupport protected def run_warmup + 5.times { GC.start } + time = Metrics::Time.new run_test(time, :benchmark) puts "%s (%s warmup)" % [full_test_name, time.format(time.total)] + + 5.times { GC.start } end def run_profile(metric) @@ -219,6 +223,10 @@ module ActiveSupport self.class::Mode end + def measure + 0 + end + def benchmark with_gc_stats do before = measure @@ -319,12 +327,6 @@ module ActiveSupport def measure GC.malloc_allocated_size / 1024.0 end - - # Unavailable - else - def measure - 0 - end end def format(measurement) @@ -343,9 +345,27 @@ module ActiveSupport def measure ObjectSpace.allocated_objects end - else + end + + def format(measurement) + measurement.to_i.to_s + end + end + + class GcRuns < Base + Mode = RubyProf::GC_RUNS + + if RubyProf.respond_to?(:measure_gc_runs) + def measure + RubyProf.measure_gc_runs + end + elsif GC.respond_to?(:collections) def measure - 0 + GC.collections + end + elsif GC.respond_to?(:heap_info) + def measure + GC.heap_info['num_gc_passes'] end end @@ -353,6 +373,24 @@ module ActiveSupport measurement.to_i.to_s end end + + class GcTime < Base + Mode = RubyProf::GC_TIME + + if RubyProf.respond_to?(:measure_gc_time) + def measure + RubyProf.measure_gc_time + end + elsif GC.respond_to?(:time) + def measure + GC.time + end + end + + def format(measurement) + '%d ms' % (measurement / 1000) + end + end end end end -- cgit v1.2.3 From 83c3e9903d2ad76ef4aea1d64d6514443f6ad438 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 20 Jun 2008 00:35:11 -0700 Subject: Don't profile GC runs/time by default --- activesupport/lib/active_support/testing/performance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 2317171467..cadcb155c1 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -18,7 +18,7 @@ module ActiveSupport { :benchmark => false, :runs => 1, :min_percent => 0.02, - :metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time], + :metrics => [:process_time, :memory, :objects], :formats => [:flat, :graph_html, :call_tree], :output => 'tmp/performance' } end -- cgit v1.2.3 From 879245de1ce294e8951927f0e694333746772187 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 20 Jun 2008 00:36:59 -0700 Subject: Tired of seeing /run --- activesupport/lib/active_support/testing/performance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index cadcb155c1..1f8a5eec8f 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -99,7 +99,7 @@ module ActiveSupport def report rate = @total / profile_options[:runs] - '%20s: %s/run' % [@metric.name, @metric.format(rate)] + '%20s: %s' % [@metric.name, @metric.format(rate)] end protected -- cgit v1.2.3 From 8d24a029df47fa9ad36f0e027d3cd447f92af344 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 20 Jun 2008 10:39:44 -0700 Subject: Don't assume RubyProf constants are defined --- activesupport/lib/active_support/testing/performance.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/testing/performance.rb') diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 1f8a5eec8f..5f2027eb3b 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -288,7 +288,7 @@ module ActiveSupport end class CpuTime < Time - Mode = RubyProf::CPU_TIME + Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME) def initialize(*args) # FIXME: yeah my CPU is 2.33 GHz @@ -302,7 +302,7 @@ module ActiveSupport end class Memory < Base - Mode = RubyProf::MEMORY + Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) # ruby-prof wrapper if RubyProf.respond_to?(:measure_memory) @@ -335,7 +335,7 @@ module ActiveSupport end class Objects < Base - Mode = RubyProf::ALLOCATIONS + Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) if RubyProf.respond_to?(:measure_allocations) def measure @@ -353,7 +353,7 @@ module ActiveSupport end class GcRuns < Base - Mode = RubyProf::GC_RUNS + Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS) if RubyProf.respond_to?(:measure_gc_runs) def measure @@ -375,7 +375,7 @@ module ActiveSupport end class GcTime < Base - Mode = RubyProf::GC_TIME + Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME) if RubyProf.respond_to?(:measure_gc_time) def measure -- cgit v1.2.3