Created
July 2, 2012 18:45
-
-
Save apeiros/3034844 to your computer and use it in GitHub Desktop.
Prints memory and cpu footprint of the server (uses ps in a subshell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
# Prints memory and cpu footprint of the server (uses ps in a subshell, | |
# portability is therefore limited) | |
def print_resource_usage | |
ps_out = `ps -o vsz,rss,%cpu,%mem -p #{$$}` | |
vsz, rss, cpu, pmem = ps_out.scan(/\d+(?:[.,]\d+)?/).map { |e| e.gsub(/,/,'.').to_f } # ps on 10.5.1 outputs ',' instead of '.' for MEM% | |
virtual, real = (vsz-rss).div(1024), rss.div(1024) | |
$stdout.printf "%dMB real, %dMB virtual, %.1f%% CPU, %.1f%% MEM\n", real, virtual, cpu, pmem | |
end | |
module_function :print_resource_usage | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment