##// END OF EJS Templates
memory: avoid shadowing variables inside a list comprehension
Augie Fackler -
r30386:ff896733 default
parent child Browse files
Show More
@@ -1,32 +1,32 b''
1 # memory.py - track memory usage
1 # memory.py - track memory usage
2 #
2 #
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 '''helper extension to measure memory usage
8 '''helper extension to measure memory usage
9
9
10 Reads current and peak memory usage from ``/proc/self/status`` and
10 Reads current and peak memory usage from ``/proc/self/status`` and
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 import atexit
15 import atexit
16
16
17 def memusage(ui):
17 def memusage(ui):
18 """Report memory usage of the current process."""
18 """Report memory usage of the current process."""
19 result = {'peak': 0, 'rss': 0}
19 result = {'peak': 0, 'rss': 0}
20 with open('/proc/self/status', 'r') as status:
20 with open('/proc/self/status', 'r') as status:
21 # This will only work on systems with a /proc file system
21 # This will only work on systems with a /proc file system
22 # (like Linux).
22 # (like Linux).
23 for line in status:
23 for line in status:
24 parts = line.split()
24 parts = line.split()
25 key = parts[0][2:-1].lower()
25 key = parts[0][2:-1].lower()
26 if key in result:
26 if key in result:
27 result[key] = int(parts[1])
27 result[key] = int(parts[1])
28 ui.write_err(", ".join(["%s: %.1f MiB" % (key, value / 1024.0)
28 ui.write_err(", ".join(["%s: %.1f MiB" % (k, v / 1024.0)
29 for key, value in result.iteritems()]) + "\n")
29 for k, v in result.iteritems()]) + "\n")
30
30
31 def extsetup(ui):
31 def extsetup(ui):
32 atexit.register(memusage, ui)
32 atexit.register(memusage, ui)
General Comments 0
You need to be logged in to leave comments. Login now