How can I profile a request in Ruby on Rails?

孤人 提交于 2019-12-21 03:48:28

问题


How can I profile a controller action?

One of my views is taking quite some time to render, and I'd like to break it down. I see script/performance/profiler, but that seems to only have access to the global scope.


回答1:


ruby-prof is the way to go. Here's a howto, How to profile your Rails and Ruby applications with ruby-prof.

If you use it in combination with a visualisation tool such as kcachegrind, you can easily separate the code that is your application code from the framework code.

I gave a talk on these tools at my local Ruby-users group a while back: Making your rails app kick ass with ruby-prof and kcachegrind.




回答2:


The Ruby on Rails console should show you which partials are taking a while to render. If that's not enough, you could install the new relic gem (https://github.com/newrelic/rpm) and use that in developer mode which will give you an overview of what's going on.

If you're deploying on Heroku you can add the free version of rpm which will give you the same statistics on your running application.

Ruby has a profiler (http://ruby-prof.rubyforge.org/) which will show you memory usage, call times, etc., but it might be hard to disseminate your code from the framework code.




回答3:


I've had some success with https://github.com/bhb/rack-perftools_profiler

It'll let you profile a single or multiple requests for any of cputime, methods, object allocations or walltime, and integrate nicely via Rack middleware.



来源:https://stackoverflow.com/questions/2716418/how-can-i-profile-a-request-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!