import os
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
          'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
    ''' given a VmKey string, returns a number of bytes. '''
    # get pseudo file  /proc/<pid>/status
    try:
        t = open(_proc_status)
        v = t.read()
        t.close()
    except IOError:
        return 0.0  # non-Linux?
    # get VmKey line e.g. 'VmRSS:  9999  kB\n ...'
    i = v.index(VmKey)
    v = v[i:].split(None, 3)  # split on runs of whitespace
    if len(v) < 3:
        return 0.0  # invalid format?
    # convert Vm value to bytes
    return float(v[1]) * _scale[v[2]]
def memory(since=0.0):
    ''' Return virtual memory usage in bytes. '''
    return _VmB('VmSize:') - since
def resident(since=0.0):
    ''' Return resident memory usage in bytes. '''
    return _VmB('VmRSS:') - since
def stacksize(since=0.0):
    ''' Return stack size in bytes. '''
    return _VmB('VmStk:') - since

02a29b8d0f4a534bc873d2ae3549a6eddadff156
<mask token>


def memory(since=0.0):
    """ Return virtual memory usage in bytes. """
    return _VmB('VmSize:') - since


def resident(since=0.0):
    """ Return resident memory usage in bytes. """
    return _VmB('VmRSS:') - since


def stacksize(since=0.0):
    """ Return stack size in bytes. """
    return _VmB('VmStk:') - since

<mask token>


def _VmB(VmKey):
    """ given a VmKey string, returns a number of bytes. """
    try:
        t = open(_proc_status)
        v = t.read()
        t.close()
    except IOError:
        return 0.0
    i = v.index(VmKey)
    v = v[i:].split(None, 3)
    if len(v) < 3:
        return 0.0
    return float(v[1]) * _scale[v[2]]


def memory(since=0.0):
    """ Return virtual memory usage in bytes. """
    return _VmB('VmSize:') - since


def resident(since=0.0):
    """ Return resident memory usage in bytes. """
    return _VmB('VmRSS:') - since


def stacksize(since=0.0):
    """ Return stack size in bytes. """
    return _VmB('VmStk:') - since

<mask token>
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0 * 1024.0, 'KB': 1024.0, 'MB': 1024.0 *
    1024.0}


def _VmB(VmKey):
    """ given a VmKey string, returns a number of bytes. """
    try:
        t = open(_proc_status)
        v = t.read()
        t.close()
    except IOError:
        return 0.0
    i = v.index(VmKey)
    v = v[i:].split(None, 3)
    if len(v) < 3:
        return 0.0
    return float(v[1]) * _scale[v[2]]


def memory(since=0.0):
    """ Return virtual memory usage in bytes. """
    return _VmB('VmSize:') - since


def resident(since=0.0):
    """ Return resident memory usage in bytes. """
    return _VmB('VmRSS:') - since


def stacksize(since=0.0):
    """ Return stack size in bytes. """
    return _VmB('VmStk:') - since

import os
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0 * 1024.0, 'KB': 1024.0, 'MB': 1024.0 *
    1024.0}


def _VmB(VmKey):
    """ given a VmKey string, returns a number of bytes. """
    try:
        t = open(_proc_status)
        v = t.read()
        t.close()
    except IOError:
        return 0.0
    i = v.index(VmKey)
    v = v[i:].split(None, 3)
    if len(v) < 3:
        return 0.0
    return float(v[1]) * _scale[v[2]]


def memory(since=0.0):
    """ Return virtual memory usage in bytes. """
    return _VmB('VmSize:') - since


def resident(since=0.0):
    """ Return resident memory usage in bytes. """
    return _VmB('VmRSS:') - since


def stacksize(since=0.0):
    """ Return stack size in bytes. """
    return _VmB('VmStk:') - since

import os
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
          'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
    ''' given a VmKey string, returns a number of bytes. '''
    # get pseudo file  /proc/<pid>/status
    try:
        t = open(_proc_status)
        v = t.read()
        t.close()
    except IOError:
        return 0.0  # non-Linux?
    # get VmKey line e.g. 'VmRSS:  9999  kB\n ...'
    i = v.index(VmKey)
    v = v[i:].split(None, 3)  # split on runs of whitespace
    if len(v) < 3:
        return 0.0  # invalid format?
    # convert Vm value to bytes
    return float(v[1]) * _scale[v[2]]
def memory(since=0.0):
    ''' Return virtual memory usage in bytes. '''
    return _VmB('VmSize:') - since
def resident(since=0.0):
    ''' Return resident memory usage in bytes. '''
    return _VmB('VmRSS:') - since
def stacksize(since=0.0):
    ''' Return stack size in bytes. '''
    return _VmB('VmStk:') - since
