Class: Middleman::Profiling::RubyProfProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/profiling.rb

Overview

A profiler that uses ruby-prof

Instance Method Summary collapse

Constructor Details

#initializeRubyProfProfiler

Returns a new instance of RubyProfProfiler.



30
31
32
33
34
# File 'lib/middleman-core/profiling.rb', line 30

def initialize
  require 'ruby-prof'
rescue LoadError
  raise "To use the --profile option, you must add the 'ruby-prof' gem to your Gemfile"
end

Instance Method Details

#report(report_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/middleman-core/profiling.rb', line 40

def report(report_name)
  result = RubyProf.stop

  printer = RubyProf::GraphHtmlPrinter.new(result)
  outfile = File.join('profile', report_name)
  outfile = (outfile + '.html') unless outfile.end_with? '.html'
  FileUtils.mkdir_p(File.dirname(outfile))
  File.open(outfile, 'w') do |f|
    printer.print(f, min_percent: 1)
  end
end

#startObject



36
37
38
# File 'lib/middleman-core/profiling.rb', line 36

def start
  RubyProf.start
end