How can I profile Ruby code in 1.9.2?
Asked Answered
B

3

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?

Bradbradan answered 8/3, 2011 at 21:50 Comment(2)
And it doesn't segfault when you don't have gem "ruby-prof" but run the bundle commands?Aleutian
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.Bradbradan
P
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

Prunella answered 9/3, 2011 at 13:48 Comment(0)
C
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`
Casmey answered 17/9, 2012 at 18:39 Comment(0)
W
2

You can use another popular profiler tool - MethodProfiler

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

Wanting answered 17/9, 2012 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.