Skip to content

Commit

Permalink
Performance: add GC metrics for # of runs and total runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Jun 19, 2008
1 parent 2541f7a commit 1e0d2e3
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions activesupport/lib/active_support/testing/performance.rb
Expand Up @@ -12,13 +12,13 @@ module Performance
if benchmark = ARGV.include?('--benchmark') # HAX for rake test
{ :benchmark => true,
:runs => 10,
:metrics => [:process_time, :memory, :objects],
:metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time],
:output => 'tmp/performance' }
else
{ :benchmark => false,
:runs => 1,
:min_percent => 0.02,
:metrics => [:wall_time, :memory, :objects],
:metrics => [:process_time, :memory, :objects, :gc_runs, :gc_time],
:formats => [:flat, :graph_html, :call_tree],
:output => 'tmp/performance' }
end
Expand Down Expand Up @@ -72,9 +72,13 @@ def run_test(metric, mode)

protected
def run_warmup
5.times { GC.start }

time = Metrics::Time.new
run_test(time, :benchmark)
puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]

5.times { GC.start }
end

def run_profile(metric)
Expand Down Expand Up @@ -219,6 +223,10 @@ def measure_mode
self.class::Mode
end

def measure
0
end

def benchmark
with_gc_stats do
before = measure
Expand Down Expand Up @@ -319,12 +327,6 @@ def measure
def measure
GC.malloc_allocated_size / 1024.0
end

# Unavailable
else
def measure
0
end
end

def format(measurement)
Expand All @@ -343,16 +345,52 @@ def measure
def measure
ObjectSpace.allocated_objects
end
else
end

def format(measurement)
measurement.to_i.to_s
end
end

class GcRuns < Base
Mode = RubyProf::GC_RUNS

if RubyProf.respond_to?(:measure_gc_runs)
def measure
RubyProf.measure_gc_runs
end
elsif GC.respond_to?(:collections)
def measure
0
GC.collections
end
elsif GC.respond_to?(:heap_info)
def measure
GC.heap_info['num_gc_passes']
end
end

def format(measurement)
measurement.to_i.to_s
end
end

class GcTime < Base
Mode = RubyProf::GC_TIME

if RubyProf.respond_to?(:measure_gc_time)
def measure
RubyProf.measure_gc_time
end
elsif GC.respond_to?(:time)
def measure
GC.time
end
end

def format(measurement)
'%d ms' % (measurement / 1000)
end
end
end
end
end
Expand Down

4 comments on commit 1e0d2e3

@chuyeow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m getting a const_missing for RubyProf::GC_RUNS and RubyProf::GC_TIME with vanilla ruby-prof (from your fork, Jeremy) – I’m probably missing a patch of some sort.

Anyway, the Mode assignments to these constants probably should be done conditionally.

@jeremy
Copy link
Member Author

@jeremy jeremy commented on 1e0d2e3 Jun 20, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good point :) Fixed in fd27488

@chuyeow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is great stuff you’re doing btw (this and the perf improvements). :)

@theflow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What patch do I need for this? I’m really curious about the GC numbers :)

Please sign in to comment.