Class: ActiveSupport::Testing::Performance::Profiler
- Defined in:
- lib/active_support/testing/performance.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Profiler
constructor
A new instance of Profiler.
- #record ⇒ Object
- #report ⇒ Object
- #run ⇒ Object
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
#record ⇒ Object
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 = [: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, .slice(:min_percent)) end end end |
#report ⇒ Object
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 |
#run ⇒ Object
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 [: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 |