forked from soarpenguin/systemtap-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaks.stp
54 lines (44 loc) · 1.08 KB
/
leaks.stp
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
global ptr2bt
global ptr2size
global bt_stats
global quit
probe begin {
warn("Start tracing. Wait for 10 sec to complete.\n")
}
probe process("/lib*/libc.so*").function("malloc").return {
if (pid() == target()) {
if (quit) {
foreach (bt in bt_stats) {
print_ustack(bt)
printf("\t%d\n", @sum(bt_stats[bt]))
}
exit()
} else {
//printf("malloc: %p (bytes %d)\n", $return, $bytes)
ptr = $return
bt = ubacktrace()
ptr2bt[ptr] = bt
ptr2size[ptr] = $bytes
bt_stats[bt] <<< $bytes
}
}
}
probe process("/lib*/libc.so*").function("free") {
if (pid() == target()) {
//printf("free: %p\n", $mem)
ptr = $mem
bt = ptr2bt[ptr]
delete ptr2bt[ptr]
bytes = ptr2size[ptr]
delete ptr2size[ptr]
bt_stats[bt] <<< -bytes
if (@sum(bt_stats[bt]) == 0) {
delete bt_stats[bt]
}
}
}
probe timer.s(10) {
quit = 1
delete ptr2bt
delete ptr2size
}