根据文档,您可以分析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 docs说您可以生成KCacheGrind文件。
鲁比教授::CallTreePrinter创建一个与KCachegrind兼容的调用树报告。
但是它并没有说如何用Rails来实现它。我查看了页面中的RubyProf,但它是空的。http://ruby-prof.rubyforge.org/classes/Rack/RubyProf.html
Ruby2.0.0,Rails 4.0.3
发布于 2014-03-08 02:15:03
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-06-07 02:16:05
改变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',
}https://stackoverflow.com/questions/22263834
复制相似问题