Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Force runs to be an integer. Start and stop RubyProf in same scope. E…

…xpect memory measurements in fractional KB now instead of bytes. Convert object allocation measurements to integer. Wrap up measure_mode in Metric instance method.
  • Loading branch information...
commit e8f78998b2af492159189d4f0aa6c3a301431ca8 1 parent f93a6d9
@jeremy jeremy authored
Showing with 21 additions and 12 deletions.
  1. +21 −12 activesupport/lib/active_support/testing/performance.rb
View
33 activesupport/lib/active_support/testing/performance.rb
@@ -97,15 +97,15 @@ def report
class Benchmarker < Performer
def run
- profile_options[:runs].times { run_test(@metric, :benchmark) }
+ profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
@total = @metric.total
end
def record
with_output_file do |file|
file.puts [full_test_name, @metric.name,
- @metric.total, profile_options[:runs],
- @metric.total / profile_options[:runs],
+ @metric.total, profile_options[:runs].to_i,
+ @metric.total / profile_options[:runs].to_i,
Time.now.utc.xmlschema,
Rails::VERSION::STRING,
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby',
@@ -132,16 +132,19 @@ def with_output_file
class Profiler < Performer
def run
- profile_options[:runs].times { run_test(@metric, :profile) }
+ RubyProf.measure_mode = @metric.measure_mode
+ RubyProf.start
+ RubyProf.pause
+ profile_options[:runs].to_i.times { run_test(@metric, :profile) }
@data = RubyProf.stop
@total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time }
end
- def record(path)
+ def record
klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
klasses.each do |klass|
- fname = output_filename(metric, klass)
+ fname = output_filename(klass)
FileUtils.mkdir_p(File.dirname(fname))
File.open(fname, 'wb') do |file|
klass.new(@data).print(file, profile_options.slice(:min_percent))
@@ -150,7 +153,7 @@ def record(path)
end
protected
- def output_filename(metric, printer_class)
+ def output_filename(printer_class)
suffix =
case printer_class.name.demodulize
when 'FlatPrinter'; 'flat.txt'
@@ -160,7 +163,7 @@ def output_filename(metric, printer_class)
else printer_class.name.sub(/Printer$/, '').underscore
end
- "#{profile_options[:output]}/#{full_test_name}_#{metric.name}_#{suffix}"
+ "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}_#{suffix}"
end
end
@@ -183,6 +186,10 @@ def name
@name ||= self.class.name.demodulize.underscore
end
+ def measure_mode
+ self.class::Mode
+ end
+
def benchmark
with_gc_stats do
before = measure
@@ -192,8 +199,10 @@ def benchmark
end
def profile
- RubyProf.measure_mode = Mode
- RubyProf.resume { yield }
+ RubyProf.resume
+ yield
+ ensure
+ RubyProf.pause
end
protected
@@ -273,7 +282,7 @@ def measure
end
def format(measurement)
- '%.2f KB' % (measurement / 1024.0)
+ '%.2f KB' % measurement
end
end
@@ -291,7 +300,7 @@ def measure
end
def format(measurement)
- measurement.to_s
+ measurement.to_i.to_s
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.