~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to pyOpenMS/pyopenms/sysinfo.py

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
 
 
3
if sys.platform == "linux2":
 
4
    import ctypes as c
 
5
    import ctypes.util
 
6
 
 
7
    libc = c.CDLL(ctypes.util.find_library("c"))
 
8
 
 
9
    class SysInfo(c.Structure):
 
10
 
 
11
         # for libc5: needs padding
 
12
        padding = 20 - 2 * c.sizeof(c.c_long) - c.sizeof(c.c_int)
 
13
 
 
14
        _fields_ = [("uptime", c.c_ulong),
 
15
                    ("loads", 3 * c.c_ulong),
 
16
                    ("totalram", c.c_ulong),
 
17
                    ("freeram", c.c_ulong),
 
18
                    ("sharedram", c.c_ulong),
 
19
                    ("bufferram", c.c_ulong),
 
20
                    ("totalswap", c.c_ulong),
 
21
                    ("freeswap", c.c_ulong),
 
22
                    ("procs", c.c_ushort),
 
23
                    ("totalhigh", c.c_ulong),
 
24
                    ("freehigh", c.c_ulong),
 
25
                    ("mem_unit", c.c_ulong),
 
26
                    ("_padding", padding * c.c_char)
 
27
        ]
 
28
 
 
29
    def free_mem():
 
30
        sys_info = SysInfo()
 
31
        libc.sysinfo(c.byref(sys_info))
 
32
        return sys_info.freeram
 
33
 
 
34
elif sys.platform == "win32":
 
35
    try:
 
36
        import win32api
 
37
    except:
 
38
        free_mem = lambda: 0 # memory will never change !
 
39
    else:
 
40
        def free_mem():
 
41
            return win32api.GlobalMemoryStatus()['AvailPhys']
 
42
 
 
43
else:
 
44
    sys.stderr.write("determination of memory status not supported on this \n"
 
45
                     " platform, mesauring for memoryleaks will never fail\n")
 
46
 
 
47
    free_mem = lambda: 0 # memory will never change !