-
Notifications
You must be signed in to change notification settings - Fork 19
/
memstatus.py
67 lines (56 loc) · 2.44 KB
/
memstatus.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from objc_util import c
import ctypes
def _get_taskinfo():
integer_t = ctypes.c_int
natural_t = ctypes.c_uint
vm_size_t = ctypes.c_ulong
class time_value_t(ctypes.Structure):
_fields_ = [("seconds", integer_t),
("microseconds", integer_t)]
def __repr__(self):
return "%s.%s" % (self.seconds, self.microseconds)
policy_t = ctypes.c_int
class task_basic_info(ctypes.Structure):
_pack_ = 4
_fields_ = [("suspend_count", integer_t),
("virtual_size", vm_size_t),
("resident_size", vm_size_t),
("user_time", time_value_t),
("system_time", time_value_t),
("policy", policy_t)]
def __repr__(self):
return repr(dict((key, getattr(self, key))
for key in dir(self)
if not key.startswith("_")))
kern_return_t = ctypes.c_int
mach_port_t = natural_t
task_name_t = ctypes.c_uint
task_flavor_t = ctypes.c_uint
task_info_t = ctypes.POINTER(ctypes.c_int)
mach_msg_type_number_t = natural_t
TASK_BASIC_INFO_COUNT = ctypes.sizeof(
task_basic_info) // ctypes.sizeof(natural_t)
TASK_BASIC_INFO = 5
KERN_SUCCESS = 0
libkern = c
task_info = libkern.task_info
task_info.restype = kern_return_t
task_info.argtypes = [task_name_t,
task_flavor_t,
ctypes.POINTER(task_basic_info),
ctypes.POINTER(mach_msg_type_number_t)]
mach_task_self = libkern.mach_task_self
mach_task_self.restype = mach_port_t
mach_task_self.argtypes = []
ti = task_basic_info()
count = mach_msg_type_number_t(TASK_BASIC_INFO_COUNT)
kr = task_info(mach_task_self(), TASK_BASIC_INFO,
ctypes.byref(ti),
ctypes.byref(count))
if kr != KERN_SUCCESS:
return None
return ti
if __name__=='__main__':
print (_get_taskinfo())
A=list(range(100000))
print (_get_taskinfo())