summaryrefslogtreecommitdiff
path: root/scripts/pmap.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-04-05 20:26:29 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2019-04-05 20:26:29 +0200
commit36b5ab0c83ad76a6a6b9ea4e97380a0f05ae332a (patch)
treed47fa1325b2e282438c2032383241e565578b928 /scripts/pmap.py
parentd286fea91fa93c6b5723e25ed89a803036e7c72f (diff)
downloadpsutil-36b5ab0c83ad76a6a6b9ea4e97380a0f05ae332a.tar.gz
improve pmap.py script
Diffstat (limited to 'scripts/pmap.py')
-rwxr-xr-xscripts/pmap.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/scripts/pmap.py b/scripts/pmap.py
index 988b7507..300f23e9 100755
--- a/scripts/pmap.py
+++ b/scripts/pmap.py
@@ -9,7 +9,6 @@ A clone of 'pmap' utility on Linux, 'vmmap' on macOS and 'procstat -v' on BSD.
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
@@ -33,9 +32,12 @@ ffffffffff600000 0K r-xp [vsyscall]
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:
@@ -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__':