8

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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Peeja
  • 13,683
  • 11
  • 58
  • 77
  • And it doesn't segfault when you don't have `gem "ruby-prof"` but run the bundle commands? – Andrew Grimm Mar 08 '11 at 22:10
  • Well, if I don't have `ruby-prof` in the bundle, then I can't `bundle exec ruby-prof`. But `bundle exec ruby config/environment.rb` doesn't segfault. – Peeja Mar 09 '11 at 03:44

3 Answers3

2

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`
Alex D
  • 29,755
  • 7
  • 80
  • 126
2

You can use another popular profiler tool - MethodProfiler

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

megas
  • 21,401
  • 12
  • 79
  • 130
2

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

chris.baglieri
  • 191
  • 1
  • 7