lib/ruby-prof/compatibility.rb in ruby-prof-0.12.1 vs lib/ruby-prof/compatibility.rb in ruby-prof-0.12.2
- old
+ new
@@ -150,15 +150,20 @@
raise(RuntimeError, "RubyProf is already running") if running?
end
# for GC.allocated_size to work GC statistics should be enabled
def self.enable_gc_stats_if_needed
- if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:enable_stats)
+ if measure_mode_requires_gc_stats_enabled?
@gc_stat_was_enabled = GC.enable_stats
end
end
def self.disable_gc_stats_if_needed(was_enabled=nil)
was_enabled ||= defined?(@gc_stat_was_enabled) && @gc_stat_was_enabled
- GC.disable_stats if self.measure_mode == RubyProf::MEMORY && GC.respond_to?(:disable_stats) && !was_enabled
+ GC.disable_stats if measure_mode_requires_gc_stats_enabled? && !was_enabled
end
-end
\ No newline at end of file
+
+ def self.measure_mode_requires_gc_stats_enabled?
+ GC.respond_to?(:enable_stats) &&
+ [RubyProf::MEMORY, RubyProf::GC_TIME, RubyProf::GC_RUNS].include?(measure_mode)
+ end
+end