From 901452d06ac39f9870bba27a8bc4c6e4f100f90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= Date: Sat, 12 Jun 2010 11:34:53 +0100 Subject: the official profiler (present in 1.9) should have the highest priority --- .../lib/active_support/testing/performance.rb | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 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 6e51dbb735..2617763175 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -260,14 +260,7 @@ begin end protected - if GC.respond_to?(:enable_stats) - def with_gc_stats - GC.enable_stats - yield - ensure - GC.disable_stats - end - elsif defined?(GC::Profiler) + if defined?(GC::Profiler) def with_gc_stats GC.start GC.disable @@ -277,6 +270,13 @@ begin GC::Profiler.disable GC.enable end + elsif GC.respond_to?(:enable_stats) + def with_gc_stats + GC.enable_stats + yield + ensure + GC.disable_stats + end else def with_gc_stats yield @@ -331,8 +331,18 @@ begin class Memory < Base Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) + # Ruby 1.9 + GC profiler patch + if defined?(GC::Profiler) + def measure + GC.enable + GC.start + kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0 + GC.disable + kb + end + # ruby-prof wrapper - if RubyProf.respond_to?(:measure_memory) + elsif RubyProf.respond_to?(:measure_memory) def measure RubyProf.measure_memory / 1024.0 end @@ -360,16 +370,6 @@ begin def measure GC.malloc_allocated_size / 1024.0 end - - # Ruby 1.9 + GC profiler patch - elsif defined?(GC::Profiler) - def measure - GC.enable - GC.start - kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0 - GC.disable - kb - end end def format(measurement) @@ -380,19 +380,8 @@ begin class Objects < Base Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) - if RubyProf.respond_to?(:measure_allocations) - def measure - RubyProf.measure_allocations - end - - # Ruby 1.8 + railsbench patch - elsif ObjectSpace.respond_to?(:allocated_objects) - def measure - ObjectSpace.allocated_objects - end - # Ruby 1.9 + GC profiler patch - elsif defined?(GC::Profiler) + if defined?(GC::Profiler) def measure GC.enable GC.start @@ -401,6 +390,17 @@ begin GC.disable count end + + elsif RubyProf.respond_to?(:measure_allocations) + def measure + RubyProf.measure_allocations + end + + # Ruby 1.8 + railsbench patch + elsif ObjectSpace.respond_to?(:allocated_objects) + def measure + ObjectSpace.allocated_objects + end end def format(measurement) -- cgit v1.2.3