Skip to content

Instantly share code, notes, and snippets.

@sshaw
Forked from itsderek23/rusage.rb
Last active October 19, 2017 13:55
Show Gist options
  • Save sshaw/c5d321df26407f1af3fef419cb49334a to your computer and use it in GitHub Desktop.
Save sshaw/c5d321df26407f1af3fef419cb49334a to your computer and use it in GitHub Desktop.
require 'get_process_mem'
require 'rusage' # gem install rusage
require 'benchmark'
n = 2000
gpm = GetProcessMem.new
Benchmark.bm(10) do |x|
x.report("status:") { n.times do gpm.linux_status_memory end }
# In sshaw version
x.report("statm:") { n.times do gpm.linux_statm_memory end }
x.report("rusage:") { n.times do Process.rusage.maxrss end }
end
gpm.mb
Process.rusage.maxrss
@sshaw
Copy link
Author

sshaw commented Apr 22, 2016

OS

~/ruby/c5d321df26407f1af3fef419cb49334a >lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 20 (Heisenbug)
Release:    20
Codename:   Heisenbug

/proc/$$/status

v2.2.4

~/ruby/c5d321df26407f1af3fef419cb49334a >ruby -vI ../get_process_mem/lib rusage.rb 
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
/home/sshaw/ruby/get_process_mem/lib/get_process_mem.rb:50: warning: shadowing outer local variable - line
                 user     system      total        real
gpm:         0.030000   0.030000   0.060000 (  0.066675)
rusage:      0.000000   0.000000   0.000000 (  0.002116)

v2.1.6

~/ruby/c5d321df26407f1af3fef419cb49334a >ruby -vI ../get_process_mem/lib rusage.rb 
ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
/home/sshaw/ruby/get_process_mem/lib/get_process_mem.rb:52: warning: shadowing outer local variable - line
                 user     system      total        real
gpm:         0.040000   0.040000   0.080000 (  0.080396)
rusage:      0.000000   0.000000   0.000000 (  0.001993)

/proc/$$/statm

v2.1.6

ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
/home/sshaw/ruby/get_process_mem/lib/get_process_mem.rb:52: warning: shadowing outer local variable - line
                 user     system      total        real
status:      0.040000   0.030000   0.070000 (  0.079459)
statm:       0.010000   0.000000   0.010000 (  0.018616)
rusage:      0.000000   0.000000   0.000000 (  0.001794)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment