Skip to content
Browse files

the official profiler (present in 1.9) should have the highest priority

  • Loading branch information...
1 parent 381a30f commit 901452d06ac39f9870bba27a8bc4c6e4f100f90f @goncalossilva goncalossilva committed with wycats Jun 12, 2010
Showing with 31 additions and 31 deletions.
  1. +31 −31 activesupport/lib/active_support/testing/performance.rb
View
62 activesupport/lib/active_support/testing/performance.rb
@@ -260,14 +260,7 @@ def profile
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 @@ def with_gc_stats
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 @@ def measure
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 @@ def measure
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 @@ def format(measurement)
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 @@ def measure
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)

0 comments on commit 901452d

Please sign in to comment.
Something went wrong with that request. Please try again.