Function to Display Ruby Memory Usage

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.

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-memory.html
http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html

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

On Jan 7, 2008 5:06 AM, M. Edward (Ed) Borasky [email protected]
wrote:

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’.

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