ATLAS Offline Software
Loading...
Searching...
No Matches
AtlRunQueryMemUtil.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3import 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
10def _VmB(VmKey):
11 '''Private.
12 '''
13 # get pseudo file /proc/<pid>/status
14 try:
15 t = open(_proc_status)
16 v = t.read()
17 t.close()
18 except (OSError,ValueError):
19 return 0.0 # non-Linux?
20 # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
21 i = v.index(VmKey)
22 v = v[i:].split(None, 3) # whitespace
23 if len(v) < 3:
24 return 0.0 # invalid format?
25 # convert Vm value to bytes
26 return float(v[1]) * _scale[v[2]]
27
28
29def memory(since=0.0):
30 '''Return memory usage in bytes.
31 '''
32 return _VmB('VmSize:') - since
33
34
35def resident(since=0.0):
36 '''Return resident memory usage in bytes.
37 '''
38 return _VmB('VmRSS:') - since
39
40
41def stacksize(since=0.0):
42 '''Return stack size in bytes.
43 '''
44 return _VmB('VmStk:') - since
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177