问题
I've been looking for profiling tools for Rails for a while. I'm currently playing and testing ruby-prof and railsbench, but I kinda frustrated with the amount of tweaking and mangling required to make then work.
Althought I don't mind (much) the tweaking, I'd like to know if is there any other, more straight-forward and easy to use, tools to profile a Rails app? Which tools you recommend?
回答1:
New Relic offers Rails profiling including a free 'Lite' version.
回答2:
You can use the built in profiler as well:
$ ruby script/performance/profiler 'User.new' 5
% cumulative self self total
time seconds seconds calls ms/call ms/call name
189.25 1.76 1.76 1 1760.00 1760.00 Profiler__.start_profile
43.01 2.16 0.40 115 3.48 3.91 ActiveRecord::ConnectionAdapters::Column#simplified_type
8.60 2.24 0.08 15 5.33 8.67 Array#each
7.53 2.31 0.07 115 0.61 5.39 ActiveRecord::ConnectionAdapters::Column#initialize
6.45 2.37 0.06 115 0.52 0.52 ActiveRecord::ConnectionAdapters::Column#type_cast
5.38 2.42 0.05 690 0.07 0.07 Regexp#===
0.00 2.69 0.00 10 0.00 0.00 Process.times
0.00 2.69 0.00 10 0.00 0.00 Benchmark.times
Note that for Rails 3, you can use rails profiler.
回答3:
rack bug is pretty cool http://github.com/brynary/rack-bug
回答4:
http://rails-analyzer.rubyforge.org/ might be what you're looking for.
I highly recommend the Production log Analyzer for a clear list of most time consuming actions and also the action profiler.
added: For the production log analyzer you don't need any configuration, it just parses the production log and gives you a list of most time consuming actions, including min/max/median time. Very good to see where you should profile/optimize more.
回答5:
Another one worth checking out is Mini Profiler: https://github.com/SamSaffron/MiniProfiler/tree/master/Ruby
It's used on StackExchange (although this version is ported to Ruby).
Here is a Railscast: http://railscasts.com/episodes/368-miniprofiler?view=asciicast
回答6:
If you are under OSX Leopard, you can give DTrace a try.
回答7:
You should also take a look at FiveRuns' TuneUp. It is completely free, installs as a plugin into your Rails application. Keep in mind that it does send data back to their server (mostly very harmless information), but that might bother some people (namely government agencies would be very unhappy about that). I think you'll be surprised how great the tool is considering it is free.
Another nice feature of it is that you can post your run data for others to comment and help you diagnose your long queries, or bad code.
来源:https://stackoverflow.com/questions/350470/what-tools-do-you-recommend-to-profile-rails-apps