Changeset 7094


Ignore:
Timestamp:
May 27, 2009, 8:51:30 AM (11 years ago)
Author:
rwilson
Message:

Improved Windows code to something that will work after WinXp? (hopefully).

File:
1 edited

Legend:

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

    r7093 r7094  
    244244        log(level, msg)
    245245    else:
    246         # from http://code.activestate.com/recipes/511491/
     246        # Windows code from: http://code.activestate.com/recipes/511491/
    247247        try:
    248248            import ctypes
    249249            import _winreg
    250250        except:
    251             log(CRITICAL, 'Windows resource usage not available')
     251            log(level, 'Windows resource usage not available')
    252252            return
    253253
    254254        kernel32 = ctypes.windll.kernel32
    255255        c_ulong = ctypes.c_ulong
    256         class MEMORYSTATUS(ctypes.Structure):
     256        c_ulonglong = ctypes.c_ulonglong
     257        class MEMORYSTATUSEX(ctypes.Structure):
    257258            _fields_ = [('dwLength', c_ulong),
    258259                        ('dwMemoryLoad', c_ulong),
    259                         ('dwTotalPhys', c_ulong),
    260                         ('dwAvailPhys', c_ulong),
    261                         ('dwTotalPageFile', c_ulong),
    262                         ('dwAvailPageFile', c_ulong),
    263                         ('dwTotalVirtual', c_ulong),
    264                         ('dwAvailVirtual', c_ulong)
     260                        ('ullTotalPhys', c_ulonglong),
     261                        ('ullAvailPhys', c_ulonglong),
     262                        ('ullTotalPageFile', c_ulonglong),
     263                        ('ullAvailPageFile', c_ulonglong),
     264                        ('ullTotalVirtual', c_ulonglong),
     265                        ('ullAvailVirtual', c_ulonglong),
     266                        ('ullAvailExtendedVirtual', c_ulonglong)
    265267                       ]
    266            
    267         memoryStatus = MEMORYSTATUS()
    268         memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUS)
    269         kernel32.GlobalMemoryStatus(ctypes.byref(memoryStatus))
     268
     269        memoryStatusEx = MEMORYSTATUSEX()
     270        memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUSEX)
     271        kernel32.GlobalMemoryStatusEx(ctypes.byref(memoryStatusEx))
    270272
    271273        msg = ('Resource usage: total memory=%.1fMB free memory=%.1fMB'
    272                % (memoryStatus.dwTotalPhys/_scale['MB'],
    273                   memoryStatus.dwAvailPhys/_scale['MB']))
     274               % (memoryStatusEx.ullTotalPhys/_scale['MB'],
     275                  memoryStatusEx.ullAvailPhys/_scale['MB']))
    274276        log(level, msg)
    275277
Note: See TracChangeset for help on using the changeset viewer.