# How to monitor memory consumed by a method?

**URL:** <https://www.ruby-forum.com/t/how-to-monitor-memory-consumed-by-a-method/164004>\
**Category:** Ruby\
**Created:** [March 26, 2009, 7:45pm UTC](https://www.ruby-forum.com/t/how-to-monitor-memory-consumed-by-a-method/164004 "2009-03-26T19:45:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paganoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@Paganoni](https://www.ruby-forum.com/u/Paganoni)\
**Post date:** [March 26, 2009, 7:45pm UTC](https://www.ruby-forum.com/t/how-to-monitor-memory-consumed-by-a-method/164004/1 "2009-03-26T19:45:46Z")

</div>

Hello, I’ve written a library that handle csv conversion…  
Files are big, themselves related and the conversion rules needs several  
hashes.  
Those data will grow up month after month, so I would like to know how  
many memory this import method can consume.

The only idea I had is launching the linux utility pmap before and after  
the method.

Is there any other solution ?

Thanks

---

<div class="post-metadata">

**Author:** ![Paganoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@Paganoni](https://www.ruby-forum.com/u/Paganoni)\
**Post date:** [March 27, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/how-to-monitor-memory-consumed-by-a-method/164004/2 "2009-03-27T17:04:38Z")

</div>

2009/3/26 Peter Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > Is there any other solution ?
> 
> Try doing GC.disable before calling method and then ps aux, for example. I  
> think this is simplier.

That way you will see how much memory the process uses up but not, how  
much of that must be attributed to the code in the method in question.  
Note that Ruby may allocate memory from the OS in larger chunks in  
order to prevent too frequent malloc calls and fragmentation. I am  
not sure how helpful that is for the OP’s problem.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![Paganoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@Paganoni](https://www.ruby-forum.com/u/Paganoni)\
**Post date:** [March 26, 2009, 8:01pm UTC](https://www.ruby-forum.com/t/how-to-monitor-memory-consumed-by-a-method/164004/3 "2009-03-26T20:01:39Z")

</div>

Quoting P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hello, I’ve written a library that handle csv conversion…  
> Files are big, themselves related and the conversion rules needs  
> several hashes.  
> Those data will grow up month after month, so I would like to know  
> how many memory this import method can consume.
> 
> The only idea I had is launching the linux utility pmap before and  
> after the method.
> 
> Is there any other solution ?

Try doing GC.disable before calling method and then ps aux, for  
example. I think this is simplier.

WBR, Peter Z.
