Class: ActiveSupport::Testing::Performance::Profiler

Inherits:
Performer show all
Defined in:
lib/active_support/testing/performance.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Profiler

Returns a new instance of Profiler.



167
168
169
170
# File 'lib/active_support/testing/performance.rb', line 167

def initialize(*args)
  super
  @supported = @metric.measure_mode rescue false
end

Instance Method Details

#recordObject



191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/active_support/testing/performance.rb', line 191

def record
  return unless @supported

  klasses = 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, profile_options.slice(:min_percent))
    end
  end
end

#reportObject



183
184
185
186
187
188
189
# File 'lib/active_support/testing/performance.rb', line 183

def report
  if @supported
    super
  else
    '%20s: unsupported' % @metric.name
  end
end

#runObject



172
173
174
175
176
177
178
179
180
181
# File 'lib/active_support/testing/performance.rb', line 172

def run
  return unless @supported

  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