File: sysinfo.py

package info (click to toggle)
openms 1.11.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 436,688 kB
  • ctags: 150,907
  • sloc: cpp: 387,126; xml: 71,547; python: 7,764; ansic: 2,626; php: 2,499; sql: 737; ruby: 342; sh: 325; makefile: 128
file content (47 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys

if sys.platform == "linux2":
    import ctypes as c
    import ctypes.util

    libc = c.CDLL(ctypes.util.find_library("c"))

    class SysInfo(c.Structure):

         # for libc5: needs padding
        padding = 20 - 2 * c.sizeof(c.c_long) - c.sizeof(c.c_int)

        _fields_ = [("uptime", c.c_ulong),
                    ("loads", 3 * c.c_ulong),
                    ("totalram", c.c_ulong),
                    ("freeram", c.c_ulong),
                    ("sharedram", c.c_ulong),
                    ("bufferram", c.c_ulong),
                    ("totalswap", c.c_ulong),
                    ("freeswap", c.c_ulong),
                    ("procs", c.c_ushort),
                    ("totalhigh", c.c_ulong),
                    ("freehigh", c.c_ulong),
                    ("mem_unit", c.c_ulong),
                    ("_padding", padding * c.c_char)
        ]

    def free_mem():
        sys_info = SysInfo()
        libc.sysinfo(c.byref(sys_info))
        return sys_info.freeram

elif sys.platform == "win32":
    try:
        import win32api
    except:
        free_mem = lambda: 0 # memory will never change !
    else:
        def free_mem():
            return win32api.GlobalMemoryStatus()['AvailPhys']

else:
    sys.stderr.write("determination of memory status not supported on this \n"
                     " platform, mesauring for memoryleaks will never fail\n")

    free_mem = lambda: 0 # memory will never change !