Ruby on rails 如何使用ruby prof为Rails应用程序输出KCacheGrind的调用树评测?

Ruby on rails 如何使用ruby prof为Rails应用程序输出KCacheGrind的调用树评测?,ruby-on-rails,ruby,ruby-on-rails-4,kcachegrind,ruby-prof,Ruby On Rails,Ruby,Ruby On Rails 4,Kcachegrind,Ruby Prof,根据文档,您可以配置Rails应用程序 我把它添加到我的config.ru中 if Rails.env.development? use Rack::RubyProf, :path => 'tmp/profile' end 但是,它只输出以下文件 users-1-call_stack.html users-1-flat.txt users-1-graph.html users-1-graph.txt 输出完全不可理解。所以我下载了QCacheGrind for Windows。

根据文档,您可以配置Rails应用程序

我把它添加到我的config.ru中

if Rails.env.development?
  use Rack::RubyProf, :path => 'tmp/profile'
end
但是,它只输出以下文件

users-1-call_stack.html
users-1-flat.txt
users-1-graph.html
users-1-graph.txt
输出完全不可理解。所以我下载了QCacheGrind for Windows。

它不会读取任何这些文件。ruby prof docs说您可以生成KCacheGrind文件

RubyProf::CallTreePrinter-创建与KCachegrind兼容的调用树报告

但它没有说明如何使用Rails。我看了看RubyProf的页面,但页面是空的。

Ruby 2.0.0,Rails 4.0.3

Change config.ru

  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
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',
  }