Changeset 7092


Ignore:
Timestamp:
May 27, 2009, 8:12:55 AM (15 years ago)
Author:
rwilson
Message:

Added Windows code to logging resource usage method.

Location:
branches/numpy/anuga/utilities
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/utilities/log.py

    r7091 r7092  
    243243        log(level, msg)
    244244    else:
    245         msg = ('Sorry, no memory statistics for Windows (yet).')
     245        # from http://code.activestate.com/recipes/511491/
     246        try:
     247            import ctypes
     248            import _winreg
     249        except:
     250            log(CRITICAL, 'Windows resource usage not available')
     251            return
     252
     253        kernel32 = ctypes.windll.kernel32
     254        c_ulong = ctypes.c_ulong
     255        class MEMORYSTATUS(ctypes.Structure):
     256            _fields_ = [('dwLength', c_ulong),
     257                        ('dwMemoryLoad', c_ulong),
     258                        ('dwTotalPhys', c_ulong),
     259                        ('dwAvailPhys', c_ulong),
     260                        ('dwTotalPageFile', c_ulong),
     261                        ('dwAvailPageFile', c_ulong),
     262                        ('dwTotalVirtual', c_ulong),
     263                        ('dwAvailVirtual', c_ulong)
     264                       ]
     265           
     266        memoryStatus = MEMORYSTATUS()
     267        memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUS)
     268        kernel32.GlobalMemoryStatus(ctypes.byref(memoryStatus))
     269
     270        msg = ('Resource usage: total memory=%.1fMB free memory=%.1fMB'
     271               % (memoryStatus.dwTotalPhys/_scale['MB'],
     272                  memoryStatus.dwAvailPhys/_scale['MB']))
    246273        log(level, msg)
    247274
Note: See TracChangeset for help on using the changeset viewer.