ATLAS Offline Software
AtlRunQueryMemUtil.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 import os
4 
5 _proc_status = '/proc/%d/status' % os.getpid()
6 
7 _scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
8  'KB': 1024.0, 'MB': 1024.0*1024.0}
9 
10 def _VmB(VmKey):
11  '''Private.
12  '''
13  global _proc_status, _scale
14  # get pseudo file /proc/<pid>/status
15  try:
16  t = open(_proc_status)
17  v = t.read()
18  t.close()
19  except (OSError,ValueError):
20  return 0.0 # non-Linux?
21  # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
22  i = v.index(VmKey)
23  v = v[i:].split(None, 3) # whitespace
24  if len(v) < 3:
25  return 0.0 # invalid format?
26  # convert Vm value to bytes
27  return float(v[1]) * _scale[v[2]]
28 
29 
30 def memory(since=0.0):
31  '''Return memory usage in bytes.
32  '''
33  return _VmB('VmSize:') - since
34 
35 
36 def resident(since=0.0):
37  '''Return resident memory usage in bytes.
38  '''
39  return _VmB('VmRSS:') - since
40 
41 
42 def stacksize(since=0.0):
43  '''Return stack size in bytes.
44  '''
45  return _VmB('VmStk:') - since
python.utils.AtlRunQueryMemUtil.stacksize
def stacksize(since=0.0)
Definition: AtlRunQueryMemUtil.py:42
python.utils.AtlRunQueryMemUtil.memory
def memory(since=0.0)
Definition: AtlRunQueryMemUtil.py:30
python.utils.AtlRunQueryMemUtil.resident
def resident(since=0.0)
Definition: AtlRunQueryMemUtil.py:36
python.utils.AtlRunQueryMemUtil._VmB
def _VmB(VmKey)
Definition: AtlRunQueryMemUtil.py:10
Trk::open
@ open
Definition: BinningType.h:40
readCCLHist.float
float
Definition: readCCLHist.py:83
Trk::split
@ split
Definition: LayerMaterialProperties.h:38