Skip to content

Instantly share code, notes, and snippets.

@fcicq
Created October 30, 2012 17:56
Show Gist options
  • Save fcicq/3981870 to your computer and use it in GitHub Desktop.
Save fcicq/3981870 to your computer and use it in GitHub Desktop.
SystemTap (userland) with flamegraph by agentzh
/*
code: https://groups.google.com/d/msg/openresty/u-puKWWONMk/bxsyQdWMkJIJ by agentzh
Require SystemTap 2.0 and linux kernel 3.5+
Example usage:
stap --ldd -d /path/to/nginx/sbin/nginx \
-d /path/to/luajit/lib/libluajit-5.1.so.2.0.0 \
--all-modules -D MAXMAPENTRIES=20240 \
-D MAXACTION=20000 \
-D MAXTRACE=100 \
-D MAXSTRINGLEN=4096 \
-D MAXBACKTRACE=100 -x 5857 a.stp > a.out
perl stackcollapse-stap.pl a.out > a.out2
perl flamegraph.pl a.out2 > a.svg
*/
global s;
global quit = 0;
probe timer.profile {
if (pid() == target()) {
if (quit) {
foreach (i in s-) {
print_ustack(i);
printf("\t%d\n", @count(s[i]));
}
exit()
} else {
s[ubacktrace()] <<< 1;
}
}
}
probe timer.s(20) {
quit = 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment