# Ruby-prof-0.4.0

**URL:** <https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078>\
**Category:** Ruby\
**Created:** [June 21, 2006, 9:23pm UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078 "2006-06-21T21:23:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 21, 2006, 9:23pm UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/1 "2006-06-21T21:23:38Z")

</div>

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/](http://rubyforge.org/projects/ruby-prof/)

Documentation:  
[http://ruby-prof.rubyforge.org/](http://ruby-prof.rubyforge.org/)

More info -

> **[ruby-prof 0.4.0 with call graphs | CFIS](https://cfis.savagexi.com/2006/06/21/ruby-prof-0-4-0-with-call-graphs/)**
>
> Update: ruby-prof 0.5.0 is now available and has significantly more features than 0.4.0, including better threading support, rails support, call tree output, etc. After porting ruby-prof to Windows a couple of weeks ago, Shugo Maeda, ruby-prof's...

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 22, 2006, 12:03am UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/2 "2006-06-22T00:03:21Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 22, 2006, 1:28am UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/3 "2006-06-22T01:28:28Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 22, 2006, 10:24am UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/4 "2006-06-22T10:24:37Z")

</div>

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:

batsman@tux-chan:~/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

batsman@tux-chan:~/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 }🙂  
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.

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 22, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/5 "2006-06-22T20:08:44Z")

</div>

Charlie S. wrote:

> Documentation:  
> [http://ruby-prof.rubyforge.org/](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]. 🙂

Pistos

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [June 23, 2006, 12:09am UTC](https://www.ruby-forum.com/t/ruby-prof-0-4-0/64078/6 "2006-06-23T00:09:33Z")

</div>

Hi Pistos,

Yup - thanks for the catch.

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

Charlie
