contrib/memory.py
changeset 43076 2372284d9457
parent 31958 de5c9d0e02ea
child 46819 d4ba4d51f85f
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    11 prints it to ``stderr`` on exit.
    11 prints it to ``stderr`` on exit.
    12 '''
    12 '''
    13 
    13 
    14 from __future__ import absolute_import
    14 from __future__ import absolute_import
    15 
    15 
       
    16 
    16 def memusage(ui):
    17 def memusage(ui):
    17     """Report memory usage of the current process."""
    18     """Report memory usage of the current process."""
    18     result = {'peak': 0, 'rss': 0}
    19     result = {'peak': 0, 'rss': 0}
    19     with open('/proc/self/status', 'r') as status:
    20     with open('/proc/self/status', 'r') as status:
    20         # This will only work on systems with a /proc file system
    21         # This will only work on systems with a /proc file system
    22         for line in status:
    23         for line in status:
    23             parts = line.split()
    24             parts = line.split()
    24             key = parts[0][2:-1].lower()
    25             key = parts[0][2:-1].lower()
    25             if key in result:
    26             if key in result:
    26                 result[key] = int(parts[1])
    27                 result[key] = int(parts[1])
    27     ui.write_err(", ".join(["%s: %.1f MiB" % (k, v / 1024.0)
    28     ui.write_err(
    28                             for k, v in result.iteritems()]) + "\n")
    29         ", ".join(
       
    30             ["%s: %.1f MiB" % (k, v / 1024.0) for k, v in result.iteritems()]
       
    31         )
       
    32         + "\n"
       
    33     )
       
    34 
    29 
    35 
    30 def extsetup(ui):
    36 def extsetup(ui):
    31     ui.atexit(memusage, ui)
    37     ui.atexit(memusage, ui)