python/psutil/examples/pmap.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial