Skip to content

Commit

Permalink
improve pmap.py script
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 5, 2019
1 parent d286fea commit 36b5ab0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 8 additions & 6 deletions scripts/pmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Report memory map of a process.
$ python scripts/pmap.py 32402
pid=32402, name=hg
Address RSS Mode Mapping
0000000000400000 1200K r-xp /usr/bin/python2.7
0000000000838000 4K r--p /usr/bin/python2.7
Expand All @@ -33,9 +32,12 @@
import sys

import psutil
from psutil._common import bytes2human
from psutil._compat import get_terminal_size


def safe_print(s):
s = s[:get_terminal_size()[0]]
try:
print(s)
except UnicodeEncodeError:
Expand All @@ -46,19 +48,19 @@ def main():
if len(sys.argv) != 2:
sys.exit('usage: pmap <pid>')
p = psutil.Process(int(sys.argv[1]))
print("pid=%s, name=%s" % (p.pid, p.name()))
templ = "%-16s %10s %-7s %s"
templ = "%-20s %10s %-7s %s"
print(templ % ("Address", "RSS", "Mode", "Mapping"))
total_rss = 0
for m in p.memory_maps(grouped=False):
total_rss += m.rss
safe_print(templ % (
m.addr.split('-')[0].zfill(16),
str(m.rss / 1024) + 'K',
bytes2human(m.rss),
m.perms,
m.path))
print("-" * 33)
print(templ % ("Total", str(total_rss / 1024) + 'K', '', ''))
print("-" * 31)
print(templ % ("Total", bytes2human(total_rss), '', ''))
safe_print("PID = %s, name = %s" % (p.pid, p.name()))


if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion scripts/winservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
Appinfo (Application Information)
status: stopped, start: manual, username: LocalSystem, pid: None
binpath: C:\Windows\system32\svchost.exe -k netsvcs
...
"""

Expand Down

0 comments on commit 36b5ab0

Please sign in to comment.