class ActiveSupport::Testing::Performance::Profiler

overridden by each implementation

Public Class Methods

new(*args) click to toggle source
# File lib/active_support/testing/performance/ruby.rb, line 26
def initialize(*args)
  super
  @supported = @metric.measure_mode rescue false
end

Public Instance Methods

record() click to toggle source
# File lib/active_support/testing/performance/ruby.rb, line 42
def record
  return unless @supported

  klasses = full_profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact

  klasses.each do |klass|
    fname = output_filename(klass)
    FileUtils.mkdir_p(File.dirname(fname))
    File.open(fname, 'wb') do |file|
      klass.new(@data).print(file, full_profile_options.slice(:min_percent))
    end
  end
end
run() click to toggle source
# File lib/active_support/testing/performance/ruby.rb, line 31
def run
  return unless @supported

  RubyProf.measure_mode = @metric.measure_mode
  RubyProf.start
  RubyProf.pause
  full_profile_options[:runs].to_i.times { run_test(@metric, :profile) }
  @data = RubyProf.stop
  @total = @data.threads.sum(0) { |thread| thread.methods.max.total_time }
end
time_with_block() { || ... } click to toggle source
# File lib/active_support/testing/performance.rb, line 169
def time_with_block
  before = Time.now
  yield
  Time.now - before
end

Protected Instance Methods

create_path_and_open_file(printer_name) { |file| ... } click to toggle source
# File lib/active_support/testing/performance/rubinius.rb, line 56
def create_path_and_open_file(printer_name)
  fname = "#{output_filename}_#{printer_name}.txt"
  FileUtils.mkdir_p(File.dirname(fname))
  File.open(fname, 'wb') do |file|
    yield(file)
  end
end
output_filename(printer_class) click to toggle source
# File lib/active_support/testing/performance/ruby.rb, line 57
def output_filename(printer_class)
  suffix =
    case printer_class.name.demodulize
      when 'FlatPrinter';                 'flat.txt'
      when 'FlatPrinterWithLineNumbers';  'flat_line_numbers.txt'
      when 'GraphPrinter';                'graph.txt'
      when 'GraphHtmlPrinter';            'graph.html'
      when 'GraphYamlPrinter';            'graph.yml'
      when 'CallTreePrinter';             'tree.txt'
      when 'CallStackPrinter';            'stack.html'
      when 'DotPrinter';                  'graph.dot'
      else printer_class.name.sub(%rPrinter$/, '').underscore
    end

  "#{super()}_#{suffix}"
end