45

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?

lsdr
  • 1,245
  • 1
  • 15
  • 28

7 Answers7

44

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.

Anthony Panozzo
  • 3,274
  • 1
  • 24
  • 22
mwilliams
  • 9,946
  • 13
  • 50
  • 71
  • 2
    Is there a way of calling a controller action or running a route through the profiler? I tried `get '/'` and other variations but could not get it to work. – Erik J Jul 06 '11 at 21:59
  • 2
    @ErikJ I had same need today, here's something I ended up using. https://gist.github.com/1389759 You can use it to check and profile your app by sending requests to it while being in a console or from a debugger. Hope it helps. – Kamil Sarna Nov 23 '11 at 20:13
20

New Relic offers Rails profiling including a free 'Lite' version.

luis.madrigal
  • 1,366
  • 1
  • 15
  • 31
Corbin March
  • 25,526
  • 6
  • 73
  • 100
  • 7
    Also, it's worth to mention that you can use "developer" mode, which allows you to use it locally without a NewRelic account. – Ivan Dec 28 '09 at 01:51
5

rack bug is pretty cool http://github.com/brynary/rack-bug

Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
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.

Cristian Vat
  • 1,602
  • 17
  • 18
3

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

Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144
  • Starting from Rails 6.1, `rack-mini-profiler` gem is added to the default Gemfile. https://github.com/rails/rails/pull/38701 – Marian13 Jun 08 '20 at 18:45
2

If you are under OSX Leopard, you can give DTrace a try.

akuhn
  • 27,477
  • 2
  • 76
  • 91
0

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.

Kevin Elliott
  • 2,630
  • 3
  • 23
  • 21