# Ruby-prof on amd-64?

**URL:** <https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725>\
**Category:** Ruby\
**Created:** [November 20, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725 "2006-11-20T19:51:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 20, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/1 "2006-11-20T19:51:09Z")

</div>

Hi,

has anyone had any success getting ruby-prof working on amd64 linux?  
Specifically, has anyone managed to deal with this error, or know what  
it is referring to:

/home/dan/ruby$ ruby-prof prime.rb  
/usr/local/lib/ruby/gems/1.8/gems/ruby-prof-0.4.1/bin/ruby-prof:154:in  
`load': integer 23456248293192 too big to convert to`int’ (RangeError)  
from  
/usr/local/lib/ruby/gems/1.8/gems/ruby-prof-0.4.1/bin/ruby-prof:154  
from /usr/local/bin/ruby-prof:18

(this happens with any ruby script)

There are a couple of people who have mentioned it on the rubyforge  
project page but without any apparent resolutions, other than that  
nothing on google.

thanks,  
Dan

for ref:  
/home/dan/ruby$ uname -a  
Linux x1-6-00 2.6.15-27-amd64-generic #1 SMP PREEMPT Sat Sep 16 01:50:50  
UTC 2006 x86\_64 GNU/Linux  
/home/dan/ruby$ ruby -v  
ruby 1.8.4 (2005-12-24) [x86\_64-linux]

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 21, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/2 "2006-11-21T15:13:18Z")

</div>

Jan S. wrote:

> try ruby-prof bugtracker:  
> [http://rubyforge.org/tracker/index.php?func=detail&aid=5207&group\_id=1814&atid=7060](http://rubyforge.org/tracker/index.php?func=detail&aid=5207&group_id=1814&atid=7060)

Thank you for taking the time to reply, but that thread doesn’t actually  
solve the problem, just describe it. Any other ideas?

Dan

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 23, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/3 "2006-11-23T17:45:01Z")

</div>

Daniel,

As you probably know, most 64-bit processors use the LP64 model (i.e.  
ints are 32 bits, longs and pointers 64 bits). Many things that people  
assume are ints on a 32-bit system actually are longs on a 64 bit  
system. This is why people should really use the C types properly, in  
other words, size\_t for lengths and ptrdiff\_t for pointer arithmetic,  
instead of int. size\_t is unsigned on 32-bits, but unsigned long on 64  
bits. Also, I think thread ids are 32-bit on 32-bit systems, but 64-bit  
on 64-bit systems. Look at the type of pthread\_t in sys/types.h on your  
AMD-64 system.

So the following code from ruby\_prof.c is going to present problems on  
64 bit systems:

typedef struct {  
/\* Cache hash value for speed reasons. _/  
st\_data\_t key;  
VALUE klass;  
ID mid;  
int thread\_id; /_ Edwin says: should be pthread\_t thread\_id\*/  
… etc …  
}

Also, this code could be an issue:

static inline prof\_data\_t \*  
stack\_push(prof\_stack\_t _stack)  
{  
if (stack-\>ptr == stack-\>end) {  
int len, new\_capa; /_ Edwin says: Naughty, naughty - should use  
ptrdiff\_t len, not int len\*/  
len = stack-\>ptr - stack-\>start; /\* Edwin says: result is actually  
ptrdiff\_t, not int (ptrdiff\_t will be unsigned long on LP64)\*/  
new\_capa = (stack-\>end - stack-\>start) \* 2;  
REALLOC\_N(stack-\>start, prof\_data\_t, new\_capa);  
stack-\>ptr = stack-\>start + len;  
stack-\>end = stack-\>start + new\_capa;  
}  
return stack-\>ptr++;  
}

Judicious changes of int to a suitable portable data type would most  
likely solve these issues.

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 23, 2006, 7:46pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/4 "2006-11-23T19:46:07Z")

</div>

Edwin F. wrote:

> As you probably know, most 64-bit processors use the LP64 model (i.e.  
> ints are 32 bits, longs and pointers 64 bits).

Until now, not really 🙂

> Judicious changes of int to a suitable portable data type would most  
> likely solve these issues.

Woo-hoo! Yes it does, almost immediately. Thank you so much Edwin,  
you’ve been a big help. Oh, look at those pretty call graphs!

For future googlers, here is the diff from changes I made to get  
ruby-prof working on amd64, 64bit, after receiving an error like this:  
integer 23456248293320 too big to convert to `int’ (RangeError)

This is in ruby-prof-0.4.1/ext/ruby\_prof.c

## 64c64 \< int thread\_id;

> ```
> pthread_t thread_id;
> 
> ```

## 97c97 \< int thread\_id;

> ```
> pthread_t thread_id;
> 
> ```

## 258c258 \< static inline int

> static inline pthread\_t  
> 261c261  
> \< return NUM2INT(rb\_obj\_id(thread));

* * *

> ```
> return NUM2LONG(rb_obj_id(thread));
> 
> ```

## 387c387 \< int len, new\_capa;

> ```
> ptrdiff_t len, new_capa;
> 
> ```

## 921c921 \< static inline int

> static inline pthread\_t

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 24, 2006, 6:12am UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/5 "2006-11-24T06:12:50Z")

</div>

I’m glad it worked for you 🙂

Hopefully someone will put in a patch on RubyForge for the changes.

Regards,  
Edwin

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [November 20, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/ruby-prof-on-amd-64/76725/6 "2006-11-20T20:05:48Z")

</div>

On 11/20/06, Daniel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> /usr/local/lib/ruby/gems/1.8/gems/ruby-prof-0.4.1/bin/ruby-prof:154
> 
> for ref:  
> /home/dan/ruby$ uname -a  
> Linux x1-6-00 2.6.15-27-amd64-generic #1 SMP PREEMPT Sat Sep 16 01:50:50  
> UTC 2006 x86\_64 GNU/Linux  
> /home/dan/ruby$ ruby -v  
> ruby 1.8.4 (2005-12-24) [x86\_64-linux]

try ruby-prof bugtracker:  
[http://rubyforge.org/tracker/index.php?func=detail&aid=5207&group\_id=1814&atid=7060](http://rubyforge.org/tracker/index.php?func=detail&aid=5207&group_id=1814&atid=7060)
