I\'d like to format my Logger output to include the current memory usage, for part of a long-running process.
Is there anything built-in to Ruby for thi
When trying to solve this problem a year ago, I did a lot of online research and API digging and was only able to solve it via a system call to ps.
In both OS X 10.7.2 and Red Hat 4.1.2-13 (on EC2):
pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
This fetches and places the resident memory size of the process in kilobytes into the size variable.
With a little effort this could be cleaned up, but most of the time is spend calling ps and capturing its output, so I don't think it is worth the time.