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
|
import gdb
import weenix
import weenix.kmem
class SlabCommand(weenix.Command):
def __init__(self):
weenix.Command.__init__(self, "slab", gdb.COMMAND_DATA)
def _allocators(self):
l = list()
for alloc in weenix.kmem.allocators():
l.append(alloc)
return l
def invoke(self, args, tty):
names = list()
slabs = list()
sizes = list()
counts = list()
names.append("")
slabs.append("slabs")
sizes.append("objsize")
counts.append("allocated")
for alloc in weenix.kmem.allocators():
names.append(alloc.name())
slabs.append(str(len(list(alloc.slabs()))))
sizes.append(str(alloc.size()))
counts.append(str(len(list(alloc.objs()))))
namewidth = max(map(lambda x: len(x), names))
slabwidth = max(map(lambda x: len(x), slabs))
sizewidth = max(map(lambda x: len(x), sizes))
countwidth = max(map(lambda x: len(x), counts))
for name, slab, size, count in zip(names, slabs, sizes, counts):
print(
"{1:<{0}} {3:>{2}} {5:>{4}} {7:>{6}}".format(
namewidth, name, slabwidth, slab, sizewidth, size, countwidth, count
)
)
def complete(self, line, word):
l = map(lambda x: x.name(), self._allocators())
l = filter(lambda x: x.startswith(word), l)
for used in line.split():
l = filter(lambda x: x != used, l)
l.sort()
return l
SlabCommand()
|