[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Function to Display Ruby Memory Usage

Michael W. Ryder

1/7/2008 1:32:00 AM

In Business Basic there is a function, DSZ, that shows the current
amount of memory used by the program code and data. This was obviously
more useful in the past where each user might have only 16 KB of memory
available. I was wondering if Ruby had something similar while thinking
about a program. The brute force method could easily take many GB of
memory to solve the problem, while a better algorithm might take a few KB.
Something like this may be useful if developing a program to run on both
a modern PC and something like a cell phone. One could see if they are
using too much memory or if it increases as the problem gets bigger.
2 Answers

M. Edward (Ed) Borasky

1/7/2008 4:07:00 AM

0

Michael W. Ryder wrote:
> In Business Basic there is a function, DSZ, that shows the current
> amount of memory used by the program code and data. This was obviously
> more useful in the past where each user might have only 16 KB of memory
> available. I was wondering if Ruby had something similar while thinking
> about a program. The brute force method could easily take many GB of
> memory to solve the problem, while a better algorithm might take a few KB.
> Something like this may be useful if developing a program to run on both
> a modern PC and something like a cell phone. One could see if they are
> using too much memory or if it increases as the problem gets bigger.

I don't know how to do this on Windows, MacOX or BSD, but on Linux, you
can pick up your PID using a call to Process.pid. Then you can shell out
to "pmap" and parse the result, which tells you all the segments and
whether they are mapped to shared libraries or inside the Ruby
executable. The code would look something like this:

pid = Process.pid
map = `pmap -d #{pid}`

# code to parse and analyze the map goes here

See

http://www.linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-m...
http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-...

While you're at it, you could do the same for the PIDs of your web
server and database in Rails. :)


Jano Svitok

1/7/2008 2:58:00 PM

0

On Jan 7, 2008 5:06 AM, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:
>
> Michael W. Ryder wrote:
> > ...
> I don't know how to do this on Windows, MacOX or BSD, but on Linux, you
> can pick up your PID using a call to Process.pid. Then you can shell out
> to "pmap" and parse the result, which tells you all the segments and
> whether they are mapped to shared libraries or inside the Ruby
> executable. The code would look something like this:
>
> pid = Process.pid
> map = `pmap -d #{pid}`
>

You'll find (much simpler) version for windows in the archive in
thread 'The real difference between Mutex and Sync'. Search for
'pslist'.