Monday, July 7, 2008

oprofile is my new best friend

For those of you who haven't been following the Ruby mailing lists, I've spent a fair amount of time over the long weekend getting up to speed on "oprofile" as a tool to dig into Ruby performance. There haven't been any great surprises beyond what I learned last year with "gcov" and "gprof" (https://rubyforge.org/docman/view.php/977/2705/Slides.pdf), but what is new is how much you can learn with oprofile.

All of you on Windows, MacOS and Solaris can stop reading now. oprofile is only available on Linux. The clever thing about oprofile is that you can profile your entire workload. Ruby, Rails, Apache, the database and the kernel -- oprofile tracks them all. And you don't have to recompile anything with special flags unless you want to get down to the exact line of code. You can even profile optimized code!

There's one more thing oprofile gives you -- down-to-the-hardware analysis. If you want it, you can get an annotated assembly language listing and learn where your code is generating cache misses, page faults, pipeline stalls, branch prediction failures -- anything that can bottleneck your code.

I'm planning to post a more detailed how-to for using oprofile to find Ruby/Rails application bottlenecks, but for now, there are some sample profiles I made over the weekend for MRI, KRI and Rubinius on RubyForge. They're all in http://cougar.rubyforge.org/svn/trunk/PTR2/. From there, look in "*_benchmark_oprof_reports". The benchmark in question is the Ruby Benchmark Suite, started by Antonio Cangiano and maintained on GitHub at http://github.com/acangiano/ruby-benchmark-suite/tree/master.

Stay tuned! To paraphrase Mark Twain, "Everybody talks about Ruby performance, but we're doing something about it!"

1 comments:

Roger Pack said...

I'd imagine profiling rails would be the most useful...though I could be wrong :)
-=r