Created
November 6, 2017 08:02
-
-
Save yjhjstz/6bc5bd9b2ce006b27c3e7a97b5c97464 to your computer and use it in GitHub Desktop.
memory leak systemTap script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global ptr2bt | |
global ptr2size | |
global bt_stats | |
global quit | |
probe begin { | |
warn("Start tracing. Wait for 10 sec to complete.\n") | |
} | |
probe process("/lib/x86_64-linux-gnu/libc.so.6").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/x86_64-linux-gnu/libc.so.6").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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment