##// END OF EJS Templates
with: use context manager for file I/O in memusage
Bryan O'Sullivan -
r27795:3e0d27d2 default
parent child Browse files
Show More
@@ -15,20 +15,15 b' import atexit'
15
15
16 def memusage(ui):
16 def memusage(ui):
17 """Report memory usage of the current process."""
17 """Report memory usage of the current process."""
18 status = None
19 result = {'peak': 0, 'rss': 0}
18 result = {'peak': 0, 'rss': 0}
20 try:
19 with open('/proc/self/status', 'r') as status:
21 # This will only work on systems with a /proc file system
20 # This will only work on systems with a /proc file system
22 # (like Linux).
21 # (like Linux).
23 status = open('/proc/self/status', 'r')
24 for line in status:
22 for line in status:
25 parts = line.split()
23 parts = line.split()
26 key = parts[0][2:-1].lower()
24 key = parts[0][2:-1].lower()
27 if key in result:
25 if key in result:
28 result[key] = int(parts[1])
26 result[key] = int(parts[1])
29 finally:
30 if status is not None:
31 status.close()
32 ui.write_err(", ".join(["%s: %.1f MiB" % (key, value / 1024.0)
27 ui.write_err(", ".join(["%s: %.1f MiB" % (key, value / 1024.0)
33 for key, value in result.iteritems()]) + "\n")
28 for key, value in result.iteritems()]) + "\n")
34
29
General Comments 0
You need to be logged in to leave comments. Login now