diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-18 15:55:32 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-18 16:02:27 -0700 |
commit | 90a9a7013ca733c6414d8ec6ababae2c65ad7c99 (patch) | |
tree | d99757ac39e21dd940ea2957987a7f53be836933 /activesupport/lib/active_support/testing/performance.rb | |
parent | 40557e17dda0525d5d26c09b3279b83695df3f4d (diff) | |
download | rails-90a9a7013ca733c6414d8ec6ababae2c65ad7c99.tar.gz rails-90a9a7013ca733c6414d8ec6ababae2c65ad7c99.tar.bz2 rails-90a9a7013ca733c6414d8ec6ababae2c65ad7c99.zip |
Write benchmark output to separate files per test+metric. Support Lloyd Hilaiel's GC.heap_info patch for current heap size.
Diffstat (limited to 'activesupport/lib/active_support/testing/performance.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/performance.rb | 40 |
1 files changed, 35 insertions, 5 deletions
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) |