Functions | Variables
MemoryMonitor Namespace Reference

Functions

def _proc_status (pid)
 
def _VmB (pid, VmKey)
 
def memory (pid, since=0.0)
 
def resident (pid, since=0.0)
 
def stacksize (pid, since=0.0)
 

Variables

dictionary _scale
 

Function Documentation

def MemoryMonitor._proc_status (   pid)
private

Definition at line 3 of file MemoryMonitor.py.

Referenced by _VmB().

3 def _proc_status(pid):
4  return '/proc/%d/status' % pid
5 
def _proc_status(pid)
Definition: MemoryMonitor.py:3
def MemoryMonitor._VmB (   pid,
  VmKey 
)
private
Private.

Definition at line 9 of file MemoryMonitor.py.

References _proc_status(), check_time_usage.float, open(), and split().

Referenced by memory(), resident(), and stacksize().

9 def _VmB(pid, VmKey):
10  '''Private.
11  '''
12  global _scale
13  proc_status = _proc_status(pid)
14  # get pseudo file /proc/<pid>/status
15  try:
16  t = open(proc_status)
17  v = t.read()
18  t.close()
19  except:
20  return 0.0 # non-Linux?
21  # get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
22  try:
23  i = v.index(VmKey)
24  except ValueError:
25  return 0.0
26  v = v[i:].split(None, 3) # whitespace
27  if len(v) < 3:
28  return 0.0 # invalid format?
29  # convert Vm value to bytes
30  return float(v[1]) * _scale[v[2]]
31 
32 
void split(double tt, double *fr)
procfile open("FD_BRL_v0.txt")
def _VmB(pid, VmKey)
Definition: MemoryMonitor.py:9
def _proc_status(pid)
Definition: MemoryMonitor.py:3
def MemoryMonitor.memory (   pid,
  since = 0.0 
)
Return memory usage in bytes.

Definition at line 33 of file MemoryMonitor.py.

References _VmB().

33 def memory(pid, since=0.0):
34  '''Return memory usage in bytes.
35  '''
36  return _VmB(pid, 'VmSize:') - since
37 
38 
def memory(pid, since=0.0)
def _VmB(pid, VmKey)
Definition: MemoryMonitor.py:9
def MemoryMonitor.resident (   pid,
  since = 0.0 
)
Return resident memory usage in bytes.

Definition at line 39 of file MemoryMonitor.py.

References _VmB().

Referenced by Tier.Tier.executeProcess().

39 def resident(pid, since=0.0):
40  '''Return resident memory usage in bytes.
41  '''
42  return _VmB(pid, 'VmRSS:') - since
43 
44 
def _VmB(pid, VmKey)
Definition: MemoryMonitor.py:9
def resident(pid, since=0.0)
def MemoryMonitor.stacksize (   pid,
  since = 0.0 
)
Return stack size in bytes.

Definition at line 45 of file MemoryMonitor.py.

References _VmB().

45 def stacksize(pid, since=0.0):
46  '''Return stack size in bytes.
47  '''
48  return _VmB(pid, 'VmStk:') - since
49 
def stacksize(pid, since=0.0)
def _VmB(pid, VmKey)
Definition: MemoryMonitor.py:9

Variable Documentation

dictionary MemoryMonitor._scale
private
Initial value:
1 = {'kB': 1024.0, 'mB': 1024.0*1024.0,
2  'KB': 1024.0, 'MB': 1024.0*1024.0}

Definition at line 6 of file MemoryMonitor.py.