Как вы выводите профилирование дерева вызовов для KCacheGrind с помощью ruby-prof для приложения Rails?
Согласно документации, вы можете профилировать приложения 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 для 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
2 ответа
Изменить 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',
}
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