##// END OF EJS Templates
contrib: helper extension to track memory usage
Martin Geisler -
r10017:253d0da2 default
parent child Browse files
Show More
@@ -0,0 +1,36 b''
1 # memory.py - track memory usage
2 #
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 '''helper extension to measure memory usage
9
10 Reads current and peak memory usage from ``/proc/self/status`` and
11 prints it to ``stderr`` on exit.
12 '''
13
14 import atexit
15
16 def memusage(ui):
17 """Report memory usage of the current process."""
18 status = None
19 result = {'peak': 0, 'rss': 0}
20 try:
21 # This will only work on systems with a /proc file system
22 # (like Linux).
23 status = open('/proc/self/status', 'r')
24 for line in status:
25 parts = line.split()
26 key = parts[0][2:-1].lower()
27 if key in result:
28 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)
33 for key, value in result.iteritems()]) + "\n")
34
35 def extsetup(ui):
36 atexit.register(memusage, ui)
General Comments 0
You need to be logged in to leave comments. Login now