Skip to content

Instantly share code, notes, and snippets.

@LukasWoodtli
Created September 5, 2022 18:53
Show Gist options
  • Save LukasWoodtli/1600d23e9d8a97a4660e650623fec924 to your computer and use it in GitHub Desktop.
Save LukasWoodtli/1600d23e9d8a97a4660e650623fec924 to your computer and use it in GitHub Desktop.
// run it like this:
// stap -v -x <PID> system_tap_example.stp
global count;
probe begin {
count = 0;
printf("Staring system tap session for pid=%i\n", target());
}
probe end {
if (pid() == target()) {
printf("End of system tap session!\n");
}
}
//probe process("mylibrary.so").function("do_something::*") {
// if (pid() == target()) {
// printf("%x: my function %s() called...\n", tid(), ppfunc());
// }
//}
probe process("/usr/lib64/libc.so*").function("malloc") {
if (pid() == target()) {
if ($size > 20000) {
printf("%s: malloc(%d)\n", ctime(gettimeofday_s()), $size);
print_ubacktrace();
printf("\n\n");
}
}
}
probe process("mylibrary.so").function("do_something") {
if (pid() == target()) {
++count;
}
}
probe process("mylibrary.so").function("dtor").return {
if (pid() == target()) {
printf("Number of counted calls: %d\n", count);
count = 0;
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment