3

According to the documentation, you can profile Rails apps http://ruby-prof.rubyforge.org/

I added this to my config.ru

if Rails.env.development?
  use Rack::RubyProf, :path => 'tmp/profile'
end

However it only outputs the following files

users-1-call_stack.html
users-1-flat.txt
users-1-graph.html
users-1-graph.txt

The output is completely incomprehensible. So I downloaded QCacheGrind for Windows. http://sourceforge.net/projects/qcachegrindwin/?source=recommended

It won't read any of those files. The ruby-prof docs says that you can generate KCacheGrind files

RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.

But it won't say how to do it with Rails. I looked at the page for RubyProf, but it was empty. http://ruby-prof.rubyforge.org/classes/Rack/RubyProf.html

Ruby 2.0.0, Rails 4.0.3

Chloe
  • 25,162
  • 40
  • 190
  • 357

2 Answers2

0
  helper_method :profile
  around_action :profile, only: [:show] 

  def profile(prefix = "profile")
    result = RubyProf.profile { yield }

    # dir = File.join(Rails.root, "tmp", "profile", params[:controller].parameterize)
    dir = File.join(Rails.root, "tmp", "profile")
    FileUtils.mkdir_p(dir)
    file = File.join(dir, "callgrind.%s.%s.%s" % [prefix.parameterize, params[:action].parameterize, Time.now.to_s.parameterize] )
    open(file, "w") {|f| RubyProf::CallTreePrinter.new(result).print(f, :min_percent => 1) }
  end
Chloe
  • 25,162
  • 40
  • 190
  • 357
0

Change config.ru

use Rack::RubyProf, :path => ::File.expand_path('tmp/profile'),
      :printers => {::RubyProf::FlatPrinter => 'flat.txt',
                                    ::RubyProf::GraphPrinter => 'graph.txt',
                                    ::RubyProf::GraphHtmlPrinter => 'graph.html',
                                    ::RubyProf::CallStackPrinter => 'call_stack.html',
                                    ::RubyProf::CallTreePrinter => 'call_grind.txt',
  }
rexmadden
  • 266
  • 4
  • 7