Profiling in Rails

I have a large view that takes a very long time to complete it. What is the best way to profile which part of the view takes the most time? I read about ruby-prof, but I'm not sure where to paste it in order to profile rendering. If there are other options, I also want to know them.

+5
source share
4 answers

The easiest way to quickly get to a bottleneck is to use the NewRelics development mode, which works locally.

  • Make sure your Gemfile has ruby-profand newrelic_rpm.
  • Go to localhost:3000/newrelicand start profiling (in the right pane)
  • , , , , , .
  • , .
  • "self". , .
  • 10 , , , , .

: newrelic, . , .

+8

, . HAML, ruby-prof. :

  - @collection.each do |x|
    = render :partial => 'name', :locals => {:object => x}

, ruby-prof Gemfile :

  - require 'ruby-prof'
  - RubyProf.start
  - @collection.each do |x|
    = render :partial => 'name', :locals => {:object => x}
  - result = RubyProf.stop
  - printer = RubyProf::CallStackPrinter.new(result)
  - file = File.open('profile.html', 'w')
  - printer.print(file)
  - file.close

, profile.html , , .

+3

NewRelic , . NewRelic , , , ruby-prof, , , .

, , . , , db, , .

https://github.com/brynary/rack-bug/

, ruby-prof, , - . , Rails-. , , ,

( ):   <% = time_zone_select: user,: time_zone, TZInfo:: Country.get( "US" ). , {}% >

:   <% = f.time_zone_select: time_zone, ActiveSupport:: TimeZone.us_zones,: default = > " ( )" % >

/:

orig template render          1392.91
fixed template render         165.56
fixed on REE instead of 1.8.7 100.70

, , , .

+1
source

If you have not done so, first check the folder login the application folder. It contains log files for each environment of your application.

To profile your rails application, put your tests in a folder your_app/test/profile

http://ruby-prof.rubyforge.org/

0
source

All Articles