Skip to content

Commit c5ca0b8

Browse files
author
jon b
committed
added memstats. improved objcbrowser by sorting menthod names
1 parent a7a3bd5 commit c5ca0b8

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

memstatus.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from objc_util import c
2+
import ctypes
3+
def _get_taskinfo():
4+
integer_t = ctypes.c_int
5+
natural_t = ctypes.c_uint
6+
vm_size_t = ctypes.c_ulong
7+
8+
class time_value_t(ctypes.Structure):
9+
_fields_ = [("seconds", integer_t),
10+
("microseconds", integer_t)]
11+
12+
def __repr__(self):
13+
return "%s.%s" % (self.seconds, self.microseconds)
14+
15+
policy_t = ctypes.c_int
16+
17+
class task_basic_info(ctypes.Structure):
18+
_pack_ = 4
19+
_fields_ = [("suspend_count", integer_t),
20+
("virtual_size", vm_size_t),
21+
("resident_size", vm_size_t),
22+
("user_time", time_value_t),
23+
("system_time", time_value_t),
24+
("policy", policy_t)]
25+
26+
def __repr__(self):
27+
return repr(dict((key, getattr(self, key))
28+
for key in dir(self)
29+
if not key.startswith("_")))
30+
31+
kern_return_t = ctypes.c_int
32+
mach_port_t = natural_t
33+
task_name_t = ctypes.c_uint
34+
task_flavor_t = ctypes.c_uint
35+
task_info_t = ctypes.POINTER(ctypes.c_int)
36+
mach_msg_type_number_t = natural_t
37+
TASK_BASIC_INFO_COUNT = ctypes.sizeof(
38+
task_basic_info) // ctypes.sizeof(natural_t)
39+
TASK_BASIC_INFO = 5
40+
KERN_SUCCESS = 0
41+
42+
libkern = c
43+
task_info = libkern.task_info
44+
task_info.restype = kern_return_t
45+
task_info.argtypes = [task_name_t,
46+
task_flavor_t,
47+
ctypes.POINTER(task_basic_info),
48+
ctypes.POINTER(mach_msg_type_number_t)]
49+
50+
mach_task_self = libkern.mach_task_self
51+
mach_task_self.restype = mach_port_t
52+
mach_task_self.argtypes = []
53+
54+
ti = task_basic_info()
55+
56+
count = mach_msg_type_number_t(TASK_BASIC_INFO_COUNT)
57+
kr = task_info(mach_task_self(), TASK_BASIC_INFO,
58+
ctypes.byref(ti),
59+
ctypes.byref(count))
60+
if kr != KERN_SUCCESS:
61+
return None
62+
return ti
63+
64+

objc_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def __init__(self,items, *args,**kwargs):
2020
ui.View.__init__(self,*args,**kwargs)
2121
self.height=700
2222
self.width=320
23-
self.items=items
23+
self.items=sorted(items)
2424
self.tv=ui.TableView(frame=self.bounds)
2525
self.tv.delegate=self
2626
self.tv.data_source=self
2727
self.add_subview(self.tv)
2828
self.filter=''
29-
self.filtereditems=[x for x in self.items if self.filter in x.lower()]
29+
self.filtereditems=sorted([x for x in self.items if self.filter in x.lower()])
3030
def tableview_number_of_rows(self, tv, section):
3131
return len(self.filtereditems)
3232

0 commit comments

Comments
 (0)