aboutsummaryrefslogtreecommitdiff
path: root/kernel/mm/slab.py
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/mm/slab.py')
-rw-r--r--kernel/mm/slab.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/kernel/mm/slab.py b/kernel/mm/slab.py
new file mode 100644
index 0000000..1b0c8fb
--- /dev/null
+++ b/kernel/mm/slab.py
@@ -0,0 +1,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()