diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-25 03:26:43 +0000 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-25 03:26:43 +0000 |
commit | 2fa426c9444dc6dd1b701592cf4d636739556b9e (patch) | |
tree | bfc54ef48ec83780b193ecc91d24f8f31006acdf /activesupport/lib/active_support/testing/performance/ruby | |
parent | 3ec79e4288df602301e26ae7b2f2b651ff745862 (diff) | |
download | rails-2fa426c9444dc6dd1b701592cf4d636739556b9e.tar.gz rails-2fa426c9444dc6dd1b701592cf4d636739556b9e.tar.bz2 rails-2fa426c9444dc6dd1b701592cf4d636739556b9e.zip |
divide the ruby interpreter into mri and yarv for improved modularity
Diffstat (limited to 'activesupport/lib/active_support/testing/performance/ruby')
-rw-r--r-- | activesupport/lib/active_support/testing/performance/ruby/mri.rb | 60 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/performance/ruby/yarv.rb | 62 |
2 files changed, 122 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/performance/ruby/mri.rb b/activesupport/lib/active_support/testing/performance/ruby/mri.rb index e69de29bb2..d12482b58f 100644 --- a/activesupport/lib/active_support/testing/performance/ruby/mri.rb +++ b/activesupport/lib/active_support/testing/performance/ruby/mri.rb @@ -0,0 +1,60 @@ +module ActiveSupport + module Testing + module Performance + module Metrics + class Base + protected + # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker) + if GC.respond_to?(:enable_stats) + def with_gc_stats + GC.enable_stats + yield + ensure + GC.disable_stats + end + end + end + + class Memory < Base + # Ruby 1.8 + ruby-prof wrapper + if RubyProf.respond_to?(:measure_memory) + def measure + RubyProf.measure_memory / 1024.0 + end + end + end + + class Amount < Base; end + + class Objects < Amount + # Ruby 1.8 + ruby-prof wrapper + if RubyProf.respond_to?(:measure_allocations) + def measure + RubyProf.measure_allocations + end + end + end + + class GcRuns < Amount + # Ruby 1.8 + ruby-prof wrapper + if RubyProf.respond_to?(:measure_gc_runs) + def measure + RubyProf.measure_gc_runs + end + end + end + + class GcTime < Time + # Ruby 1.8 + ruby-prof wrapper + if RubyProf.respond_to?(:measure_gc_time) + def measure + RubyProf.measure_gc_time / 1000 + end + end + end + end + end + end +end + + diff --git a/activesupport/lib/active_support/testing/performance/ruby/yarv.rb b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb index e69de29bb2..1e6fa2f289 100644 --- a/activesupport/lib/active_support/testing/performance/ruby/yarv.rb +++ b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb @@ -0,0 +1,62 @@ +module ActiveSupport + module Testing + module Performance + module Metrics + class Base + protected + # Ruby 1.9 with GC::Profiler + if defined?(GC::Profiler) + def with_gc_stats + GC::Profiler.enable + GC.start + yield + ensure + GC::Profiler.disable + end + end + end + + class Memory < Base + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocated_size) + def measure + GC.malloc_allocated_size / 1024.0 + end + end + end + + class Amount < Base; end + + class Objects < Amount + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocations) + def measure + GC.malloc_allocations + end + end + end + + class GcRuns < Amount + # Ruby 1.9 + if GC.respond_to?(:count) + def measure + GC.count + end + end + end + + class GcTime < Time + # Ruby 1.9 with GC::Profiler + if defined?(GC::Profiler) && GC::Profiler.respond_to?(:total_time) + def measure + GC::Profiler.total_time + end + end + end + end + end + end +end + + + |