3

根据文档,您可以分析 Rails 应用程序 http://ruby-prof.rubyforge.org/

我将此添加到我的 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。 http://sourceforge.net/projects/qcachegrindwin/?source=recommended

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

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

但它不会说如何使用 Rails 来做到这一点。我查看了 RubyProf 的页面,但它是空的。 http://ruby-prof.rubyforge.org/classes/Rack/RubyProf.html

Ruby 2.0.0,Rails 4.0.3

4

2 回答 2

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
于 2014-03-08T02:15:03.880 回答
0

更改 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',
  }
于 2014-06-07T02:16:05.423 回答