如何输出带有Ruby-prof的Ruby-prof的kcachegrind呼叫树分析



根据文档,您可以配置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

输出完全无法理解。因此,我下载了用于Windows的Qcachegrind。http://sourceforge.net/projects/qcachegrindwin/?source=recommonded

它不会读取任何这些文件。Ruby-prof Docs说您可以生成Kcachegrind文件

rubyprof :: calltroeprinter-创建与Kcachegrind兼容的呼叫树报告。

,但它不会说如何使用轨道。我查看了RubyProf的页面,但它是空的。http://ruby-prof.rubyforge.org/classes/rack/rubyprof.html

Ruby 2.0.0,Rails 4.0.3

  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

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

相关内容

  • 没有找到相关文章

最新更新