Mercurial > hg
comparison contrib/memory.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | de5c9d0e02ea |
children | d4ba4d51f85f |
comparison
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) |