Ruby-prof-0.4.0

Shugo and I are happy to announce the release of ruby-prof 0.4.0, which
is chock full of new features:

  • Addition of call graph profiles similar to GProf

  • Improved speed - overhead is now as low as 15% for some code, although
    you should generally expect around 50%

  • Full support for multiple threads

  • New cross-referenced html reports

  • New ruby-prof script that makes it easy to profile your programs
    without modifying them

  • Vastly improved documentation

  • Detection of recursive calls and call cycles

  • Support for windows

Best of all, ruby-prof is now distributed as a gem so it’s as easy to
install as:

gem install ruby-prof

If you’re on Windows, the gem includes a pre-built windows binary. If
you’re on Linux or Unix, the binary will be automatically built on
intallation.

Hope it helps people,

Charlie


ruby-prof at RubyForge:
http://rubyforge.org/projects/ruby-prof/

Documentation:
http://ruby-prof.rubyforge.org/

More info -
http://cfis.savagexi.com/articles/2006/06/21/ruby-prof-0-4-0-with-call-graphs

On Thu, Jun 22, 2006 at 04:19:58AM +0900, Charlie S. wrote:

Shugo and I are happy to announce the release of ruby-prof 0.4.0, which
is chock full of new features:

[good stuff]

I was in the process of adding some of that to rcov (building on top of
your
win32-compatible branch), but you guys beat me to it => no reason to
release
rcov 0.7.0 anymore :slight_smile:

The feature list is impressive, the documentation looks good, and
the release seems solid. Kudos to you both.

Hi Mauricio,

Thanks for the kind of words - and great work on rcov, I use it
everyday. I was actually hoping rcov would have the call graphs, but I
needed the functionality as soon as possible and wasn’t sure rcov would
add it :slight_smile:

Anyway, I’ll follow with an email to you and Shugo to see it makes sense
combining ruby-prof and rcov in some way.

Charlie

On Thu, Jun 22, 2006 at 04:19:58AM +0900, Charlie S. wrote:

Shugo and I are happy to announce the release of ruby-prof 0.4.0, which
is chock full of new features:

  • Addition of call graph profiles similar to GProf

  • Improved speed - overhead is now as low as 15% for some code, although
    you should generally expect around 50%

I tried to profile rcov (while running its own unit tests), and ran into
this:

$ ruby-prof -p graph_html -c cpu -f prof.html bin/rcov – -I
lib:ext/rcovrt/ -T --no-html test/test_*
Loaded suite /home/batsman/usr/bin/ruby-prof
Started

Finished in 3.660745 seconds.

41 tests, 438 assertions, 0 failures, 0 errors
±---------------------------------------------------±------±------±-------+
| File | Lines | LOC | COV |
±---------------------------------------------------±------±------±-------+
|lib/rcov.rb | 934 | 558 | 88.0% |
±---------------------------------------------------±------±------±-------+
|Total | 934 | 558 | 88.0% |
±---------------------------------------------------±------±------±-------+
88.0% 1 file(s) 934 Lines 558 LOC
/home/batsman/usr/lib/ruby/gems/1.8/gems/ruby-prof-0.4.0/bin/ruby-prof:128:in
`stop’: The name has already been assigned to another method. This is
a bug - please report it. (RuntimeError)
from
/home/batsman/usr/lib/ruby/gems/1.8/gems/ruby-prof-0.4.0/bin/ruby-prof:128

I applied this to see what was going on:

— ruby_prof.c.orig 2006-06-22 09:40:32.000000000 +0200
+++ ruby_prof.c.mod 2006-06-22 09:42:07.000000000 +0200
@@ -880,7 +880,7 @@
/* Definitely should never happen! */
rb_raise(rb_eRuntimeError,
“The name %s has already been assigned to another
method. This is a bug - please report it.”,

  •             name);
    
  •             StringValuePtr(name));
    
    }
    rb_hash_aset(hash, name, prof_method_new(method));

… and found what is causing the problem. rcov’s tests do something
like:

[email protected]:~/mess/current$ cat ruby-prof-bomb.rb
str = %{module Foo; class Bar; def foo; end end end}
eval str
Foo::Bar.new.foo
Object.class_eval{ remove_const :Foo }
eval str
Foo::Bar.new.foo

[email protected]:~/mess/current$ ruby-prof -p graph ruby-prof-bomb.rb
/home/batsman/usr/lib/ruby/gems/1.8/gems/ruby-prof-0.4.0/bin/ruby-prof:128:in
`stop’: The name Foo::Bar#foo has already been assigned to another
method. This is a bug - please report it. (RuntimeError)
from
/home/batsman/usr/lib/ruby/gems/1.8/gems/ruby-prof-0.4.0/bin/ruby-prof:128
from /home/batsman/usr/bin/ruby-prof:18

I really wanted to get a call graph, so I applied the following naïve
patch:

— ruby_prof.c.orig 2006-06-22 09:40:32.000000000 +0200
+++ ruby_prof.c 2006-06-22 09:42:53.000000000 +0200
@@ -875,12 +875,9 @@
overwrite the reference to the other prof_method. That will
mean that Ruby
will garbage collect it wreaking all sorts of havoc! Trust me -
this one took
a long time to track down. */

  • if (existing_value != Qnil)
  • {
  •    /* Definitely should never happen! */
    
  •    rb_raise(rb_eRuntimeError,
    
  •             "The name %s has already been assigned to another 
    

method. This is a bug - please report it.",

  •             name);
    
  • while(existing_value != Qnil) {
  •   rb_str_cat(name, "'", 1);
    
  •   existing_value = rb_hash_aref(hash, name);
    
    }
    rb_hash_aset(hash, name, prof_method_new(method));

ruby_prof seems to work now, and there are two separate entries in the
call
graph for Foo::Bar#foo (see the attached ruby-prof-out-ok.txt). I think
keeping them that way, as opposed to consolidating them, makes sense,
since
they could have been entirely different methods.

Before I forget, a minor nitpick }:slight_smile:
Could you release a tarball through Rubyforge, in addition to the
RubyGems
packages? Some systems like FreeBSD’s ports are happier when there’s an
online accessible tarball. Other repackagers will appreciate too.

Charlie S. wrote:

Documentation:
http://ruby-prof.rubyforge.org/

In the README (online, anyway), you have:

result = RubyProf.end

When really, it’s

result = RubyProf.stop

This was difficult to track down [in my curses app which does not print
to stderr or stdout]. :slight_smile:

Pistos

Hi Pistos,

Yup - thanks for the catch.

Documentation is updated in ruby-prof-0.4.1 (just released).

Charlie

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs