Skip to content

Instantly share code, notes, and snippets.

@fabrizioc1
Last active December 12, 2015 00:48
Show Gist options
  • Save fabrizioc1/4686339 to your computer and use it in GitHub Desktop.
Save fabrizioc1/4686339 to your computer and use it in GitHub Desktop.
Estimate Linux process memory usage
# can probably cross reference with ltrace
# this removes shared libraries from the total memory count
def memory_estimate(pid)
`sudo pmap #{pid}`.lines.reject{|line|
line[%r[/lib[^.]+\.so]] or line[/^ total/]
}.drop(1).reduce(0){|total,line|
total + line.match(/(\d+)K/)[1].to_i
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment