Created
December 5, 2012 13:33
-
-
Save tuxdna/4215536 to your computer and use it in GitHub Desktop.
Script find usage of shared libraries of a running process
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
#!/usr/bin/env ruby | |
# filename="/proc/5952/maps" | |
def usage | |
puts "USAGE: #{$0} /proc/<pid>/maps" | |
exit | |
end | |
filename=ARGV[0] | |
usage unless filename | |
libs = {} | |
File.open(filename).readlines.each do |line| | |
entries = line.split(/\s+/) | |
# p [ entries, entries.size] | |
if entries.size == 6 then | |
libname = entries[-1] | |
if libname =~ /\.so/ then | |
start_mem,to_mem = entries[0].split("-") | |
bytes = to_mem.hex - start_mem.hex | |
# puts "#{libname}: #{bytes/1024.0} KBs" | |
if libs[libname] then | |
old_val = libs[libname] | |
new_val = (old_val || 0) + bytes | |
libs[libname] = new_val | |
else | |
libs[libname] = bytes | |
end | |
end | |
end | |
end | |
total = 0 | |
libs.keys.sort.each do | k | | |
libname = k | |
bytes = libs[k] | |
puts "#{libname}: #{bytes/1024.0} KBs" | |
total += bytes | |
end | |
puts "total memory consumption by shared libraries: #{total/1024.0} KBs ( #{total/1024.0/1024} MBs )" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment