Module: Resque::Plugins::MultiJobForks::RssReader
- Extended by:
- RssReader
- Defined in:
- lib/resque/plugins/multi_job_forks/rss_reader.rb
Constant Summary collapse
- LINUX =
RbConfig::CONFIG['host_os'].start_with?('linux')
- PS_CMD =
"ps -o rss= -p %d".freeze
- UNITS =
{ b: 1024**-1, kb: 1024**0, mb: 1024**1, gb: 1024**2, tb: 1024**3, }.freeze
Instance Method Summary collapse
-
#rss(pid = Process.pid) ⇒ Object
Returns RSS in Kb; should work on Linux and Mac OS X.
-
#rss_linux(pid = Process.pid) ⇒ Object
Read from /proc/$pid/status.
-
#rss_posix(pid = Process.pid) ⇒ Object
Fork/exec ps and parse result.
Instance Method Details
#rss(pid = Process.pid) ⇒ Object
Returns RSS in Kb; should work on Linux and Mac OS X
17 18 19 |
# File 'lib/resque/plugins/multi_job_forks/rss_reader.rb', line 17 def rss(pid=Process.pid) LINUX ? rss_linux(pid) : rss_posix(pid) end |
#rss_linux(pid = Process.pid) ⇒ Object
Read from /proc/$pid/status. Linux only. MUCH faster and doesn’t incur significant memory cost.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resque/plugins/multi_job_forks/rss_reader.rb', line 29 def rss_linux(pid=Process.pid) File.open("/proc/#{pid}/status") do |file| file.each_line do |line| if line[/^VmRSS/] _,c,u = line.split return (c.to_i * UNITS[u.downcase.to_sym]).to_i end end end end |
#rss_posix(pid = Process.pid) ⇒ Object
Fork/exec ps and parse result. Should work on any system with POSIX ps.
23 24 25 |
# File 'lib/resque/plugins/multi_job_forks/rss_reader.rb', line 23 def rss_posix(pid=Process.pid) `#{PS_CMD % [pid]}`.to_i end |