Resident Memory Size Logging

Hello:

Is there a way to get the resident memory size of the rails process in-
code using ruby? I’d like to have my application log the size of its
own memory.

Thank you in advance,

Dan

BTW, this is one way of doing it under Linux:
Opening “/proc/$pid/status” and looking for VmSize.

Not sure if there is a more efficient.

Dan

Dan wrote:

Hello:

Is there a way to get the resident memory size of the rails process in-
code using ruby? I’d like to have my application log the size of its
own memory.

Thank you in advance,

Dan

(Given your followup post mentions your running linux …)

in your controller or in application.rb


after_filter :after_req_resource_usage

def after_req_resource_usage
ps_info = ps -o psr,etime,pcpu,pmem,rss,vsz -p #{Process.pid} | grep -v CPU
ignore, psr, elapsed, pcpu, pmem, rss, vsz = ps_info.split(/\s+/)
logger.info(“pid=#{Process.pid} pcpu=#{pcpu} pmem=#{pmem} rss=#{rss}
vsz=#{vsz}”)
end