michael@0: #!/usr/bin/env python michael@0: michael@0: # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """ michael@0: A clone of 'pmap' utility on Linux, 'vmmap' on OSX and 'procstat -v' on BSD. michael@0: Report memory map of a process. michael@0: """ michael@0: michael@0: import sys michael@0: michael@0: import psutil michael@0: from psutil._compat import print_ michael@0: michael@0: def main(): michael@0: if len(sys.argv) != 2: michael@0: sys.exit('usage: pmap pid') michael@0: p = psutil.Process(int(sys.argv[1])) michael@0: print_("pid=%s, name=%s" % (p.pid, p.name)) michael@0: templ = "%-16s %10s %-7s %s" michael@0: print_(templ % ("Address", "RSS", "Mode", "Mapping")) michael@0: total_rss = 0 michael@0: for m in p.get_memory_maps(grouped=False): michael@0: total_rss += m.rss michael@0: print_(templ % (m.addr.split('-')[0].zfill(16), michael@0: str(m.rss / 1024) + 'K' , michael@0: m.perms, michael@0: m.path)) michael@0: print_("-" * 33) michael@0: print_(templ % ("Total", str(total_rss / 1024) + 'K', '', '')) michael@0: michael@0: if __name__ == '__main__': michael@0: main()