rss, vms = [parse_status(field=x, value_only=True) for x in ['VmRSS', 'VmSize']] if rss[-3:] == vms[-3:] and rss[-3:] == ' kB': # the same units rss = int(rss[:-3]) # strip from rss vms = int(vms[:-3]) return (rss, vms) try: # we prefer to use psutil if available # and let's stay away from "externals" module for now # Note: importing as __Process so it does not get # 'queried' by autodoc leading to an exception # while being unable to get values for the properties from psutil import Process as __Process __pymvpa_process__ = __Process(__pymvpa_pid__) def get_vmem(): """Return utilization of virtual memory Generic implementation using psutil """ mi = __pymvpa_process__.get_memory_info() # in later versions of psutil mi is a named tuple. # but that is not the case on Debian squeeze with psutil 0.1.3 rss = mi[0] / 1024 vms = mi[1] / 1024 return (rss, vms) except ImportError: get_vmem = get_vmem_from_status
# but do not crash return (-1, -1) if rss[-3:] == vms[-3:] and rss[-3:] == ' kB': # the same units rss = int(rss[:-3]) # strip from rss vms = int(vms[:-3]) return (rss, vms) try: # we prefer to use psutil if available # and let's stay away from "externals" module for now # Note: importing as __Process so it does not get # 'queried' by autodoc leading to an exception # while being unable to get values for the properties from psutil import Process as __Process __pymvpa_process__ = __Process(__pymvpa_pid__) __pymvpa_memory_info = __pymvpa_process__.memory_info if hasattr(__pymvpa_process__, 'memory_info') \ else __pymvpa_process__.get_memory_info def get_vmem(): """Return utilization of virtual memory Generic implementation using psutil """ mi = __pymvpa_memory_info() # in later versions of psutil mi is a named tuple. # but that is not the case on Debian squeeze with psutil 0.1.3 rss = mi[0] / 1024 vms = mi[1] / 1024 return (rss, vms)