Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I profile Ruby code in 1.9.2?

What can I use to profile code in 1.9.2? All of the versions of ruby-prof I've found segfault against 1.9.2.

For instance, when I add

gem "ruby-prof"

to my Rails project's Gemfile and run

bundle
bundle exec ruby-prof config/environment.rb

I get a segfault.

Is there a new profiling gem in town? Is there a way to make ruby-prof play nice?

like image 655
Peeja Avatar asked Mar 08 '11 21:03

Peeja


3 Answers

Not sure it helps but I stumbled on this which may add a bit more clarity or lead you down a different path: http://www.devheads.net/development/ruby/core/segmentation-fault-when-using-ruby-prof-and-ruby-192.htm. You may want to check out wycats' fork based on that thread: https://github.com/wycats/ruby-prof

Also, I have not tried it out myself and it may not be exactly what you are looking for but Aman of Github fame has a port of google-perftools for Ruby: https://github.com/tmm1/perftools.rb

like image 173
chris.baglieri Avatar answered Nov 05 '22 20:11

chris.baglieri


As @chris.baglieri suggested, you can use the perftools.rb gem for profiling Ruby 1.9 code.

gem install perftools.rb

Then

require 'perftools'
PerfTools::CpuProfiler.start('profile_data') do
  # something cpu-intensive
end
`pprof.rb --text profile_data profile.txt`
`pprof.rb --pdf  profile_data profile.pdf`
like image 26
Alex D Avatar answered Nov 05 '22 19:11

Alex D


You can use another popular profiler tool - MethodProfiler

It's very handy to find slow method in the target class.

like image 34
megas Avatar answered Nov 05 '22 20:11

megas