nest-simulator
nest-simulator copied to clipboard
Recording more detailed memory consumption metrics
Currently, the VMSize kernel value for the process running NEST can be accessed via the memory_thisjob
sli-command (see processes.sli line 1165). However, other metrics like the VMPeak value (peak memory consumption) and VMRSS (resident set size; actual physical allocated memory) are equally important and should be read out.
As we are moving away from SLI, I implemented the functionality in Python (see below), however I am unsure about the correct place to put the code. Could someone of the PyNEST team create a PR out of the code I provided?
def _VmB(VmKey):
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0, 'KB': 1024.0, 'MB': 1024.0*1024.0}
# get pseudo file /proc/<pid>/status
try:
t = open(_proc_status)
v = t.read()
t.close()
except:
return 0.0 # non-Linux?
# get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
i = v.index(VmKey)
v = v[i:].split(None, 3) # whitespace
if len(v) < 3:
return 0.0 # invalid format?
# convert Vm value to bytes
return float(v[1]) * _scale[v[2]]
def get_vmsize():
"""Return memory usage in bytes."""
return _VmB('VmSize:')
def get_rss():
"""Return resident memory usage in bytes."""
return _VmB('VmRSS:')
def get_vmpeak():
"""Return peak memory usage in bytes."""
return _VmB('VmPeak:')