Announcing ruby-prof 0.5.0

Make sure to grab the latest version of ruby-prof, currently 0.5.2, which includes some performance tweaks and bug fixes.

A year has passed since the last release of ruby-prof. If you haven’t used ruby-prof, its a superfast, open-source, profiler for Ruby that shows you where your program is slow.

Over the last few months the list of bugs and enhancements on Ruby Forge has been accumulating at an embarassing rate. And not to mention, I need to profile our rails app.

So its time for another release.
And this isn’t just a minor bug fix release – its a major update that adds lots of new stuff. To install it, open a command prompt and type:

gem install ruby-prof

Then pick the appropriate gem for your platform.

Multithreaded Applications

The most important change is support for multi-threaded applications. Previously, ruby-prof correctly recognized the threads in a program and their independent call stacks, but it got the thread times wrong. ruby-prof would incorrectly add a child thread’s time to a parent thread’s time, making hard to figure out where the time in a program was spent. Now, ruby-prof keeps track of a thread’s “wait time,” which is the time it spends waiting for other threads. Thanks to Sylvain Joyeux for a patch that got the ball rolling on better thread support.

Measurement Modes

Sylvain also submitted a second patch that suprised me. Instead of tracking method times, why not track object allocations? That seemed reasonable, but he implemented it as another type of clock mode (ruby-prof supports 3 different ways of measuring time – process time, wall time and cpu time).

At first I was hesitant about the patch – shoehorning object allocations into clock modes didn’t make much sense to me. But after thinking about it a bit, I decided Sylvain was onto something. Instead of thinking about “clock modes” I started thinking about “measurement modes” (catchy, isn’t it?). And once you have that perspective, then it makes sense for ruby-prof to measure all sorts of things in a running program – time, object allocations, memory usage, etc.

So with a bit of refactoring, ruby-prof’s now supports for “measure modes.” They are process time, wall time, cpu time an object allocation. And now its easy to add more if anyone wants to submit a patch!

I should note there is one downside to the object allocations mode – it only works if you have a patched Ruby interpreter (if you don’t ruby-prof works fine, you just don’t get access to allocation information).

Rails

What use would a Ruby profiler be if it didn’t work with Rails? ruby-prof now provides some hooks to make easier to profile your rails app. But I’ll leave those for a future blog post.

Call Graph Format

Carl Shimer implemented support for the call graph format which is used by KCachegrind to visualize calling information.

Recursive Methods

Finally, ruby-prof has much improved support for recursive method calls as explained in the updated readme file.

Bug Fixes

And last, this release fixes some nasty bugs:

Unknown Singleton Object – This was a tough one since I didn’t understand how to reproduce it. But luckily Matthew Fallshaw submitted a reproducable test case, and from there it was just a matter of reading the translated version of the Ruby Hacking Guide to unravel the mysteries of Ruby’s singleton classes.

64-bit support – The 0.4.x releases used ints to store pointers instead of longs, which meant they didn’t compile and/or work on 64 bit machines. This is now fixed thanks to a patch submitted by Diego ‘Flameeyes’ Pettenò.

IRB support – Previously you couldn’t start ruby-prof in a method and then exit that method. Which meant that ruby-prof couldn’t be used in IRB. That restriction has now been removed.

sort order – The sort orderan in generated reports was wrong. Graph reports now sort based on a method’s total percent time while flat reports use a method’s self percent time.

So give version 0.5.0 a try and see how you like it!

  1. July 22, 2007

    Really cool. I didn’t know your gem. I’m going to release a major version of a Rails application, and your package could be really precious to my team.
    Thanks a lot

    Reply
  2. Charlie Savage –
    July 22, 2007

    Hi Massimo,

    Thanks – and good luck with your application. If you find any performance bottlenecks with ruby-prof, I’d love to hear about them.

    Reply

Leave a Reply

Your email address will not be published.

Top