Getting memory usage of my process from OSX using Ruby

后端 未结 3 498
星月不相逢
星月不相逢 2021-02-03 10:49

I have a Ruby app which (on Linux) uses the /proc filesystem to get information on its memory usage. Does anyone know how to get the same information for Mac OSX? The task_info

相关标签:
3条回答
  • 2021-02-03 11:31

    Referring to this answer it seems like you need to call proc_pidinfo(). I don't think there's a Ruby equivalent, so either you'll have to write a C-extension or use the ruby-ffi gem.

    Other sources indicate Ruby 1.9.2 ships with a built in FFI -- but that version is not delivered with OS X.

    0 讨论(0)
  • 2021-02-03 11:39

    The OS gem has an rss_bytes method that works for Linux/windows/OS X ...

    0 讨论(0)
  • 2021-02-03 11:49

    Taken from http://laurelfan.com/2008/1/15/ruby-memory-usage:

    memory_usage = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes 
    

    Verified to work in both Linux and OS X.

    This returns the number of bytes that the process has resident in memory, excluding any that are swapped out

    To get the total virtual memory size including swap, change rss to vsz (tested in Linux, but not tested in OSX):

    memory_usage = `ps -o vsz= -p #{Process.pid}`.to_i # in kilobytes 
    
    0 讨论(0)
提交回复
热议问题