Changeset 8299 for trunk/anuga_core/source/anuga/utilities/system_tools.py
- Timestamp:
- Jan 17, 2012, 1:05:00 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/utilities/system_tools.py
r8145 r8299 12 12 import tarfile 13 13 import warnings 14 import pdb 14 15 15 16 try: … … 567 568 568 569 570 #### Memory functions 571 _proc_status = '/proc/%d/status' % os.getpid() 572 _scale = {'kB': 1024.0, 'mB': 1024.0*1024.0, 573 'KB': 1024.0, 'MB': 1024.0*1024.0} 574 _total_memory = 0.0 575 _last_memory = 0.0 576 577 def _VmB(VmKey): 578 '''private method''' 579 global _proc_status, _scale 580 # get pseudo file /proc/<pid>/status 581 try: 582 t = open(_proc_status) 583 v = t.read() 584 t.close() 585 except: 586 return 0.0 # non-Linux? 587 # get VmKey line e.g. 'VmRSS: 9999 kB\n ...' 588 i = v.index(VmKey) 589 v = v[i:].split(None, 3) # whitespace 590 if len(v) < 3: 591 return 0.0 # invalid format? 592 # convert Vm value to MB 593 return (float(v[1]) * _scale[v[2]]) / (1024.0*1024.0) 594 595 596 def MemoryUpdate(print_msg=None,str_return=False): 597 '''print memory usage stats in MB. 598 ''' 599 global _total_memory, _last_memory 600 601 _last_memory = _total_memory 602 _total_memory = _VmB('VmSize:') 603 604 #if print_msg is not None: 605 mem_diff = _total_memory - _last_memory 606 return (mem_diff,_total_memory) 607 608
Note: See TracChangeset
for help on using the changeset viewer.