Skip to content

Commit 2d27ac2

Browse files
committed
tools/memleak: Show allocation type in print_outstanding
Signed-off-by: Jiajun Yao <[email protected]>
1 parent d188e07 commit 2d27ac2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/memleak.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import sys
2222

2323
class Allocation(object):
24-
def __init__(self, stack, size):
24+
def __init__(self, stack, size, type_index):
2525
self.stack = stack
2626
self.count = 1
2727
self.size = size
28+
self.type_index = type_index
2829

2930
def update(self, size):
3031
self.count += 1
@@ -154,6 +155,7 @@ def run_command_get_pid(command):
154155
u64 size;
155156
u64 timestamp_ns;
156157
int stack_id;
158+
u32 type_index;
157159
};
158160
159161
struct combined_alloc_info_t {
@@ -243,6 +245,7 @@ def run_command_get_pid(command):
243245
if (address != 0) {
244246
info.timestamp_ns = bpf_ktime_get_ns();
245247
info.stack_id = stack_traces.get_stackid(ctx, STACK_FLAGS);
248+
info.type_index = type_index
246249
allocs.update(&address, &info);
247250
update_statistics_add(info.stack_id, info.size);
248251
}
@@ -549,14 +552,15 @@ def print_outstanding():
549552
combined.append(('0x'+format(addr, '016x')+'\t').encode('utf-8') + bpf.sym(addr, pid,
550553
show_module=True, show_offset=True))
551554
alloc_info[info.stack_id] = Allocation(combined,
552-
info.size)
555+
info.size,
556+
info.type_index)
553557
if args.show_allocs:
554558
print("\taddr = %x size = %s" %
555559
(address.value, info.size))
556560
to_show = sorted(alloc_info.values(), key=alloc_sort_map[sort_key])[-top_stacks:]
557561
for alloc in to_show:
558-
print("\t%d bytes in %d allocations from stack\n\t\t%s" %
559-
(alloc.size, alloc.count,
562+
print("\t%d bytes in %d allocations of type %d from stack\n\t\t%s" %
563+
(alloc.size, alloc.count, alloc.type_index
560564
b"\n\t\t".join(alloc.stack).decode("ascii")))
561565

562566
def print_outstanding_combined():

0 commit comments

Comments
 (0)