[Yt-svn] yt-commit r1507 - trunk/yt
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Thu Oct 29 20:01:38 PDT 2009
Author: mturk
Date: Thu Oct 29 20:01:36 2009
New Revision: 1507
URL: http://yt.enzotools.org/changeset/1507
Log:
Adding the function get_memory_usage() to funcs
Modified:
trunk/yt/funcs.py
Modified: trunk/yt/funcs.py
==============================================================================
--- trunk/yt/funcs.py (original)
+++ trunk/yt/funcs.py Thu Oct 29 20:01:36 2009
@@ -103,6 +103,26 @@
# Some function wrappers that come in handy once in a while
#
+# we use the resource module to get the memory page size
+
+try:
+ import resource
+except ImportError:
+ pass
+
+def get_memory_usage():
+ """
+ Returning resident size in megabytes
+ """
+ pagesize = resource.getpagesize()
+ pid = os.getpid()
+ status_file = "/proc/%s/statm" % (pid)
+ if not os.path.isfile(status_file):
+ return None
+ line = open(status_file).read()
+ size, resident, share, text, library, data, dt = [int(i) for i in line.split()]
+ return resident * pagesize / (1024 * 1024) # return in megs
+
def time_execution(func):
"""
Decorator for seeing how long a given function takes, depending on whether
More information about the yt-svn
mailing list